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

public class cars_ats_other 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_other().run();
    }

    private final long PRIME = 37;
    private final long BASE = (long) 1e7 + 7;

    private int calcHash(Long s) {
        long val = 0;
        while (s > 0) {
            val = ((val * PRIME) + (s % 10 + 1)) % BASE;
            s /= 10;
        }
        return (int) val;
    }

    private void solve() throws IOException {
        int n = nextInt();
        long[] q = new long[n + 2];
        int l = 0;
        int r = -1;
        long sum = 0;
        int[] hashSet = new int[(int) BASE];
        Arrays.fill(hashSet, 0);
        for (int i = 0; i < n; i++) {
            String code = nextToken();
            if (code.equals("+")) {
                long num = nextLong();
                sum += num;
                hashSet[calcHash(num)]++;
                r++;
                q[r] = num;
            } else if (code.equals("-")) {
                long num = q[l];
                l++;
                sum -= num;
                hashSet[calcHash(num)]--;
            } else {
                int cnt = r - l + 1;
                if (sum % cnt != 0) {
                    out.println(0);
                } else {
                    out.println(hashSet[calcHash(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);
        }
    }
}
