#include <cstdio>
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

int main()
{
	freopen("cars.in", "r", stdin);
	freopen("cars.out", "w", stdout);
	int n;
	cin >> n;
	long long a, sum = 0, cnt = 0;
	map<long long, pair<long long, int> > ms;
	queue<long long> q;
	for (int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		switch (c)
		{
		case '+': 
			cin >> a;
			q.push(a);
			sum += a;
			cnt++;
			if (ms.count(a) == 0) ms[a] = make_pair(a, 1);
			else ms[a].second++;
			break;
		case '-':
			a = q.front();
			q.pop();
			sum -= a;
			cnt--;
			if (ms[a].second == 1) ms.erase(a);
			else ms[a].second--;
			break;
		case '?':
			if (cnt != 0 && sum % cnt == 0) cout << ms[sum / cnt].second << endl;
			else cout << 0 << endl;
			break;
		default:
			break;
		}
	}
}