import java.util.*;
import java.io.*;

public class cars_ats implements Runnable {
    StringTokenizer st;
    PrintWriter out;
    BufferedReader br;

    private String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    public static void main(String[] args) {
        new cars_ats().run();
    }

    private TreeMap<Long, Integer> inProduction;
    private ArrayDeque<Long> q;

    private void solve() throws IOException {
        inProduction = new TreeMap<Long, Integer>();
        q = new ArrayDeque<Long>();
        long sum = 0;
        int cnt = 0;
        int n = nextInt();

        for (int i = 0; i < n; i++) {
            String code = nextToken();
            if (code.equals("+")) {
                long num = nextLong();
                sum += num;
                q.add(num);
                cnt++;
                if (inProduction.containsKey(num)) {
                    inProduction.put(num, inProduction.get(num) + 1);
                } else {
                    inProduction.put(num, 1);
                }
            } else if (code.equals("-")) {
                long num = q.pollFirst();
                cnt--;
                sum -= num;
                inProduction.put(num, inProduction.get(num) - 1);
            } else {
                if (sum % cnt != 0) {
                    out.println(0);
                } else {
                    if (!inProduction.containsKey(sum / cnt)) {
                        out.println(0);
                    } else {
                        out.println(inProduction.get(sum / cnt));
                    }
                }
            }
        }
    }

    public void run() {
        try {
            br = new BufferedReader(new FileReader("cars.in"));
            out = new PrintWriter("cars.out");

            solve();

            br.close();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(1);
        }
    }
}
