Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main implements Runnable {
- final long MOD = 1 << 16;
- public void _main() throws IOException {
- while (true) {
- int n = nextInt();
- if (n == 0)
- break;
- long a = 1;
- long b = 0;
- for (int i = 0; i < n; i++) {
- String com = next();
- if (com.equals("ADD")) {
- b += nextInt();
- if (b >= MOD)
- b -= MOD;
- }
- else {
- int v = nextInt();
- a = (a * v) % MOD;
- b = (b * v) % MOD;
- }
- }
- boolean[] can = new boolean[(int)MOD];
- for (int x = 0; x < MOD; x++)
- can[(int)((a * x + b) % MOD)] = true;
- int res = 0;
- for (int i = 0; i < MOD; i++)
- if (can[i])
- ++res;
- out.println(res);
- }
- }
- private BufferedReader in;
- private PrintWriter out;
- private StringTokenizer st;
- private String next() throws IOException {
- while (st == null || !st.hasMoreTokens()) {
- String rl = in.readLine();
- if (rl == null)
- return null;
- st = new StringTokenizer(rl);
- }
- return st.nextToken();
- }
- private int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- private long nextLong() throws IOException {
- return Long.parseLong(next());
- }
- private double nextDouble() throws IOException {
- return Double.parseDouble(next());
- }
- public static void main(String[] args) {
- new Thread(new Main()).start();
- }
- public void run() {
- try {
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(System.out);
- _main();
- out.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(202);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement