#include <cstdio>
#include <iostream>

using namespace std;

const int maxN = 100 * 1000;
const int lengthOfBlock = 317;
const int countBlocks = ((maxN + 1) + lengthOfBlock - 1) / lengthOfBlock;

long long sumBlocks[countBlocks];
long long sumInBlock[maxN + 1];
long long a[maxN + 1];
int countQueries, countCrabes;	

void add(int i, int value) {
	a[i] += i;
	int numOfBlock = i / lengthOfBlock;
	int startPosition = numOfBlock * lengthOfBlock;
	int endPosition = min(startPosition + lengthOfBlock, maxN + 1);
	for (int j = i; j < endPosition; j++) {
		sumInBlock[j] += value;
	}
	for (int j = numOfBlock; j < countBlocks; j++) {
		sumBlocks[j] += value;
	}
}
	
long long sum(int r) {
	int numOfBlock = r / lengthOfBlock;
	long long result = sumInBlock[r];
	if (numOfBlock != 0) result += sumBlocks[numOfBlock - 1];
	return result;
}

int main() {
	freopen("gonarch.in", "r", stdin);
	freopen("gonarch.out", "w", stdout);
	scanf("%d", &countQueries);
	char type;
	int k;
	for (int i = 0; i < countQueries; i++) {
		scanf("%1s%d", &type, &k);
		if (type == '+') {
			add(k, k);
			countCrabes++;
		} else if (type == '-') {
			add(k, -k);
			countCrabes--;
		} else {
			int n = k;
			long long answer = 1L * n * countCrabes;
			int sqrtN = (int)sqrt(.0 + n);
			for (int k = 1; k <= sqrtN; k++) {
				if (a[k] != 0) answer -= a[k] * (n / k);
			}
				
			int lastBad = n;
			long long badSum = sum(lastBad);
			long long goodSum = 0;
			int numOfBlock = 0;
			for (int ndivk = 1; ndivk < sqrtN; ndivk++) {
				goodSum = badSum;
					
				lastBad = n / (ndivk + 1);
					
				numOfBlock = lastBad / lengthOfBlock;
				if (numOfBlock != 0) badSum = sumInBlock[lastBad] + sumBlocks[numOfBlock - 1];
				else badSum = sumInBlock[lastBad];
					
				answer -= (goodSum - badSum) * ndivk;
			}
				
			goodSum = badSum;
				
			lastBad = max(n / (sqrtN + 1), sqrtN);

			badSum = sum(lastBad);
			answer -= (goodSum - badSum) * sqrtN;
				
			printf("%d\n", answer);
		}
	}
}