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

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;
	vector<long long> q(200000);
	int be = 0, en = 0;
	for (int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		switch (c)
		{
		case '+': 
			cin >> a;
			q[en++] = a, sum += a;
			cnt++;
			break;
		case '-':
			a = q[be++], sum -= a;
			cnt--;
			break;
		case '?':
			if (cnt != 0 && sum % cnt == 0)
			{
				long long ans = 0, sr = sum / cnt;
				for (int i = be; i < en; i++)
					ans += (q[i] == sr);
				cout << ans << endl;
			}
			else cout << 0 << endl;
			break;
		default:
			break;
		}
	}
}