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

public class gonarch_bm {
	FastScanner in;
	PrintWriter out;

	class NLogSQRTSolution {
		int n;
		SegmentTree st;
		long mul;
		int MAX = (int) 1e5;
		int SQRT = 2000;
		long[] val;

		class SegmentTree {
			int n;
			long[] addV;

			SegmentTree(int n) {
				this.n = n;
				addV = new long[n * 4];
			}

			private void push(int v) {
				if (addV[v] == 0)
					return;
				addV[v * 2 + 1] += addV[v];
				addV[v * 2 + 2] += addV[v];
				addV[v] = 0;
			}

			private void add(int v, int l, int r, int needL, int needR, int val) {
				if (needL > needR)
					return;
				if (needL == l && needR == r) {
					addV[v] += val;
					return;
				}
				push(v);
				int m = (l + r) / 2;
				add(v * 2 + 1, l, m, needL, Math.min(needR, m), val);
				add(v * 2 + 2, m + 1, r, Math.max(needL, m + 1), needR, val);
			}

			public void add(int needL, int needR, int val) {
				add(0, 0, n - 1, needL, needR, val);
			}

			private long get(int v, int l, int r, int needPos) {
				if (l == r)
					return addV[v];
				push(v);
				int m = (l + r) / 2;
				if (m >= needPos)
					return get(v * 2 + 1, l, m, needPos);
				return get(v * 2 + 2, m + 1, r, needPos);
			}

			public long get(int needPos) {
				return get(0, 0, n - 1, needPos);
			}
		}

		public NLogSQRTSolution() {
			super();
			mul = 0;
			val = new long[SQRT + 1];
			st = new SegmentTree(MAX + 1);
		}

		public void add(int x) {
			if (x <= SQRT) {
				val[x]++;
				return;
			}
			mul++;
			for (int i = 1;; i++) {
				int left = x * i;
				int right = Math.min(MAX, x * (i + 1) - 1);
				if (right < left)
					break;
				st.add(left, right, x * i);
			}
		}

		public void rem(int x) {
			if (x <= SQRT) {
				val[x]--;
				return;
			}
			mul--;
			for (int i = 1;; i++) {
				int left = x * i;
				int right = Math.min(MAX, x * (i + 1) - 1);
				if (right < left)
					break;
				st.add(left, right, -x * i);
			}
		}

		public long calc(int f) {
			long t1 = f * mul;
			long t2 = st.get(f);
			for (int i = 1; i <= SQRT; i++)
				if (val[i] != 0)
					t1 += val[i] * (f % i);
			return t1 - t2;
		}
	}

	void solve() {
		NLogSQRTSolution sol = new NLogSQRTSolution();
		int n = in.nextInt();
		for (int i = 0; i < n; i++) {
			char c = in.next().charAt(0);
			if (c == '+') {
				sol.add(in.nextInt());
			} else {
				if (c == '-') {
					sol.rem(in.nextInt());
				} else {
					out.println(sol.calc(in.nextInt()));
				}
			}
		}
	}

	void run() {
		try {
			in = new FastScanner(new File("gonarch.in"));
			out = new PrintWriter(new File("gonarch.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

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