#include <bits/stdc++.h>
using namespace std;

#define MI            1000000000
#define clr(i, j)     memset(i, j, sizeof(i))
typedef long long     ll;
typedef long double   ld;
typedef vector<int>   vi;
typedef pair<int, int> pii;
ll power(ll x,ll y)
{
    ll temp;
    if( y ==1)
        return x;

    if (y%2 == 0){
        temp = power(x, y/2);
        return temp*temp;
    }
    else{
        temp = power(x, (y-1)/2);
        return x*temp*temp;
    }
}
int to_int(string X)
{
    int in = 0;
    ll p = power(10 , X.size()-1);
    for(int i = 0;i<X.size();i++)
    {
    in += (X[i]-'0')*p;
    p /= 10;
    }
    return in;
}
int gcd(int x, int y)
{
    if(y == 0)
        return x;
    return gcd(y, x%y);
}
vector <string> v, vec;
int main()
{
    int n;
    scanf("%d", &n);
    for(int k=0; k<n; k++)
    {
        char c;
        scanf(" %c", &c);
        string s;
        cin >> s;
        if(c == '+')
        {
            v.push_back(s);
            for(int i=0; i<s.size(); i++)
            {
                int x = s[i]-'0';
                if(x%2 == 0)
                    s[i] = '0';
                else
                    s[i] = '1';
            }
            vec.push_back(s);
        }
        else if(c == '-')
        {
            v.erase(find(v.begin(), v.end(), s));
            for(int i=0; i<s.size(); i++)
            {
                int x = s[i]-'0';
                if(x%2 == 0)
                    s[i] = '0';
                else
                    s[i] = '1';
            }
            vec.erase(find(vec.begin(), vec.end(), s));
        }
        else
        {
            int ans = 0;
            for(int i=0; i<vec.size(); i++)
            {
                int f = 1;
                string zer = "000000000000000000";
                if(vec[i].size() < s.size())
                {
                    int z = s.size()-vec[i].size();
                    if(vec[i] != s.substr(z, vec[i].size()))
                        f = 0;
                    if(s.substr(0, z) != zer.substr(0, z))
                        f = 0;
                }
                else
                {
                    int z = vec[i].size()-s.size();
                    if(s != vec[i].substr(z, s.size()))
                        f = 0;
                    if(vec[i].substr(0, z) != zer.substr(0, z))
                        f = 0;
                }
                if(f == 1)
                    ans++;
            }
            printf("%d\n", ans);
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define MI            1000000000
#define clr(i, j)     memset(i, j, sizeof(i))
typedef long long     ll;
typedef long double   ld;
typedef vector<int>   vi;
typedef pair<int, int> pii;
ll power(ll x,ll y)
{
    ll temp;
    if( y ==1)
        return x;

    if (y%2 == 0){
        temp = power(x, y/2);
        return temp*temp;
    }
    else{
        temp = power(x, (y-1)/2);
        return x*temp*temp;
    }
}
int to_int(string X)
{
    int in = 0;
    ll p = power(10 , X.size()-1);
    for(int i = 0;i<X.size();i++)
    {
    in += (X[i]-'0')*p;
    p /= 10;
    }
    return in;
}
int gcd(int x, int y)
{
    if(y == 0)
        return x;
    return gcd(y, x%y);
}
vector <string> v;
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        char c;
        cin >> c;
        string s;
        cin >> s;
        if(c == '?')
        {
            int ans = 0;
            for(int j=0; j<v.size(); j++)
            {
                bool f = 1;
                if(v[j].size() >= s.size())
                {
                    for(int k=0; k<v[j].size(); k++)
                    {
                        int z = k-(v[j].size()-s.size());
                        int x = (v[j][k]-'0');
                        if(z >= 0)
                        {
                            int y;
                            if(s[z] == '0')
                                y = 2;
                            else
                                y = 1;
                            if(x%y != 0)
                                f = 0;
                        }
                        else if(x%2 != 0)
                            f = 0;
                    }
                }
                else
                {

                    for(int k=0; k<s.size(); k++)
                    {
                        int z = k-(s.size()-v[j].size());
                        //int x = (v[j][k]-'0');
                        if(z < 0 && s[k] == '1')
                            f = 0;
                        else if(z >= 0)
                        {
                            int y;
                            if(s[k] == '1')
                                y = 1;
                            else
                                y = 2;
                            if((v[j][z]-'0')%y == 1)
                                f = 0;
                        }
                    }
                }
                if(f == 1)
                    ans++;
            }
            cout << ans << endl;
        }
        else
        {
            if(c == '+')
                v.push_back(s);
            else
                v.erase(find(v.begin(), v.end(), s));
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define MI            1000000000
#define clr(i, j)     memset(i, j, sizeof(i))
typedef long long     ll;
typedef long double   ld;
typedef vector<int>   vi;
typedef pair<int, int> pii;
ll power(ll x,ll y)
{
    ll temp;
    if( y ==1)
        return x;

    if (y%2 == 0){
        temp = power(x, y/2);
        return temp*temp;
    }
    else{
        temp = power(x, (y-1)/2);
        return x*temp*temp;
    }
}
int to_int(string X)
{
    int in = 0;
    ll p = power(10 , X.size()-1);
    for(int i = 0;i<X.size();i++)
    {
    in += (X[i]-'0')*p;
    p /= 10;
    }
    return in;
}
int gcd(int x, int y)
{
    if(y == 0)
        return x;
    return gcd(y, x%y);
}
vector <string> v;
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        char c;
        cin >> c;
        string s;
        cin >> s;
        if(c == '?')
        {
            int ans = 0;
            for(int j=0; j<v.size(); j++)
            {
                bool f = 1;
                if(v[j].size() >= s.size())
                {
                    for(int k=0; k<v[j].size(); k++)
                    {
                        int z = k-(v[j].size()-s.size());
                        int x = (v[j][k]-'0');
                        if(z >= 0)
                        {
                            int y = s[z]-'0';
                            if(x%2 != y)
                                f = 0;
                        }
                        else if(x%2 != 0)
                            f = 0;
                    }
                }
                else
                {

                    for(int k=0; k<s.size(); k++)
                    {
                        int z = k-(s.size()-v[j].size());
                        //int x = (v[j][k]-'0');
                        if(z < 0 && s[k] == '1')
                            f = 0;
                        else if(z >= 0)
                        {
                            int y = s[k]-'0';
                            if((v[j][z]-'0')%2 != y)
                                f = 0;
                        }
                    }
                }
                if(f == 1)
                    ans++;
            }
            cout << ans << endl;
        }
        else
        {
            if(c == '+')
                v.push_back(s);
            else
                v.erase(find(v.begin(), v.end(), s));
        }
    }
}


//written by Aman Mishra(aspro)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,s,e) for(ll i=s;i<=e;i++)
#define aspro ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pii pair<int,int>
#define INF 10000000000000
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
set<int> st;
#define fi first
#define se second
#define pp pair<pair<char,int>,int>
ll value[5000009];
ll findvalue(ll x)
{
    ll power=1,ans=0;
    while(x!=0)
    {
        ll temp=x%10;
        temp=temp%2;
        if(temp==1)
        {
            ans+=power;
        }
        x=x/10;
        power*=2;
    }
    return ans;
}
int main()
{
    aspro
    ll a;
    //while(1)
    //{cin>>a;cout<<findvalue(a)<<endl;}
    ll n;
    cin>>n;
    f(i,1,n)
    {
        char ch;
        ll x;
        cin>>ch;
        if(ch=='+')
        {
            cin>>x;
            ll y=findvalue(x);
            value[y]++;
        }
        if(ch=='-')
        {
            cin>>x;
            ll y=findvalue(x);
            value[y]--;
        }
        if(ch=='?')
        {
            string str;
            cin>>str;
            int si=str.size();
            ll power=1,val=0;
            for(int i=si-1;i>=0;i--)
            {
                if(str[i]=='1')
                {
                    val+=power;
                }
                power=power*2;
            }
            //cout<<val<<endl;
            cout<<value[val]<<endl;
        }
    }

}


//written by Aman Mishra(aspro)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,s,e) for(ll i=s;i<=e;i++)
#define aspro ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pii pair<int,int>
#define INF 10000000000000
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
set<int> st;
#define fi first
#define se second
#define pp pair<pair<char,int>,int>
ll value[5000009];
#define si(a) scanf("%I64d",&a);
ll findvalue(ll x)
{
    ll power=1,ans=0;
    while(x!=0)
    {
        ll temp=x%10;
        temp=temp%2;
        if(temp==1)
        {
            ans+=power;
        }
        x=x/10;
        power*=2;
    }
    return ans;
}
int main()
{
    //aspro
   // freopen("in.txt","r",stdin);
    ll n;
    si(n);
    f(i,1,n)
    {
        //cout<<"i : "<<i<<endl;
        char ch[2],str[20];
        ll x;
        scanf("%s",ch);
        if(ch[0]=='+')
        {
            si(x);
            ll y=findvalue(x);
            value[y]++;
        }
        if(ch[0]=='-')
        {
            si(x);
            ll y=findvalue(x);
            value[y]--;
        }
        if(ch[0]=='?')
        {
            //string str;
            //cin.ignore();
            scanf("%s",str);
            int si=strlen(str);
            ll power=1,val=0;
            for(int i=si-1;i>=0;i--)
            {
                if(str[i]=='1')
                {
                    val+=power;
                }
                power=power*2;
            }
            //cout<<val<<endl;
            printf("%I64d\n",value[val]);
        }
    }

}


//written by Aman Mishra(aspro)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,s,e) for(ll i=s;i<=e;i++)
#define aspro ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pii pair<int,int>
#define INF 10000000000000
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
set<int> st;
#define fi first
#define se second
#define pp pair<pair<char,int>,int>
ll value[5000009];
#define si(a) scanf("%I64d",&a);
ll findvalue(ll x)
{
    ll power=1,ans=0;
    while(x!=0)
    {
        ll temp=x%10;
        temp=temp%2;
        if(temp==1)
        {
            ans+=power;
        }
        x=x/10;
        power*=2;
    }
    return ans;
}
int main()
{
    //aspro
    ll n;
    si(n);
    f(i,1,n)
    {
        //cout<<"i : "<<i<<endl;
        char ch;
        ll x;
        cin>>ch;
        if(ch=='+')
        {
            si(x);
            ll y=findvalue(x);
            value[y]++;
        }
        if(ch=='-')
        {
            si(x);
            ll y=findvalue(x);
            value[y]--;
        }
        if(ch=='?')
        {
            string str;
            //cin.ignore();
            cin>>str;
            int si=str.size();
            ll power=1,val=0;
            for(int i=si-1;i>=0;i--)
            {
                if(str[i]=='1')
                {
                    val+=power;
                }
                power=power*2;
            }
            //cout<<val<<endl;
            printf("%I64d\n",value[val]);
        }
    }

}


//written by Aman Mishra(aspro)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,s,e) for(ll i=s;i<=e;i++)
#define aspro ios_base::sync_with_stdio(0);cin.tie(0);
#define pb push_back
#define pii pair<int,int>
#define INF 10000000000000
#define MOD 1000000007
#define test int t;cin>>t;while(t--)
set<int> st;
#define fi first
#define se second
#define pp pair<pair<char,int>,int>
ll value[100009];
ll findvalue(ll x)
{
    ll power=1,ans=0;
    while(x!=0)
    {
        ll temp=x%10;
        temp=temp%2;
        if(temp==1)
        {
            ans+=power;
        }
        x=x/10;
        power*=2;
    }
    return ans;
}
int main()
{
    aspro
    ll a;
    //while(1)
    //{cin>>a;cout<<findvalue(a)<<endl;}
    ll n;
    cin>>n;
    f(i,1,n)
    {
        char ch;
        ll x;
        cin>>ch;
        if(ch=='+')
        {
            cin>>x;
            ll y=findvalue(x);
            value[y]++;
        }
        if(ch=='-')
        {
            cin>>x;
            ll y=findvalue(x);
            value[y]--;
        }
        if(ch=='?')
        {
            string str;
            cin>>str;
            int si=str.size();
            ll power=1,val=0;
            for(int i=si-1;i>=0;i--)
            {
                if(str[i]=='1')
                {
                    val+=power;
                }
                power=power*2;
            }
            //cout<<val<<endl;
            cout<<value[val]<<endl;
        }
    }

}


#include <iostream>
#include <string>
#include <unordered_map>

unsigned mask(unsigned long long number)
{
    unsigned result = 0;
    for (unsigned mask = 1; number > 0; mask <<= 1) {
        if (number % 2) {
            result += mask;
        }
        number /= 10;
    }
    return result;
}

int main()
{
    int t;
    std::cin >> t;

    std::unordered_map<unsigned long long, int> numbers;
    std::unordered_map<unsigned, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned mask = std::stoi(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include <iostream>
#include <string>
#include <unordered_map>

unsigned mask(unsigned long long number)
{
    unsigned result = 0;
    for (unsigned long long mask = 1; number > 0; mask <<= 1) {
        if (number % 2) {
            result |= mask;
        }
        number /= 10;
    }
    return result;
}

int main()
{
    int t;
    std::cin >> t;

    std::unordered_map<unsigned long long, int> numbers;
    std::unordered_map<unsigned, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned mask = std::stoi(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include <iostream>
#include <string>
#include <map>

unsigned mask(unsigned long long number)
{
    unsigned m = 0;
    for (int i = 0; number > 0; i++) {
        if (number % 2) {
            m += (1ull << i);
        }
        number /= 10;
    }
    return m;
}

int main()
{
    int t;
    std::cin >> t;

    std::map<unsigned long long, int> numbers;
    std::map<unsigned, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned mask = std::stoi(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include <iostream>
#include <string>
#include <unordered_map>

unsigned mask(unsigned long long number)
{
    unsigned result = 0;
    for (unsigned long long mask = 1; number > 0; mask <<= 1) {
        if (number % 2) {
            result += mask;
        }
        number /= 10;
    }
    return result;
}

int main()
{
    int t;
    std::cin >> t;

    std::unordered_map<unsigned long long, int> numbers;
    std::unordered_map<unsigned, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned mask = std::stoi(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include <iostream>
#include <string>
#include <map>

unsigned long long mask(unsigned long long number)
{
    unsigned long long m = 0;
    for (int i = 0; number > 0; i++) {
        if (number % 2) {
            m += (1ull << i);
        }
        number /= 10;
    }
    return m;
}

int main()
{
    int t;
    std::cin >> t;

    std::map<unsigned long long, int> numbers;
    std::map<unsigned long long, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned long long mask = std::stoll(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include <iostream>
#include <string>
#include <unordered_map>

unsigned mask(unsigned long long number)
{
    unsigned m = 0;
    for (int i = 0; number > 0; i++) {
        if (number % 2) {
            m += (1ull << i);
        }
        number /= 10;
    }
    return m;
}

int main()
{
    int t;
    std::cin >> t;

    std::unordered_map<unsigned long long, int> numbers;
    std::unordered_map<unsigned, int> masks;

    for (int i = 0; i < t; i++) {
        char op;
        std::string numString;
        std::cin >> op >> numString;

        if (op == '+') {
            unsigned long long number = std::stoll(numString);
            numbers[number]++;
            masks[mask(number)]++;
        } else if (op == '-') {
            unsigned long long number = std::stoll(numString);
            numbers[number]--;
            masks[mask(number)]--;
        } else if (op == '?') {
            unsigned mask = std::stoi(numString, nullptr, 2);
            std::cout << masks[mask] << std::endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

int varLength , signLength;

bool MatchPattern(ll  number , ll num)
{
    ll shit  = (varLength >= signLength)? number : num;
//        cout<<shit<<endl;
        while(shit)
        {
            int x = number%10 , y = num%10;
//            cout<<x<<' '<<y<<endl;
            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
               return 0;

            number/=10;
            num/=10;
            shit/=10;
        }
   return 1;
}

int main()
{
    Ryuzaki;

    int t;

    cin>>t;

    unordered_map<ll , int>s;

    while(t--)
    {
        char sign;
        ll num;

            cin>>sign>>num;

        if(sign=='+')
            s[num]++;
        else if(sign=='-')
            s[num]--;
        else
        {
            ll cnt=0;
            signLength = 1+log10(num);

            for(auto it = s.begin(); it!=s.end(); it++)
            {
                if(it->S > 0)
                {
                    varLength = 1 + log10(it->F);
                    cnt+= 1ll* (it->S) * MatchPattern(it->F,num);
                }
            }
                cout<<cnt<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

//int varLength , signLength;

ll MatchPattern( ll num)
{
        ll pattern = 0;
        while(num)
        {
            int x = num%10;
            if(x&1)
                pattern= pattern*10+1;
            else
                pattern = pattern*10+0;
            num/=10;
        }
        return pattern;

//    ll shit  = (varLength >= signLength)? number : num;
//
//        while(shit)
//        {
//            int x = number%10 , y = num%10;
//
//            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
//               return 0;
//
//            number/=10;
//            num/=10;
//            shit/=10;
//        }
//   return 1;
}
pair<ll,ll> reversee(ll num)
{
    ll reversedNumber = 0;
    ll zeroes = 0;
    bool flag =0;
    while(num)
    {
        int x = num%10;
        if(x==0&&flag==0)
            zeroes++;
        else
            flag = 1;

        reversedNumber = reversedNumber*10+x;
        num/=10;
    }
    return {reversedNumber , zeroes };
}
int main()
{
    Ryuzaki;

    int t;
    unordered_map<ll , int>s;
    cin>>t;

    while(t--)
    {
        char sign; // + 362100027803823236 100100001001001010
        ll num;
        cin>>sign>>num;

        pair<ll,ll> temp = reversee(num);
//        cout<<temp.first<<' ';

        ll ten =1;
        for(int i=0;i<temp.second;i++)
            ten*=10;

        temp.first = MatchPattern(temp.first) * ten;
//        cout<<"fjlksjf  "<<temp.first<<endl;
        if(sign=='+')
            s[temp.first]++;
        else if(sign=='-')
            s[temp.first]--;
        else
            cout<<s[temp.first]<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

int varLength , signLength;

bool MatchPattern(ll  number , ll num)
{
    int shit  = (varLength >= signLength)? number : num;
//        cout<<shit<<endl;
        while(shit)
        {
            int x = number%10 , y = num%10;
//            cout<<x<<' '<<y<<endl;
            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
               return 0;

            number/=10;
            num/=10;
            shit/=10;
        }
   return 1;
}

int main()
{
    Ryuzaki;

    int t;
//    scanf("%d\n",&t);
        cin>>t;

    unordered_map<ll , int>s;

    while(t--)
    {
        char sign;
        ll num;
//        scanf("%c %lld",&sign,&num);
            cin>>sign>>num;

        if(sign=='+')
            s[num]++;
        else if(sign=='-')
            s[num]--;
        else
        {
            int cnt=0;
            signLength = 1+log10(num);

            for(auto it = s.begin(); it!=s.end(); it++)
            {
                if(it->S > 0)
                {
                    varLength = 1 + log10(it->F);
                    cnt+= (it->S) * MatchPattern(it->F,num);
                }
            }
//            printf("%d\n",cnt);
                cout<<cnt<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

//int varLength , signLength;

ll MatchPattern( ll num)
{
        ll pattern = 0;
        while(num)
        {
            int x = num%10;
            if(x&1)
                pattern= pattern*10+1;
            else
                pattern = pattern*10+0;
            num/=10;
        }
        return pattern;

//    ll shit  = (varLength >= signLength)? number : num;
//
//        while(shit)
//        {
//            int x = number%10 , y = num%10;
//
//            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
//               return 0;
//
//            number/=10;
//            num/=10;
//            shit/=10;
//        }
//   return 1;
}
pair<ll,ll> reversee(ll num)
{
    ll reversedNumber = 0;
    ll zeroes = 0;
    bool flag =0;
    while(num)
    {
        int x = num%10;
        if(x==0&&flag==0)
            zeroes++;
        else
            flag = 1;

        reversedNumber = reversedNumber*10+x;
        num/=10;
    }
    return {reversedNumber , zeroes };
}
int main()
{
    Ryuzaki;

    int t;
    unordered_map<ll , int>s;
    cin>>t;

    while(t--)
    {
        char sign;
        ll num;
        cin>>sign>>num;

        pair<ll,ll> temp = reversee(num);
        //cout<<temp.first<<' ';
        temp.first = MatchPattern(temp.first) * pow(10,temp.second);
       // cout<<"fjlksjf  "<<temp.first<<endl;
        if(sign=='+')
            s[temp.first]++;
        else if(sign=='-')
            s[temp.first]--;
        else
            cout<<s[temp.first]<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

int varLength , signLength;

bool MatchPattern(ll  number , ll num)
{
    int shit  = (varLength >= signLength)? number : num;
//        cout<<shit<<endl;
        while(shit)
        {
            int x = number%10 , y = num%10;
//            cout<<x<<' '<<y<<endl;
            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
               return 0;

            number/=10;
            num/=10;
            shit/=10;
        }
   return 1;
}

int main()
{
    Ryuzaki;

    int t;

    cin>>t;

    unordered_map<ll , int>s;

    while(t--)
    {
        char sign;
        ll num;

            cin>>sign>>num;

        if(sign=='+')
            s[num]++;
        else if(sign=='-')
            s[num]--;
        else
        {
            ll cnt=0;
            signLength = 1+log10(num);

            for(auto it = s.begin(); it!=s.end(); it++)
            {
                if(it->S > 0)
                {
                    varLength = 1 + log10(it->F);
                    cnt+= (it->S) * MatchPattern(it->F,num);
                }
            }
                cout<<cnt<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

int varLength , signLength;

bool MatchPattern(ll  number , ll num)
{
    int shit  = (varLength >= signLength)? number : num;
//        cout<<shit<<endl;
        while(shit)
        {
            int x = number%10 , y = num%10;
//            cout<<x<<' '<<y<<endl;
            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
               return 0;

            number/=10;
            num/=10;
            shit/=10;
        }
   return 1;
}

int main()
{
    Ryuzaki;

    int t;

    cin>>t;

    unordered_map<ll , int>s;

    while(t--)
    {
        char sign;
        ll num;

            cin>>sign>>num;

        if(sign=='+')
            s[num]++;
        else if(sign=='-')
            s[num]--;
        else
        {
            ll cnt=0;
            signLength = 1+log10(num);

            for(auto it = s.begin(); it!=s.end(); it++)
            {
                if(it->S > 0)
                {
                    varLength = 1 + log10(it->F);
                    cnt+= 1ll* (it->S) * MatchPattern(it->F,num);
                }
            }
                cout<<cnt<<endl;
        }

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

//int varLength , signLength;

ll MatchPattern( ll num)
{
        ll pattern = 0;
        while(num)
        {
            int x = num%10;
            if(x&1)
                pattern= pattern*10+1;
            else
                pattern = pattern*10+0;
            num/=10;
        }
        return pattern;

//    ll shit  = (varLength >= signLength)? number : num;
//
//        while(shit)
//        {
//            int x = number%10 , y = num%10;
//
//            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
//               return 0;
//
//            number/=10;
//            num/=10;
//            shit/=10;
//        }
//   return 1;
}
ll reversee(ll num)
{
    ll reversedNumber = 0;

    while(num)
    {
        int x = num%10;
        reversedNumber = reversedNumber*10+x;
        num/=10;
    }
    return reversedNumber;
}
int main()
{
    Ryuzaki;

    int t;
    unordered_map<ll , int>s;
    cin>>t;

    while(t--)
    {
        char sign;
        ll num;
        cin>>sign>>num;

        ll temp = reversee(num);
        temp = MatchPattern(temp);
//        cout<<"fjlksjf  "<<temp<<endl;
        if(sign=='+')
            s[temp]++;
        else if(sign=='-')
            s[temp]--;
        else
            cout<<s[temp]<<endl;

    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-10;
const int OO = 2147483647;
typedef complex<double> point;

#define ll long long
#define ull unsinged long long
#define Ryuzaki ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0)
#define F first
#define S second

/*
* I'm L , and i'm gonna catch you Kira
*     ___
*    |\  \
*    \ \  \
*     \ \  \
*      \ \  \____
*       \ \_______\
*        \|_______|
*/

//geometry
#define X real()
#define Y imag()
#define angle(a) (atan2(a.imag() , a.real()))
#define vec(a , b) (b - a)
#define length(a) (hypot((a).imag(), (a).real()))
#define normalize(a) a/length(a)
#define dp(a , b) ((conj(a)*b).real())
#define cp(a , b) ((conj(a)*b).imag())
#define same(p1, p2) (dp(vec(p1 , p2),vec(p1 , p2)<EPS))
#define lengthSqr(p) (dp(p , p))
#define rotate0(p , ang) (p * exp(point(0 , ang)))
#define rotateA(p,ang,about) (rotate0(vec(about , p),ang)+about)
#define reflect0(v ,m) (conj(v/m)*m)

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};

bool cmp(int i , int j)
{
    return i>j;
}

//int varLength , signLength;

ll MatchPattern( ll num)
{
        ll pattern = 0;
        while(num)
        {
            int x = num%10;
            if(x&1)
                pattern= pattern*10+1;
            else
                pattern = pattern*10+0;
            num/=10;
        }
        return pattern;

//    ll shit  = (varLength >= signLength)? number : num;
//
//        while(shit)
//        {
//            int x = number%10 , y = num%10;
//
//            if( (y==1&&(x%2==0) ) || (y==0&&(x%2==1)))
//               return 0;
//
//            number/=10;
//            num/=10;
//            shit/=10;
//        }
//   return 1;
}
pair<ll,ll> reversee(ll num)
{
    ll reversedNumber = 0;
    ll zeroes = 0;
    bool flag =0;
    while(num)
    {
        int x = num%10;
        if(x==0&&flag==0)
            zeroes++;
        else
            flag = 1;

        reversedNumber = reversedNumber*10+x;
        num/=10;
    }
    return {reversedNumber , zeroes };
}
int main()
{
    Ryuzaki;

    int t;
    unordered_map<ll , int>s;
    cin>>t;

    while(t--)
    {
        char sign; // + 362100027803823236 100100001001001010
        ll num;
        cin>>sign>>num;

        pair<ll,ll> temp = reversee(num);
//        cout<<temp.first<<' ';

        int ten =1;
        for(int i=0;i<temp.second;i++)
            ten*=10;

        temp.first = MatchPattern(temp.first) * ten;
//        cout<<"fjlksjf  "<<temp.first<<endl;
        if(sign=='+')
            s[temp.first]++;
        else if(sign=='-')
            s[temp.first]--;
        else
            cout<<s[temp.first]<<endl;

    }
    return 0;
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	set<string> S;
	map<string, int> m;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s, t;

		cin >> s >> t;
		if (s == "+")
		{
			S.insert(t);
			m[t]++;
		}
		else if (s == "-")
		{
			if (m[t] == 1) S.erase(t);
			else m[t]--;
		}
		else
		{
			int plen = t.length(), ans = 0;
			for (auto it = S.begin(); it != S.end(); it++)
			{
				int len = it->length();
				auto p = *it;
				bool f = true;
				for (int j = plen - 1; j >= 0 || len>0; j--)
				{
					char cmp, cmp2;
					len--;
					if (len < 0) cmp = '0';
					else if ((p[len] - '0') % 2 == 0) cmp = '0';
					else cmp = '1';
					if (j < 0) cmp2 = '0';
					else cmp2 = t[j];
					if (cmp != cmp2)
					{
						f = false;
						break;
					}
				}
				if (f) ans += m[p];
			}
			cout << ans << "\n";
		}
	}
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	map<int, int> m[20];
	cin >> n;
	for (int tc = 0; tc < n; tc++)
	{
		string s, p;
		long long t;

		cin >> s;
		if (s == "+")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j = 1; i<20; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]++;
				t /= 10;
			}
		}
		else if (s == "-")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j = 1; i<20; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]--;
				t /= 10;
			}
		}
		else
		{
			cin >> p;
			int i=0, j = 1, parity = 0, len = p.length() - 1;
			bool f = true;
			for (;i<19; i++,len--)
			{
				if (len>=0 && p[len] == '1') parity += j;
				if (!m[i].count(parity))
				{
					f = false;
					break;
				}
				j *= 2;
			}
			if (f)
			{
				i--;
				cout << m[i][parity] << "\n";
			}
			else cout << "0\n";
		}
	}
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	int n;
	set<string> S;
	map<string, int> m;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s, t;

		cin >> s >> t;
		if (s == "+")
		{
			S.insert(t);
			m[t]++;
		}
		else if (s == "-")
		{
			if (m[t] == 1) S.erase(t);
			else m[t]--;
		}
		else
		{
			int plen = t.length(), ans = 0;
			for (auto it = S.begin(); it != S.end(); it++)
			{
				int len = it->length();
				auto p = *it;
				bool f = true;
				for (int j = plen - 1; j >= 0 || len>0; j--)
				{
					char cmp, cmp2;
					len--;
					if (len < 0) cmp = '0';
					else if ((p[len] - '0') % 2 == 0) cmp = '0';
					else cmp = '1';
					if (j < 0) cmp2 = '0';
					else cmp2 = t[j];
					if (cmp != cmp2)
					{
						f = false;
						break;
					}
				}
				if (f) ans += m[p];
			}
			cout << ans << "\n";
		}
	}
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	map<int, int> m[20];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s, p;
		long long t;

		cin >> s;
		if (s == "+")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j = 1; i<20; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]++;
				t /= 10;
			}
		}
		else if (s == "-")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j = 1; i<20; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]--;
				t /= 10;
			}
		}
		else
		{
			cin >> p;
			int j = 1, parity = 0, len = p.length() - 1;
			bool f = true;
			for (int i=0; i<19; i++,len--)
			{
				if (len>=0 && p[len] == '1') parity += j;
				if (!m[i].count(parity))
				{
					f = false;
					break;
				}
				i++, j *= 2;
			}
			if (f)
			{
				i--;
				cout << m[i][parity] << "\n";
			}
			else cout << "0\n";
		}
	}
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	map<int, int> m[20];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s,p;
		long long t;

		cin >> s;
		if (s == "+")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j=1; i<20; i++,j*=2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]++;
				t /= 10;
			}
		}
		else if (s == "-")
		{
			cin >> t;
			int parity = 0;
			for (int i = 0, j = 1; i<20; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]--;
				t /= 10;
			}
		}
		else
		{
			cin >> p;
			int i = 0, j = 1, parity = 0, len = p.length()-1;
			bool f = true;
			for(;len>=0;len--)
			{
				if (p[len] == '1') parity += j;
				if (!m[i].count(parity))
				{
					f = false;
					break;
				}
				i++, j*=2;
			}
			if (f)
			{
				i--;
				cout << m[i][parity] << "\n";
			}
			else cout << "0\n";
		}
	}
}


#include<set>
#include<map>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	set<string> S;
	map<int, int> m[20];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		string s,p;
		long long t;

		cin >> s;
		if (s == "+")
		{
			cin >> t;
			long long parity = 0;
			for (int i = 0, j=1; i<19; i++,j*=2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]++;
				t /= 10;
			}
		}
		else if (s == "-")
		{
			cin >> t;
			long long parity = 0;
			for (int i = 0, j = 1; i<19; i++, j *= 2)
			{
				long long rem = t % 10;
				if (rem % 2 == 1) parity += j;
				m[i][parity]--;
				t /= 10;
			}
		}
		else
		{
			cin >> p;
			long long parity = 0, len=p.length(), j=1;
			int i = 0, ans = 0;
			bool f = true;
			while(len--)
			{
				if (p[len] == '1') parity += j;
				if (!m[i].count(parity))
				{
					f = false;
					break;
				}
				i++, j*=2;
			}
			if (f)
			{
				i--;
				cout << m[i][parity] << "\n";
			}
			else cout << "0\n";
		}
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

map<string, int> m;

int main(){

    int q;
    cin >> q;

    while(q--){

        char t; string s;
        cin >> t >> s;

        if(t == '+')
            for(int i = 0; i < s.size(); ++i)
                s[i] = ('0' + (s[i] - '0') % 2);

        reverse(s.begin(), s.end());

        while(s.size() < 18) s.push_back('0');

        if(t == '+') m[s]++;
        else if(t == '-') m[s]--;
        else if(t == '?')
            cout << m[s] << endl;
    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//map<string, int> m;

int cnt[1 << 20];

struct trie{

    void insert(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
            cnt[po]++;
        }
    }

    void erase(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
            cnt[po]--;
        }
    }

    int count(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
        }

        return cnt[po];
    }

} tt;

int main(){

    int q;
    cin >> q;

    while(q--){

        char t, s[19];
        cin >> t >> s;

        int l = strlen(s);

        for(int i = 0; i < l; ++i)
            s[i] = ((s[i] - '0') & 1) + '0';

        reverse(s, s+l);

        // cout << string(s) << endl;

        for(int x = l; x < 18; ++x ) s[x] = '0';

        //cout << string(s) << endl;

        if(t == '+') tt.insert(s);
        else if(t == '-') tt.erase(s);
        else cout << tt.count(s) << endl;

    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

map<char*, int> m;

int main(){

    int q;
    cin >> q;

    while(q--){

        char t; char s[20];
        cin >> t >> s;

        int l = strlen(s);

        for(int i = 0; i < l; ++i)
            s[i] = ('0' + (s[i] - '0') & 1);

        reverse(s, s+l);

        for(int x = l; x < 18; ++x ) s[x] = '0';

        if(t == '+') m[s]++;
        else if(t == '-') m[s]--;
        else if(t == '?')
            cout << m[s] << endl;
    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//map<string, int> m;

int cnt[1 << 19];

struct trie{

    void insert(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
            cnt[po]++;
        }
    }

    void erase(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
            cnt[po]--;
        }
    }

    int count(char* s){
        int po = 1, c;
        for(int i = 0; i < 18; ++i){
            c = (s[i] - '0');
            po = po*2 + c;
        }

        return cnt[po];
    }

} tt;

int main(){

    int q;
    scanf("%d ", &q);

    while(q--){

        char t, s[19];
        scanf(" %c %s", &t, s);

        int l = strlen(s);

        for(int i = 0; i < l; ++i)
            s[i] = ((s[i] - '0') & 1) + '0';

        reverse(s, s+l);

        // cout << string(s) << endl;

        for(int x = l; x < 18; ++x ) s[x] = '0';

        //cout << string(s) << endl;

        if(t == '+') tt.insert(s);
        else if(t == '-') tt.erase(s);
        else printf("%d\n", tt.count(s));

    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

map<string, int> m;

int main(){

    int q;
    cin >> q;

    while(q--){

        char t; string s;
        cin >> t >> s;

        for(int i = 0; i < s.size(); ++i)
            s[i] = ('0' + (s[i] - '0') % 2);

        reverse(s.begin(), s.end());

        while(s.size() < 18) s.push_back('0');

        if(t == '+') m[s]++;
        else if(t == '-') m[s]--;
        else if(t == '?')
            cout << m[s] << endl;
    }

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

map<string, int> m;

int main(){

    int q;
    cin >> q;

    while(q--){

        char t, s[19];
        cin >> t >> s;

        int l = strlen(s);

        for(int i = 0; i < l; ++i)
            s[i] = ((s[i] - '0') & 1) + '0';

        reverse(s + 0, s+l);

        // cout << string(s) << endl;

        for(int x = l; x < 18; ++x ) s[x] = '0';

        //cout << string(s) << endl;

        if(t == '+') m[s]++;
        else if(t == '-') m[s]--;
        else
            cout << m[s] << endl;

    }

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <string>
using namespace std;

const int LEN = 1048576;

int main()
{
	int* cnt = new int[LEN];
	fill(cnt, cnt+LEN, 0);
	int T;
	cin >> T;
	for(int t = 0; t < T; ++t)
	{
		char c;
		cin >> c;
		if(c == '+' || c == '-')
		{
			string s;
			cin >> s;
			for(int i = 0; i < (int)s.size(); ++i)
			{
				s[i] = ((s[i]-'0') % 2) + '0';
			}

			unsigned long pat = 0;
			bitset<20> b(s);
			pat = b.to_ulong();
			cnt[pat] += (c == '+' ? 1 : -1);
		}
		else
		{
			string s;
			cin >> s;
			bitset<20> b(s);
			unsigned long pat = b.to_ulong();
			cout << cnt[pat] << endl;
		}
	}
	delete[] cnt;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

const int LEN = 1048576;

int main()
{
	int* cnt = new int[LEN];
	fill(cnt, cnt+LEN, 0);
	int T;
	cin >> T;
	for(int t = 0; t < T; ++t)
	{
		char c;
		cin >> c;
		if(c == '+' || c == '-')
		{
			int pat = 0;
			long long tmp;
			cin >> tmp;
			int offset = 0;
			while(tmp)
			{
				int i = (tmp % 10) % 2;
				tmp /= 10;
				pat |= (i << offset);
				++offset;
			}
			//cout << pat << " ";
			cnt[pat] += (c == '+' ? 1 : -1);
			//cout << cnt[pat] << endl;
		}
		else
		{
			string s;
			cin >> s;
			bitset<20> b(s);
			unsigned long pat = b.to_ulong();
			cout << cnt[pat] << endl;
		}
	}
	delete[] cnt;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

const int LEN = 1048576;

int main()
{
	int* cnt = new int[LEN];
	fill(cnt, cnt+LEN, 0);
	int T;
	cin >> T;
	for(int t = 0; t < T; ++t)
	{
		char c;
		cin >> c;
		if(c == '+' || c == '-')
		{
			int pat = 0;
			long long tmp;
			cin >> tmp;
			int offset = 0;
			while(tmp)
			{
				int i = (tmp % 10) % 2;
				tmp /= 10;
				pat |= (i << offset);
				++offset;
			}
			//cout << pat << " ";
			cnt[pat] += (c == '+' ? 1 : -1);
			//cout << cnt[pat] << endl;
		}
		else
		{
			long long tmp;
			cin >> tmp;
			int pat = 0, offset = 0;
			while(tmp)
			{
				pat |= ((tmp%10) << offset);
				++offset;
				tmp /= 10;
			}
			cout << cnt[pat] << endl;
		}
	}
	delete[] cnt;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
using namespace std;

const int LEN = 1048576;

int main()
{
	int* cnt = new int[LEN];
	fill(cnt, cnt+LEN, 0);
	int T;
	cin >> T;
	for(int t = 0; t < T; ++t)
	{
		char c;
		cin >> c;
		if(c == '+' || c == '-')
		{
			unsigned long pat = 0;
			long long tmp;
			cin >> tmp;
			string s;
			while(tmp)
			{
				s += to_string((tmp%10)%2);
				tmp /= 10;
			}
			reverse(s.begin(), s.end());
			bitset<20> b(s);
			pat = b.to_ulong();
			//cout << pat << " ";
			cnt[pat] += (c == '+' ? 1 : -1);
			//cout << cnt[pat] << endl;
		}
		else
		{
			string s;
			cin >> s;
			bitset<20> b(s);
			unsigned long pat = b.to_ulong();
			cout << cnt[pat] << endl;
		}
	}
	delete[] cnt;
	return 0;
}


#include <cstdio>
#include <vector>
#include <cstdlib>
#include <utility>
using namespace std;

class Dsu
{
public:
	vector<int> p, rank;
	vector<long long> sum;

	Dsu(int n)
	{
		rank.assign(n, -1);
		sum.assign(n, 0);
		p.resize(n);
		for(int i = 0; i < n; ++i)
			p[i] = i;
	}
	void add(int a, int s)
	{
		rank[a] = 0;
		sum[a] = s;
	}
	int findSet(int a)
	{
		return (p[a] == a ? a : (p[a] = findSet(p[a])));
	}
	void unionSets(int a, int b)
	{
		int x = findSet(a), y = findSet(b);
		if(x == y)
			return;
		if(rank[x] < rank[y])
			p[x] = y;
		else if(rank[x] > rank[y])
			p[y] = x;
		else
		{
			p[x] = y;
			++rank[y];
		}

	}
};

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> a(n), ord(n);
	vector<long long> res(n);
	for(int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	for(int i = 0; i < n; ++i)
		scanf("%d", &ord[i]);

	Dsu dsu(n);
	long long maxsum = 0;
	res[n-1] = 0;
	for(int j = n-1; j > 0; --j)
	{
		int i = ord[j]-1;
		dsu.add(i, a[i]);
		if(i < n-1 && dsu.rank[i+1] != -1)
		{
			long long old = dsu.sum[dsu.findSet(i+1)], old1 = dsu.sum[dsu.findSet(i)];
			dsu.unionSets(i, i+1);
			dsu.sum[dsu.findSet(i)] = old + old1;
		}
		if(i > 0 && dsu.rank[i-1] != -1)
		{
			long long old = dsu.sum[dsu.findSet(i-1)], old1 = dsu.sum[dsu.findSet(i)];
			dsu.unionSets(i, i-1);
			dsu.sum[dsu.findSet(i)] = old + old1;
		}
		maxsum = max(maxsum, dsu.sum[dsu.findSet(i)]);
		res[j-1] = maxsum;
	}
	for(int i = 0; i < n; ++i)
		printf("%lld\n", res[i]);

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#include <string>
using namespace std;

const int LEN = 1048576;

int main()
{
	int* cnt = new int[LEN];
	fill(cnt, cnt+LEN, 0);
	int T;
	cin >> T;
	for(int t = 0; t < T; ++t)
	{
		char c;
		cin >> c;
		if(c == '+' || c == '-')
		{
			string s;
			cin >> s;
			for(int i = 0; i < (int)s.size(); ++i)
			{
				s[i] = ((s[i]-'0') % 2) + '0';
			}

			unsigned long pat = 0;
			/*long long tmp;
			cin >> tmp;
			string s;
			while(tmp)
			{
				s += to_string((tmp%10)%2);
				tmp /= 10;
			}
			reverse(s.begin(), s.end());*/
			bitset<20> b(s);
			pat = b.to_ulong();
			//cout << pat << " ";
			cnt[pat] += (c == '+' ? 1 : -1);
			//cout << cnt[pat] << endl;
		}
		else
		{
			string s;
			cin >> s;
			bitset<20> b(s);
			unsigned long pat = b.to_ulong();
			cout << cnt[pat] << endl;
		}
	}
	delete[] cnt;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

LL p[300000];
char ch, s[50];

int main()
{
    int n,bin;
    scanf("%d",&n);
    for(int i = 0; i<n; i++)
    {
        getchar();
        scanf("%c%s",&ch,s);
        bin = 0;
        for(int j = 0,len = strlen(s); j<len; j++)
        {
            bin <<= 1;
            if((s[j]-'0')&1)
                bin++;
        }

        if(ch=='+')
            p[bin]++;
        else if(ch=='-')
            p[bin]--;
        else
            printf("%lld\n",p[bin]);
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<LL,LL>m;
map<LL,LL>::iterator it;
char s[50];
LL num;
int pi[20];

int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }

            num += 2e18;
            if(m.find(num)!=m.end())
                m[num]++;
            else
                m[num] = 1;
        }

        else if(s[0] == '-')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }

            num += 2e18;
            m[num]--;
        }

        else
        {
            memset(pi,0,sizeof(pi));
            int j = strlen(s)-1, now = 18;
            for(;j>=2; j--)
            {
                pi[now--] = s[j]-'0';
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                //cout<<it->first<<endl;
                int B = 1;
                num = it->first;
                if(m[num]==0) {it++; continue;}
                for(int j = 18; j>0; j--)
                {
                    if((pi[j]+(num)%10)%2==1) {B = 0; break;}
                    num /= 10;
                }

                if(B)
                    sum += it->second;

                it++;
            }

            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<string,LL>m;
map<string,LL>::iterator it;
char s[50];
LL num;
char pi[50];
string node;
char tmp;
int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }

            if(m.find(node)!=m.end())
                m[node]++;
            else
                m[node] = 1;
        }

        else if(s[0] == '-')
        {
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }
            m[node]--;
        }

        else
        {
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                if(m[node]==0) {it++; continue;}
                if(node==it->first)
                    sum += it->second;
                it++;
            }
            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<LL,LL>m;
map<LL,LL>::iterator it;
char s[50];
LL num;
int pi[20];

int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }

            num += 2e18;
            if(m.find(num)!=m.end())
                m[num]++;
            else
                m[num] = 1;
        }

        else if(s[0] == '-')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }

            num += 2e18;
            m[num]--;

            //cout<<m[num]<<endl;
        }

        else
        {
            memset(pi,0,sizeof(pi));
            int j = strlen(s)-1, now = 18;
            for(;j>=2; j--)
            {
                pi[now--] = s[j]-'0';
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                //cout<<it->first<<endl;
                int B = 1;
                num = it->first;
                for(int j = 18; j>0; j--)
                {
                    if((pi[j]+(num)%10)%2==1) {B = 0; break;}
                    num /= 10;
                }

                if(B)
                    sum += it->second;

                it++;
            }

            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<string,LL>m;
map<string,LL>::iterator it;
char s[50];
char pi[50];
string node;
char tmp;
int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }

            if(m.find(node)!=m.end())
                m[node]++;
            else
                m[node] = 1;
        }

        else if(s[0] == '-')
        {
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }
            m[node]--;
        }

        else
        {
            int cnt = 0;
            for(int j = 0; j<20; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 19; j>=0; j--)
            {
                node += pi[j];
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                if(node==it->first)
                {
                    sum += it->second;
                    break;
                }
                it++;
            }
            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

LL p[300000];
LL a,sum;
char ch, s[50];
int main()
{
    int n;
    cin>>n;
    for(int i = 0; i<n; i++)
    {
        cin>>ch>>s;
        sum = 0;
        for(int j = 0; j<strlen(s); j++)
        {
            sum <<= 1;
            if((s[j]-'0')&1)
                sum++;
        }

        if(ch=='+')
        {
           p[sum]++;
        }

        else if(ch=='-')
        {
            p[sum]--;
        }
        else
        {
            cout<<p[sum]<<endl;
        }
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

LL p[300000];
LL a,sum;
char ch, s[50];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0; i<n; i++)
    {
        getchar();
        scanf("%c%s",&ch,s);
        sum = 0;
        for(int j = 0,len = strlen(s); j<len; j++)
        {
            sum <<= 1;
            if((s[j]-'0')&1)
                sum++;
        }

        if(ch=='+')
            p[sum]++;
        else if(ch=='-')
            p[sum]--;
        else
            printf("%lld\n",p[sum]);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

LL p[300000];
char ch, s[50];

int main()
{
    int n,bin;
    scanf("%d",&n);
    for(int i = 0; i<n; i++)
    {
        getchar();
        scanf("%c%s",&ch,s);
        bin = 0;
        for(int j = 0; j<strlen(s); j++)
        {
            bin <<= 1;
            if((s[j]-'0')&1)
                bin++;
        }

        if(ch=='+')
            p[bin]++;
        else if(ch=='-')
            p[bin]--;
        else
            printf("%lld\n",p[bin]);
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<string,LL>m;
map<string,LL>::iterator it;
char s[50];
LL num;
char pi[20];
string node;
char tmp;
int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }

            if(m.find(node)!=m.end())
                m[node]++;
            else
                m[node] = 1;
        }

        else if(s[0] == '-')
        {
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }
            m[node]--;
        }

        else
        {
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }
            for(int j = 0; j<=(cnt-1)/2; j++)
            {
                tmp = pi[j]; pi[j] = pi[cnt-1-j]; pi[j] = pi[cnt-1-j] = tmp;
            }
            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {

                if(m[node]==0) {it++; continue;}
                if(node==it->first)
                    sum += it->second;
                it++;
            }
            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<string,LL>m;
map<string,LL>::iterator it;
char s[50];
LL num;
char pi[20];
string node;

int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }

            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }

            if(m.find(node)!=m.end())
                m[node]++;
            else
                m[node] = 1;
        }

        else if(s[0] == '-')
        {
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }

            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }

            m[node]--;
        }

        else
        {
            int cnt = 0;
            for(int j = 0; j<18; j++) pi[j] = '0';
            for(int j = 2; s[j]; j++)
            {
                if((s[j]-'0')&1)
                pi[cnt++] = '1';
            }

            node = "";
            for(int j = 17; j>=0; j--)
            {
                node += pi[j];
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {

                if(m[node]==0) {it++; continue;}

               // cout<<it->first<<endl;
               if(node==it->first)
                    sum += it->second;

                it++;
            }

            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<LL,LL>m;
map<LL,LL>::iterator it;
char s[50];
LL num;
int pi[20];

int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }

            if(m.find(num)!=m.end())
                m[num]++;
            else
                m[num] = 1;
        }

        else if(s[0] == '-')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                num += (s[j]-'0');
            }
            m[num]--;
        }

        else
        {
            memset(pi,0,sizeof(pi));
            int j = strlen(s)-1, now = 18;
            for(;j>=2; j--)
            {
                pi[now--] = s[j]-'0';
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                int B = 1;
                num = it->first;
                if(!m[num]) {it++; continue;}
                for(int j = 18; j>now || num>0; j--)
                {
                    if((pi[j]+(num)%10)%2==1) {B = 0; break;}
                    num /= 10;
                }
                if(B)
                    sum += it->second;

                it++;
            }

            cout<<sum<<endl;
        }

    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<map>
#include<string>
#include<set>
#define LL long long
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define INF 0x7fffffff
#define LNF ((1LL<<62)-1)
#define mod 1000000007
#define maxn 250000

using namespace std;

map<LL,LL>m;
map<LL,LL>::iterator it;
char s[50];
LL num;
int pi[20];

int main()
{
    int t;
    cin>>t;
    m.clear();
    getchar();
    for(int i = 0; i<t; i++)
    {
        gets(s);
        if(s[0] == '+')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                if((s[j]-'0')&1)
                    num = num+1;
            }

            if(m.find(num)!=m.end())
                m[num]++;
            else
                m[num] = 1;
        }

        else if(s[0] == '-')
        {
            num = 0;
            for(int j = 2; s[j]; j++)
            {
                num *= 10;
                if((s[j]-'0')&1)
                    num = num+1;
            }
            m[num]--;
        }

        else
        {
            memset(pi,0,sizeof(pi));
            int j = strlen(s)-1, now = 18;
            for(;j>=2; j--)
            {
                pi[now--] = s[j]-'0';
            }

            LL sum = 0;
            it = m.begin();
            while(it!=m.end())
            {
                int B = 1;
                num = it->first;
                if(!m[num]) {it++; continue;}
                for(int j = 18; j>now || num>0; j--)
                {
                    if(pi[j]+(num%10)==1) {B = 0; break;}
                    num /= 10;
                }
                if(B)
                    sum += it->second;

                it++;
            }

            cout<<sum<<endl;
        }

    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<deque<char>,ll> mapp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        char o;
        string n;
        cin>>o>>n;
            deque<char> tem;
            tem.resize(n.size());
        for (int i=0;i<n.size();i++)
            tem[i]=((n[i]-'0')%2+'0');
        if (o=='+')
            mapp[tem]++;
        if (o=='-')
            mapp[tem]--;
        if (o=='?'){
            map<deque<char>,ll>::iterator it=mapp.begin();
            ll c=0;
            while(it!=mapp.end())
            {
                deque<char> temp=it->first;
                while(temp.size()!=tem.size())
                {
                    if (tem.size()<temp.size())
                        tem.push_front('0');
                    if (temp.size()<tem.size())
                        temp.push_front('0');
                }
                if (tem==temp)
                    c+=it->second;
                it++;
            }
           cout<<c<<"\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<deque<char>,ll> mapp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        char o;
        string n;
        cin>>o>>n;
        deque<char> tem;
        tem.resize(n.size());
        for (int i=0; i<n.size(); i++)
            tem[i]=((n[i]-'0')%2+'0');
            while(tem.size()<19)
                tem.push_front('0');
        if (o=='+')
            mapp[tem]++;
        if (o=='-')
            mapp[tem]--;
        if (o=='?')
        {
            map<deque<char>,ll>::iterator it=mapp.begin();
            ll c=0;
            while(it!=mapp.end())
            {
                if (it->first==tem)
                    c+=it->second;
             it++;
            }
            cout<<c<<"\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<deque<char>,ll> mapp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        char o;
        string n;
        cin>>o>>n;
        deque<char> tem;
        tem.resize(n.size());
        for (int i=0; i<n.size(); i++)
            tem[i]=((n[i]-'0')%2+'0');
        if (o=='+')
            mapp[tem]++;
        if (o=='-')
            mapp[tem]--;
        if (o=='?')
        {
            map<deque<char>,ll>::iterator it=mapp.begin();
            ll c=0;
            while(it!=mapp.end())
            {
                deque<char> temp=it->first;
                int s1=temp.size()-1,s2=tem.size()-1;
                bool flag=0;
                while(s1>=0||s2>=0)
                {
                    char x='0',y='0';
                    if (s1>=0)
                        x=temp[s1];
                    if (s2>=0)
                        y=tem[s2];
                    s1--;
                    s2--;
                    if (x!=y)
                    {
                        flag=1;
                        break;
                    }
                }
                if (!flag)
                    c+=it->second;
             it++;
            }
            cout<<c<<"\n";
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
map<deque<char>,int> mapp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        char o;
        string n;
        cin>>o>>n;
            deque<char> tem;
        for (int i=0;i<n.size();i++)
        {
            tem.push_back(n[i]);
        }
        if (o=='+')
            mapp[tem]++;
        if (o=='-')
            mapp[tem]--;
        if (o=='?'){
            map<deque<char>,int>::iterator it=mapp.begin();
            int c=0;
            while(it!=mapp.end())
            {
                deque<char> temp=it->first;
                for (int i=0;i<temp.size();i++)
                    temp[i]=((temp[i]-'0')%2+'0');
                while(temp.size()!=tem.size())
                {
                    if (tem.size()<temp.size())
                        tem.push_front('0');
                    if (temp.size()<tem.size())
                        temp.push_front('0');
                }
                if (tem==temp)
                    c+=it->second;
                it++;
            }
            cout<<c<<endl;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
map<deque<char>,ll> mapp;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        char o;
        string n;
        cin>>o>>n;
        deque<char> tem;
        tem.resize(n.size());
        for (int i=0; i<n.size(); i++)
            tem[i]=((n[i]-'0')%2+'0');
            while(tem.size()<19)
                tem.push_front('0');
        if (o=='+')
            mapp[tem]++;
        if (o=='-')
            mapp[tem]--;
        if (o=='?')
        {

            cout<<mapp[tem]<<"\n";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
map<long,long>m;
signed main(){
    long n;
    cin>>n;
    for(auto i=0;i<n;i++){
        string type,num,ss;
        cin>>type>>num;
        for(auto i=0;i<num.size();i++){
            long eo  = (num[i]-'0')%2;
            ss+=to_string(eo);
        }

        long z = stoull(ss,0,2);
        cout<<num<<" "<<z<<endl;

        if(type[0]=='+'){
            m[z]++;
        }else if(type[0]=='-'){
            m[z]--;
        }else
            cout<<m[z]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll,ll>m;
string type,num;
main(){
    ll n;
    cin>>n;

    for(auto i=0;i<n;i++){

        cin >> type >> num;
        string ss;

        for(auto i=0; i<num.size(); i++) {ll eo = (num[i]-'0')%2; ss += to_string(eo);}
        ll z = stoull(ss, 0, 2);

        if(type[0] == '?'){
            cout << m[z] << endl;
        }else if(type[0] == '+'){
            m[z] += 1;
        }else if(type[0] == '-')
            m[z]--;
    }
}


#include<bits/stdc++.h>
using namespace std;
map<long,long>m;
signed main(){
    long n;
    cin>>n;
    for(auto i=0;i<n;i++){
        string type,num,ss;
        cin>>type>>num;
        for(auto i=0;i<num.size();i++){
            long eo  = (num[i]-'0')%2;
            ss+=to_string(eo);
        }

        long z = stoull(ss,0,2);
        cout<<num<<" "<<z<<endl;

        if(type[0]=='+'){
            m[z]++;
        }else if(type[0]=='-'){
            m[z]--;
        }else
            cout<<m[zz]<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
map<long,long>m;
signed main(){
    long n;
    cin>>n;
    for(auto i=0;i<n;i++){
        string type,num,ss;
        cin>>type>>num;
        for(auto i=0;i<num.size();i++){
            long eo  = (num[i]-'0') % 2;
            ss+=to_string(eo);
        }

        long z = stoull(ss,0,2);
        cout<<num<<" "<<z<<endl;

        if(type[0]=='+'){
            m[z]++;
        }else if(type[0]=='-'){
            m[z]--;
        }else
            cout<<m[zz]<<endl;
    }
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
typedef long long lld;
const int L=20, N=1<<21;

struct trie
{
    int n, a[N][3];

    trie()
    {
        memset(this, 0, sizeof(trie));
    }

    void insert(lld x)
    {
        for(int p=0, i=0; i<L; i++)
        {
            int b=x&1;

            if( a[p][b]<=0 )
                a[p][b]=++n;

            p=a[p][b];
            a[p][2]++;
            x/=10;
        }
    }

    void erase(lld x)
    {
        for(int p=0, i=0; i<L; i++)
        {
            int b=x&1;
            p=a[p][b];
            a[p][2]--;
            x/=10;
        }
    }

    int query(const char* s) const
    {
        int p=0;

        for(int n=strlen(s), i=0; i<L; i++)
        {
            int b= i<n ? s[n-i-1]&1 : 0;
            p=a[p][b];
        }

        return a[p][2];
    }
} T;

int main()
{
    int n;

    for(scanf("%d", &n); n>0; n--)
    {
        char c, s[20]={0};
        scanf(" %c%s", &c, s);

        if( c=='+' )
            T.insert(atoll(s));
        else if( c=='-' )
            T.erase(atoll(s));
        else//if( c=='?' )
            printf("%d\n", T.query(s));
    }
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
typedef long long lld;
const int L=20, N=1<<21;

struct trie
{
    int n, a[N][3];

    trie()
    {
        memset(this, 0, sizeof(trie));
    }

    void insert(lld x)
    {
        for(int p=0, i=0; i<L; i++)
        {
            int b=x&1;

            if( a[p][b]<=0 )
                a[p][b]=++n;

            p=a[p][b];
            a[p][2]++;
            x/=10;
        }
    }

    void erase(lld x)
    {
        for(int p=0, i=0; i<L; i++)
        {
            int b=x&1;
            p=a[p][b];
            a[p][2]--;
            x/=10;
        }
    }

    int query(const char* s) const
    {
        int p=0;

        for(int i=strlen(s)-1; i>=0; i--)
        {
            int b=s[i]&1;
            p=a[p][b];
        }

        return a[p][2];
    }
} T;

int main()
{
    int n;

    for(scanf("%d", &n); n>0; n--)
    {
        char c, s[20]={0};
        scanf(" %c%s", &c, s);

        if( c=='+' )
            T.insert(atoll(s));
        else if( c=='-' )
            T.erase(atoll(s));
        else//if( c=='?' )
            printf("%d\n", T.query(s));
    }
}


#include<cstdio>
#include<map>
using namespace std;
typedef long long lld;

lld f(const char* s)
{
    lld ans=0;

    for(int i=0; s[i]!='\0'; i++)
        ans=(ans<<1)|(s[i]&1);

    return ans;
}

int main()
{
    int n;
    scanf("%d", &n);

    for(map<lld, int> M; n>0; n--)
    {
        char c, s[20]={0};
        scanf(" %c%s", &c, s);
        lld k=f(s);

        if( c=='+' )
            M[k]++;
        else if( c=='-' )
            M[k]--;
        else//if( c=='?' )
            printf("%d\n", M[k]);
    }
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
typedef long long lld;
const int N=1<<21;

struct trie
{
    int n, a[N][3];

    trie()
    {
        memset(this, 0, sizeof(trie));
    }

    void insert(lld x)
    {
        int p=0;

        do{
            int b=x&1;

            if( a[p][b]<=0 )
                a[p][b]=++n;

            p=a[p][b];
            a[p][2]++;
            x/=10;
        }while( x>0 );
    }

    void erase(lld x)
    {
        int p=0;

        do{
            int b=x&1;
            p=a[p][b];
            a[p][2]--;
            x/=10;
        }while( x>0 );
    }

    int query(const char* s) const
    {
        lld x=0;

        for(; *s!='\0'; s++)
            x=(x<<1)|(*s-'0');

        int p=0;

        do{
            int b=x&1;
            p=a[p][b];
            x>>=1;
        }while( x>0 );

        return a[p][2];
    }
} T;

int main()
{
    int n;

    for(scanf("%d", &n); n>0; n--)
    {
        char c, s[20]={0};
        scanf(" %c%s", &c, s);

        if( c=='+' )
            T.insert(atoll(s));
        else if( c=='-' )
            T.erase(atoll(s));
        else//if( c=='?' )
            printf("%d\n", T.query(s));
    }
}


/*------------------------------------\
*	Hariom Singh
*	SVNIT Surat
*
*------------------------------------*/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define fore(i,a,b) for(i=a;i<=b;i++)
#define forl(i,a,b) for(i=a;i<b;i++)
#define si(d) scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define ll long long
#define ull unsigned long long
int mod=1000*1000*1000+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	multiset<ll> ms;
	while ( t-- )
	{

	   char x ;
	   cin >> x ;
	   if ( x == '+')
	   {
	       ll y;
	       cin >> y ;
	       ms.insert(y);
	   }
	   else if ( x == '-')
	   {
	       ll y ;
	       cin >> y ;
	       multiset<ll> :: iterator it,it1;
	      // cout << *it <<" " <<*it1 << endl;
	       it = ms.lower_bound(y);
	       it1 = it;
	       it1 ++;
	       ms.erase(it);

	   }
	   else
	   {
	     ll s ;
	     cin >> s;
	     ll cnt = 0;
	     multiset<ll> :: iterator it , lb ,ub;
	     ll z = s;
	     int prev = 0;
	     for ( it = ms.begin() ; it != ms.end() ; it =ms. upper_bound(*it))
	     {
	        s = z;
	     ll p = *it;
	     int si = ms.count(p);
	      //int si = ub - it ;

	     int flag = 0;
	     while ( s != 0 || p != 0)
	     {
	         int sr = s%10;
	         int pr = p%2 ;
	         s /= 10;
	         p /= 10;

	         if ( sr != pr )
	         {
	             flag = 1;
	             prev = 0;
	             break;
	         }
	     }
	     if ( flag == 0)
	     cnt += si ;

	     }
	       cout << cnt << endl;
	   }
	}
	return 0;
}


/*------------------------------------\
*	Hariom Singh
*	SVNIT Surat
*
*------------------------------------*/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define fore(i,a,b) for(i=a;i<=b;i++)
#define forl(i,a,b) for(i=a;i<b;i++)
#define si(d) scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define ll long long
#define ull unsigned long long
int mod=1000*1000*1000+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	multiset<ll> ms;
	while ( t-- )
	{

	   char x ;
	   cin >> x ;
	   if ( x == '+')
	   {
	       ll y;
	       cin >> y ;
	       ms.insert(y);
	   }
	   else if ( x == '-')
	   {
	       ll y ;
	       cin >> y ;
	       multiset<ll> :: iterator it,it1;
	      // cout << *it <<" " <<*it1 << endl;
	       it = ms.find(y);
	       it1 = it;
	       it1 ++;
	       ms.erase(it,it1);

	   }
	   else
	   {
	     ll s ;
	     cin >> s;
	     ll cnt = 0;
	     multiset<ll> :: iterator it;
	     ll z = s;
	     for ( it = ms.begin() ; it != ms.end() ; it++)
	     {
	        s = z;
	     ll p = *it;
	     //cout << p << endl;
	     int flag = 0;
	     while ( s != 0 || p != 0)
	     {
	         int sr = s%10;
	         int pr = p%2 ;
	         s /= 10;
	         p /= 10;

	         if ( sr != pr )
	         {
	             flag = 1;
	             break;
	         }
	     }
	     if ( flag == 0)
	     cnt++;

	     }
	       cout << cnt << endl;
	   }
	}
	return 0;
}


/*------------------------------------\
*	Hariom Singh
*	SVNIT Surat
*
*------------------------------------*/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define fore(i,a,b) for(i=a;i<=b;i++)
#define forl(i,a,b) for(i=a;i<b;i++)
#define si(d) scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define ll long long
#define ull unsigned long long
int mod=1000*1000*1000+7;
 map < string , ll > m;
 void sol( ll x , int ty)
 {
     string temp="";
     for ( int i = 0 ;i<19;i++)
     {
         if ( (x%10)%2 == 0)
         temp = "0"+temp;
         else
         temp = "1"+temp;
         x /= 10;
     }
     if ( ty )
     m[temp] ++;
     else
     m[temp] --;

 }
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
//	multiset<ll> ms;
	while ( t-- )
	{

	   char x ;
	   cin >> x ;
	   if ( x == '+')
	   {
	       ll y ;
	       cin >> y ;
	       sol(y,1);
	   }
	   else if ( x == '-')
	   {
	       ll y ;
	       cin >> y;
	       sol(y,0);
	   }
	   else
	   {
	       string s;
	       cin >> s;
	       while ( s.length()<19)
	       s = "0"+s;
	       cout << m[s] << endl;
	   }
	}
	return 0;
}


/*------------------------------------\
*	Hariom Singh
*	SVNIT Surat
*
*------------------------------------*/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define fore(i,a,b) for(i=a;i<=b;i++)
#define forl(i,a,b) for(i=a;i<b;i++)
#define si(d) scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define ll long long
#define ull unsigned long long
int mod=1000*1000*1000+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	multiset<ll> ms;
	while ( t-- )
	{

	   char x ;
	   cin >> x ;
	   if ( x == '+')
	   {
	       ll y;
	       cin >> y ;
	       ms.insert(y);
	   }
	   else if ( x == '-')
	   {
	       ll y ;
	       cin >> y ;
	       multiset<ll> :: iterator it,it1;
	      // cout << *it <<" " <<*it1 << endl;
	       it = ms.find(y);
	       it1 = it;
	       it1 ++;
	       ms.erase(it,it1);

	   }
	   else
	   {
	     ll s ;
	     cin >> s;
	     ll cnt = 0;
	     multiset<ll> :: iterator it , lb ,ub;
	     ll z = s;
	     int prev = 0;
	     for ( it = ms.begin() ; it != ms.end() ; it =ms. upper_bound(*it))
	     {
	        s = z;
	     ll p = *it;
	     int si = ms.count(p);
	      //int si = ub - it ;

	     int flag = 0;
	     while ( s != 0 || p != 0)
	     {
	         int sr = s%10;
	         int pr = p%2 ;
	         s /= 10;
	         p /= 10;

	         if ( sr != pr )
	         {
	             flag = 1;
	             prev = 0;
	             break;
	         }
	     }
	     if ( flag == 0)
	     cnt += si ;

	     }
	       cout << cnt << endl;
	   }
	}
	return 0;
}


/*------------------------------------\
*	Hariom Singh
*	SVNIT Surat
*
*------------------------------------*/

#include<bits/stdc++.h>
using namespace std;

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define fore(i,a,b) for(i=a;i<=b;i++)
#define forl(i,a,b) for(i=a;i<b;i++)
#define si(d) scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define ll long long
#define ull unsigned long long
int mod=1000*1000*1000+7;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	multiset<ll> ms;
	while ( t-- )
	{

	   char x ;
	   cin >> x ;
	   if ( x == '+')
	   {
	       ll y;
	       cin >> y ;
	       ms.insert(y);
	   }
	   else if ( x == '-')
	   {
	       ll y ;
	       cin >> y ;
	       multiset<ll> :: iterator it,it1;
	      // cout << *it <<" " <<*it1 << endl;
	       it = ms.find(y);
	       it1 = it;
	       it1 ++;
	       ms.erase(it,it1);

	   }
	   else
	   {
	     ll s ;
	     cin >> s;
	     ll cnt = 0;
	     multiset<ll> :: iterator it;
	     ll z = s;
	     int prev = 0;
	     for ( it = ms.begin() ; it != ms.end() ; it++)
	     {
	        s = z;
	     ll p = *it;
	     ll q = *it;
	     if ( it != ms.begin())
	     q-- ;
	     //cout << p << endl;
	     if ( q == p && it != ms.begin() )
	     {
	         if ( prev == 1)
	         cnt ++;
	         continue;
	     }
	     int flag = 0;
	     while ( s != 0 || p != 0)
	     {
	         int sr = s%10;
	         int pr = p%2 ;
	         s /= 10;
	         p /= 10;

	         if ( sr != pr )
	         {
	             flag = 1;
	             prev = 0;
	             break;
	         }
	     }
	     if ( flag == 0)
	     cnt++ , prev = 1;

	     }
	       cout << cnt << endl;
	   }
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=10000000;
#define ll long long int
int n;
bool valid(int x,int y){
      if( x>=0 && x<=n-1 && y<=n-1 && y>=0)
        return true;
      return false;
}
ll cnt[N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    char ch;
     ll res=1;
    string str;
    cin>>ch>>str;
     reverse(str.begin(),str.end());
     while(str.size()<18)
      str+='0';
    if(ch=='+'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2 !=0 )
          res=res*2+1;
       // else
        //  res=res*2;
      }
      cnt[res]++;

    }
    else if(ch=='-'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2+1;
       // else
         // res=res*2;
      }
      cnt[res]--;

    }
    else{
      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2 +1;
      //  else
        //  res=res*2;
      }
      cout<<cnt[res]<<endl;
    }

  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=10000000;
#define ll long long int
int n;
bool valid(int x,int y){
      if( x>=0 && x<=n-1 && y<=n-1 && y>=0)
        return true;
      return false;
}
ll cnt[N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    char ch;
     ll res=1;
    string str;
    cin>>ch>>str;
     reverse(str.begin(),str.end());
     while(str.size()<18)
      str+='0';
    if(ch=='+'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2 !=0 )
          res=res*2;
        else
          res=res*2 +1;
      }
      cnt[res]++;

    }
    else if(ch=='-'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res*=2;
        else
          res=res*2 +1;
      }
      cnt[res]--;

    }
    else{
      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res*=2;
        else
          res=res*2+1;
      }
      cout<<cnt[res]<<endl;
    }

  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=10000000;
#define ll long long int
int n;
bool valid(int x,int y){
      if( x>=0 && x<=n-1 && y<=n-1 && y>=0)
        return true;
      return false;
}
ll cnt[N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    char ch;
     ll res=1;
    string str;
    cin>>ch>>str;
     //reverse(str.begin(),str.end());
     while(str.size()<18)
      str='0'+str;
    if(ch=='+'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2 !=0 )
          res=res*2+1;
       else
         res=res*2;
      }
      cnt[res]++;

    }
    else if(ch=='-'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2+1;
       else
         res=res*2;
      }
      cnt[res]--;

    }
    else{
      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2 +1;
       else
         res=res*2;
      }
      cout<<cnt[res]<<endl;
    }

  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=10000000;
#define ll long long int
int n;
bool valid(int x,int y){
      if( x>=0 && x<=n-1 && y<=n-1 && y>=0)
        return true;
      return false;
}
ll cnt[N];
int main()
{
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    char ch;
     ll res=1;
    string str;
    cin>>ch>>str;
     reverse(str.begin(),str.end());
     while(str.size()<18)
      str+='0';
    if(ch=='+'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2 !=0 )
          res=res*2+1;
       else
         res=res*2;
      }
      cnt[res]++;

    }
    else if(ch=='-'){

      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2+1;
       else
         res=res*2;
      }
      cnt[res]--;

    }
    else{
      for(int i=0;i<18;i++){
        if((str[i]-'0')%2!=0)
          res=res*2 +1;
       else
         res=res*2;
      }
      cout<<cnt[res]<<endl;
    }

  }
  return 0;
}