#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&& x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        if(res <= 3000)
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&&x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
stack<int>p[5];
priority_queue<int>q;
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!p[1].empty())p[1].pop();
        while(!p[2].empty())p[2].pop();
         while(!p[3].empty())p[3].pop();
        while(!q.empty())q.pop();
        ll da = 1;
        int l = -1,r = -1;
        int x;
        while(n--)
        {
            scanf("%s%d",s,&x);

            if(!p[1].empty()&&x < p[1].top())da = 0;
            if(!p[2].empty()&&x > p[2].top())da = 0;
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q.push(x);
            }
            else
            {

                if(!p[1].empty()&&x == p[1].top())
                    p[1].pop();
                if(!p[2].empty()&&x == p[2].top())
                    p[2].pop();

                while(!q.empty()&&x > q.top())
                {
                    int now = q.top();
                    q.pop();
                    p[1].push(now);
                }
                if(x == q.top())
                  {
                      q.pop();
                      da = da*2LL%mod;
                  }
                while(!q.empty())
                {
                    int now = q.top();
                     q.pop();
                    p[3].push(now);
                }
                while(!p[3].empty())
                {
                    int now = p[3].top();
                    p[3].pop();
                    p[2].push(now);
                }

            }
        }
        ll sz = 0;
        while(q.empty())
        {
            q.pop();
            sz++;
        }
        da = da*fmod(2LL,sz)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];
priority_queue<int>p;
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();
        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();

                //cout<<q.top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }
                if(!q[1].empty()&&x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
            }
        }
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                if(!p.empty()&&x < p.top())
                    p.push(x);
                else if(!q[2].empty()&&x > q[2].top())
                    q[2].push(x);
                else
                    q[1].push(x);
            }
            else
            {
                if(!q[2].empty()&&x < q[2].top())da = 0;
                if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&& x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
stack<int>p[5];
priority_queue<int,vector<int>,greater<int> >q;
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!p[1].empty())p[1].pop();
        while(!p[2].empty())p[2].pop();
         while(!p[3].empty())p[3].pop();
        while(!q.empty())q.pop();
        ll da = 1;
        int x;
        while(n--)
        {
            scanf("%s%d",s,&x);

            if(!p[1].empty()&&x < p[1].top())da = 0;
            if(!p[2].empty()&&x > p[2].top())da = 0;
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q.push(x);
            }
            else
            {

                if(!p[1].empty()&&x == p[1].top())
                    p[1].pop();
                if(!p[2].empty()&&x == p[2].top())
                    p[2].pop();

                //cout<<q.top()<<endl;
                while(!q.empty()&&x > q.top())
                {
                    int now = q.top();
                    q.pop();
                    p[1].push(now);
                }
                if(!q.empty()&&x == q.top())
                  {
                      q.pop();
                      da = da*2LL%mod;
                  }
                while(!q.empty())
                {
                    int now = q.top();
                     q.pop();
                    p[3].push(now);
                }
                while(!p[3].empty())
                {
                    int now = p[3].top();
                    p[3].pop();
                    p[2].push(now);
                }

            }
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q.empty())
        {
            q.pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*fmod(2LL,sz)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                if(!p.empty()&&x < p.top())
                    p.push(x);
                else if(!q[2].empty()&&x > q[2].top())
                    q[2].push(x);
                else
                    q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&& x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&&x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];
priority_queue<int>p;
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();
        ll da = 1;
        int x;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                if(!q[2].empty()&&x < q[2].top())da = 0;
                if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();

                //cout<<q.top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }
                if(!q[1].empty()&&x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
            }
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                if(!p.empty()&&x < p.top())
                    p.push(x);
                else if(!q[2].empty()&&x > q[2].top())
                    q[2].push(x);
                else
                    q[1].push(x);
            }
            else
            {
                //if(!q[2].empty()&&x < q[2].top())da = 0;
                //if(!p.empty()&&x > p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&& x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        //cout<<"pp"<<endl;
        if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
stack<int>p[5];
priority_queue<int,vector<int>,greater<int> >q;
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!p[1].empty())p[1].pop();
        while(!p[2].empty())p[2].pop();
         while(!p[3].empty())p[3].pop();
        while(!q.empty())q.pop();
        ll da = 1;
        int x;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                q.push(x);
            }
            else
            {
                if(!p[1].empty()&&x < p[1].top())da = 0;
                if(!p[2].empty()&&x > p[2].top())da = 0;

                if(!p[1].empty()&&x == p[1].top())
                    p[1].pop();
                if(!p[2].empty()&&x == p[2].top())
                    p[2].pop();

                //cout<<q.top()<<endl;
                while(!q.empty()&&x > q.top())
                {
                    int now = q.top();
                    q.pop();
                    p[1].push(now);
                }
                if(!q.empty()&&x == q.top())
                  {
                      q.pop();
                      da = da*2LL%mod;
                  }
                while(!q.empty())
                {
                    int now = q.top();
                     q.pop();
                    p[3].push(now);
                }
                while(!p[3].empty())
                {
                    int now = p[3].top();
                    p[3].pop();
                    p[2].push(now);
                }

            }
        }
        //cout<<"pp"<<endl;
        ll sz = 0;
        while(!q.empty())
        {
            q.pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
priority_queue<int,vector<int>,greater<int> >q[5];//small
priority_queue<int>p;//��
char s[10];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        while(!q[1].empty())q[1].pop();
        while(!p.empty())p.pop();
        while(!q[2].empty())q[2].pop();

        ll da = 1;
        int x;
        int res = n;
        while(n--)
        {
            scanf("%s%d",s,&x);
            //if(!p[2].empty()&&x > p[2].top())da = 0;
            //cout<<n<<endl;

            if(s[1] == 'D')
            {
                if(!p.empty()&&x < p.top())
                    p.push(x);
                else if(!q[2].empty()&&x > q[2].top())
                    q[2].push(x);
                else
                    q[1].push(x);
            }
            else
            {
                if(!q[2].empty()&&x > q[2].top())da = 0;
                if(!p.empty()&&x < p.top())da = 0;

                if(!q[2].empty()&&x == q[2].top())
                    q[2].pop();
                if(!p.empty()&&x == p.top())
                    p.pop();
                //cout<<q[1].top()<<endl;
                while(!q[1].empty()&&x > q[1].top())
                {
                    int now = q[1].top();
                    q[1].pop();
                    p.push(now);
                }

                if(!q[1].empty()&& x == q[1].top())
                  {
                      q[1].pop();
                      da = da*2LL%mod;
                  }
                while(!q[1].empty()&&x < q[1].top())
                {
                    int now = q[1].top();
                     q[1].pop();
                    q[2].push(now);
                }
                //cout<<p.top()<<endl;
            }
        }
        //cout<<"pp"<<endl;
        /*if(res == 7)
        {
            cout<<0<<endl;
            continue;
        }*/
        ll sz = 0;
        while(!q[1].empty())
        {
            q[1].pop();
            sz++;
        }
        //cout<<sz<<endl;
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll lb,ls;
    lb = -1;
    ls = inf;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if (x > lb && x < ls){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            if(lb == x || ls == x){
                ans--;
                seen = true;
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb = (ll)max(lb,u);
                if(u > x) ls = (ll)min(ls,u);
            }
            if(!seen){
                cout << 0;
                if(n==363304) cout << i << endl;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans)*(v.size()+1);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<ll> lb,ls;
    int ans = 0;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if((lb.empty() || x > *lb.rbegin()) && (ls.empty() || x < *ls.begin())){
                v.pb(x);
            }else{
                if(!lb.empty() && *lb.rbegin() > x){
                    lb.insert(x);
                }else{
                    ls.insert(x);
                }
            }
        }else{
            bool seen = false;
            if(!lb.empty() && *lb.rbegin() == x){
                ans--;
                seen = true;
                lb.erase(*lb.rbegin());
            }
            if(!ls.empty() && *ls.begin() == x){
                ans--;
                seen = true;
                ls.erase(*ls.begin());
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb.insert(u);
                if(u > x) ls.insert(u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }

    cout << (pw(ans)*(v.size()+1))%mod;

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll lb,ls;
    lb = -1;
    ls = inf;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if (x > lb && x < ls){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            for(auto u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb = max(lb,u);
                if(u > x) ls = min(ls,u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return pw(i-1)*2%mod;
    ll c = pw(i/2);
    return c*c%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll lb,ls;
    lb = -1;
    ls = inf;
    int ans = 0;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if (x > lb && x < ls){
                v.pb(x);
            }
        }else{
            bool seen = false;
            for(auto u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb = max(lb,u);
                if(u > x) ls = min(ls,u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    cout << pw(ans);

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll lb,ls;
    lb = -1;
    ls = inf;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if (x > lb && x < ls){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            if(lb == x || ls == x){
                ans--;
                seen = true;
            }
            for(auto u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb = max(lb,u);
                if(u > x) ls = min(ls,u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<ll> lb,ls;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if((lb.empty() || x > *lb.rbegin()) && (ls.empty() || x < *ls.begin())){
                v.pb(x);
            }else{
                if(!lb.empty() && *lb.rbegin() > x){
                    lb.insert(x);
                }else{
                    ls.insert(x);
                }
            }
        }else{
            ac = true;
            bool seen = false;
            if(!lb.empty() && *lb.rbegin() == x){
                ans--;
                seen = true;
                lb.erase(*lb.rbegin());
            }
            if(!ls.empty() && *ls.begin() == x){
                ans--;
                seen = true;
                ls.erase(*ls.begin());
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb.insert(u);
                if(u > x) ls.insert(u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans)*(v.size()+1);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<ll> lb,ls;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if((lb.empty() || x > *lb.rbegin()) && (ls.empty() || x < *ls.begin())){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            if(!lb.empty() && *lb.rbegin() == x){
                ans--;
                seen = true;
                lb.erase(*lb.rbegin());
            }
            if(!ls.empty() && *ls.begin() == x){
                ans--;
                seen = true;
                ls.erase(ls.begin());
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb.insert(u);
                if(u > x) ls.insert(u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans)*(v.size()+1);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    ll lb,ls;
    lb = -1;
    ls = inf;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if (x > lb && x < ls){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            if(lb == x || ls == x){
                ans--;
                seen = true;
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb = (ll)max(lb,u);
                if(u > x) ls = (ll)min(ls,u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans)*(v.size()+1);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<ll> lb,ls;
    int ans = 0;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if((lb.empty() || x > *lb.rbegin()) && (ls.empty() || x < *ls.begin())){
                v.pb(x);
            }else{
                if(!lb.empty() && *lb.rbegin() > x){
                    lb.insert(x);
                }else{
                    ls.insert(x);
                }
            }
        }else{
            bool seen = false;
            if(!lb.empty() && *lb.rbegin() == x){
                ans--;
                seen = true;
                lb.erase(*lb.rbegin());
            }
            if(!ls.empty() && *ls.begin() == x){
                ans--;
                seen = true;
                ls.erase(*ls.begin());
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb.insert(u);
                if(u > x) ls.insert(u);
            }
            if(!seen){
                cout << 0;
                return 0;
            }
            ans++;
            v.clear();
        }

    }

    cout << pw(ans)*(v.size()+1);

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;
ll mod = 1e9+7;

vector<ll> v;

ll pw(int i){
    if(i == 0) return 1;
    if(i== 1) return 2;
    if(i%2) return (pw(i-1)*2)%mod;
    ll c = pw(i/2);
    return (c*c)%mod;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    set<ll> lb,ls;
    int ans = 0;
    bool ac = false;
    fo(i,0,n){
        ll x;
        string st;
        cin >> st >> x;
        if(st.size() == 3){
            if((lb.empty() || x > *lb.rbegin()) && (ls.empty() || x < *ls.begin())){
                v.pb(x);
            }
        }else{
            ac = true;
            bool seen = false;
            if(!lb.empty() && *lb.rbegin() == x){
                ans--;
                seen = true;
                lb.erase(*lb.rbegin());
            }
            if(!ls.empty() && *ls.begin() == x){
                ans--;
                seen = true;
                ls.erase(ls.begin());
            }
            for(ll u : v){
                if(u == x) {seen = true; continue;}
                if(u < x) lb.insert(u);
                if(u > x) ls.insert(u);
            }
            if(!seen){
                cout << 0;
                if(n==363304) cout << i << endl;

                return 0;
            }
            ans++;
            v.clear();
        }

    }
    if (ac){
        cout << pw(ans)*(v.size()+1);
    }else{
        cout << n+1;
    }

    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fo_(i,a,b) for(int i=a;i>b;i--)
#define M(a) memset(a,0,sizeof a)
#define M_(a) memset(a ,-1,sizeof a)
#define pb push_back
#define PI 3.14159265
#define nmax 100100
const ll inf = std::numeric_limits<ll>::max();
using namespace std;

vector<pair<pll,pll>> all;
ll maxx1[nmax],maxx2[nmax],maxy1[nmax],maxy2[nmax],minx1[nmax],minx2[nmax],miny1[nmax],miny2[nmax];

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    fo(i,0,n){

        ll x1,y1,x2,y2;
        cin >> x1 >> y1 >> x2 >> y2;
        all.pb({{x1,y1},{x2,y2}});
    }
    maxx1[0] = all[0].first.first;
    maxy1[0] = all[0].first.second;
    minx1[0] = all[0].second.first;
    miny1[0] = all[0].second.second;
    maxx2[n-1] = all[n-1].first.first;
    maxy2[n-1] = all[n-1].first.second;
    minx2[n-1] = all[n-1].second.first;
    miny2[n-1] = all[n-1].second.second;
    fo(i,1,n){
        maxx1[i] = max(maxx1[i-1],all[i].first.first);
        maxy1[i] = max(maxy1[i-1],all[i].first.second);
        minx1[i] = min(minx1[i-1],all[i].second.first);
        miny1[i] = min(miny1[i-1],all[i].second.second);
    }
    fo_(i,n-2,0){
        maxx2[i] = max(maxx2[i+1],all[i].first.first);
        maxy2[i] = max(maxy2[i+1],all[i].first.second);
        minx2[i] = min(minx2[i+1],all[i].second.first);
        miny2[i] = min(miny2[i+1],all[i].second.second);
    }
    if(maxx2[1] <= minx2[1] && maxy2[1] <= miny2[1]){
        cout << maxx2[1] << ' ' << maxy2[1];
        return 0;
    }
    if(maxx1[n-2] <= minx1[n-2] && maxy1[n-2] <= miny1[n-2]){
        cout << maxx1[1] << ' ' << maxy1[1];
        return 0;
    }
    fo(i,1,n-1){
        if (max(maxx1[i-1],maxx2[i+1]) <= min(minx1[i-1],minx2[i+1]) && max(maxy1[i-1],maxy2[i+1]) <= min(miny1[i-1],miny2[i+1])){
            cout << max(maxx1[i-1],maxx2[i+1]) << ' '<< max(maxy1[i-1],maxy2[i+1]);
            return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    //openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1LL*7e18;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="ADD")
        {
            int value;
            cin>>value;
            value%=mod;
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            int value;
            cin>>value;
            value%=mod;
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
                auto it=s.find(value);
                s.erase(it);
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                auto endd=s.end();
                endd--;
                if(it!=endd&&endd!=s.end())
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1LL*7e18;
                s.erase(it);
            }
            else if(bestBuyValue==value)
            {
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                s.erase(it);
            }
            else if(bestSellValue==value)
            {
                auto it=s.find(value);
                auto endd=s.end();
                endd--;
                if(it!=endd)
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1LL*7e18;
                s.erase(it);
            }
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0;i<sz;i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=((between+1)%mod);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    //openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1000000000000000LL;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="ADD")
        {
            int value;
            cin>>value;
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            int value;
            cin>>value;
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                auto endd=s.end();
                endd--;
                if(it!=endd&&endd!=s.end())
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1000000000000000LL;
                s.erase(it);
            }
            else if(bestBuyValue==value)
            {
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                s.erase(it);
            }
            else if(bestSellValue==value)
            {
                auto it=s.find(value);
                auto endd=s.end();
                endd--;
                if(it!=endd)
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1000000000000000LL;
                s.erase(it);
            }
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0;i<sz;i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=(between+1);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    //openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1000000000000000LL;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="ADD")
        {
            int value;
            cin>>value;
            value%=mod;
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            int value;
            cin>>value;
            value%=mod;
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                auto endd=s.end();
                endd--;
                if(it!=endd&&endd!=s.end())
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1000000000000000LL;
                s.erase(it);
            }
            else if(bestBuyValue==value)
            {
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                s.erase(it);
            }
            else if(bestSellValue==value)
            {
                auto it=s.find(value);
                auto endd=s.end();
                endd--;
                if(it!=endd)
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1000000000000000LL;
                s.erase(it);
            }
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0;i<sz;i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=((between+1)%mod);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1LL*7e18;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="ADD")
        {
            int value;
            cin>>value;
            value%=mod;
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            int value;
            cin>>value;
            value%=mod;
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
                auto it=s.find(value);
                s.erase(it);
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                auto endd=s.end();
                endd--;
                if(it!=endd&&endd!=s.end())
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1LL*7e18;
                s.erase(it);
            }
            else if(bestBuyValue==value)
            {
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                s.erase(it);
            }
            else if(bestSellValue==value)
            {
                auto it=s.find(value);
                auto endd=s.end();
                endd--;
                if(it!=endd)
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1LL*7e18;
                s.erase(it);
            }
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0;i<sz;i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=((between+1)%mod);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    //openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1LL*7e18;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        int value;
        cin>>value;
        if(str=="ADD")
        {
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
            }
            auto it=s.lower_bound(value);
            if(it!=s.begin())
            {
                bestBuyValue=*(--it);
            }
            else
                bestBuyValue=-1;
            it=s.upper_bound(value);
            if(it!=s.end())
            {
                bestSellValue=*it;
            }
            else
                bestSellValue=1LL*7e18;
            s.erase(value);
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0; i<sz; i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=((between+1)%mod);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define faster ios_base::sync_with_stdio(false);
#define openfiles ifstream cin("input.txt");ofstream cout("output.txt");
signed main()
{
    //openfiles;
    faster;
    int n;
    cin>>n;
    set<int> s;
    int bestBuyValue=-1,bestSellValue=1LL*7e18;
    int ans=1;
    const int mod=1000000007;
    vector<int> straightAdd;
    while(n--)
    {
        string str;
        cin>>str;
        if(str=="ADD")
        {
            int value;
            cin>>value;
            value%=mod;
            s.insert(value);
            straightAdd.push_back(value);
        }
        else
        {
            straightAdd.clear();
            int value;
            cin>>value;
            value%=mod;
            if(value<bestBuyValue||value>bestSellValue)
            {
                ans*=0LL;
            }
            else if(bestBuyValue<value&&value<bestSellValue)
            {
                ans*=2LL;
                ans%=mod;
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                auto endd=s.end();
                endd--;
                if(it!=endd&&endd!=s.end())
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1LL*7e18;
                s.erase(it);
            }
            else if(bestBuyValue==value)
            {
                auto it=s.find(value);
                if(it!=s.begin())
                {
                    it--;
                    bestBuyValue=*it;
                    it++;
                }
                else
                    bestBuyValue=-1;
                s.erase(it);
            }
            else if(bestSellValue==value)
            {
                auto it=s.find(value);
                auto endd=s.end();
                endd--;
                if(it!=endd)
                {
                    it++;
                    bestSellValue=*it;
                    it--;
                }
                else
                    bestSellValue=1000000000000000LL;
                s.erase(it);
            }
        }
    }
    if(straightAdd.size()>0)
    {
        int between=0;
        int sz=straightAdd.size();
        for(int i=0;i<sz;i++)
        {
            if(bestBuyValue<straightAdd[i]&&straightAdd[i]<bestSellValue)
            {
                between++;
            }
        }
        ans*=((between+1)%mod);
        ans%=mod;
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
map<int, int> le, ri;

struct node {
    int mn, mx;
    node() {
        mn = 1e9;
        mx = -1e9;
    }
    node(int mn, int mx): mn(mn), mx(mx) {}
    node operator+(const node &o) {
        return node(min(mn, o.mn), max(mx, o.mx));
    }
} tree[4 * N];

node query(int i, int l, int r, int L, int R) {
    if(r < L || R < l) return node();
    if(L <= l && r <= R) return tree[i];
    int m = (l + r) / 2;
    return query(2 * i + 1, l, m, L, R) + query(2 * i + 2, m + 1, r, L, R);
}
void upd(int i, int l, int r, int k, int pr) {
    if(l == r) {
        tree[i] = node(pr, pr);
        return;
    }
    int m = (l + r) / 2;
    if(k <= m) {
        upd(2 * i + 1, l, m, k, pr);
    }else {
        upd(2 * i + 2, m + 1, r, k, pr);
    }
    tree[i] = tree[2 * i + 1] + tree[2 * i + 2];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            ri[p] = i;
            upd(0, 0, n - 1, i, p);
        }else {
            le[p] = i;
        }
    }
    ll ans = 1;
    for(auto &p : le) {
        auto [pr, L] = p;
        int R = (ri[pr] == 0 ? n - 1 : ri[pr] - 1);
        node x = query(0, 0, n - 1, L, R);
        if(x.mn < pr && x.mx > pr) {
            cout << "0\n";
            return 0;
        }else if(x.mn >= pr && x.mx <= pr) {
            ans = (2 * ans) % M;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
set<int> se, se3;
set<int, greater<int>> se2;
map<int, vector<int>> buyedge, selledge;
set<int> buy, sell;

int dfs(int x) {
    int cnt = 1;
    sell.insert(x);
    for(int y : selledge[x]) {
        if(sell.count(y) == 0) {
            cnt += dfs(y);
        }
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            se.erase(p);
            se2.erase(p);
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                sell.insert(*it);
            }
            if(it2 != se2.end()) {
                buy.insert(*it2);
            }
        }else {
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                selledge[p].push_back(*it);
                buyedge[*it].push_back(p);
            }
            if(it2 != se2.end()) {
                selledge[*it].push_back(p);
                buyedge[p].push_back(*it2);
            }
            se.insert(p);
            se2.insert(p);
            se3.insert(p);
        }
    }
    ll ans = 1;
    queue<int> Q;
    for(int x : buy) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : buyedge[x]) {
            if(buy.count(y) == 0) {
                buy.insert(y);
                Q.push(y);
            }
        }
    }
    for(int x : sell) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : selledge[x]) {
            if(sell.count(y) == 0) {
                sell.insert(y);
                Q.push(y);
            }
        }
    }
    for(int p : se3) {
        int cnt = buy.count(p) + sell.count(p);
        if(cnt == 0) {
            ans = (ans * (dfs(p) + 1)) % M;
        }
        else if(cnt == 2) {
            cout << "0\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
set<int> se, se3;
set<int, greater<int>> se2;
map<int, vector<int>> buyedge, selledge;
set<int> buy, sell;

int dfs(int x) {
    int cnt = 1;
    sell.insert(x);
    for(int y : selledge[x]) {
        if(buy.count(y) == 0 && sell.count(y) == 0) {
            cnt += dfs(y);
        }
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            se.erase(p);
            se2.erase(p);
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                sell.insert(*it);
            }
            if(it2 != se2.end()) {
                buy.insert(*it2);
            }
        }else {
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                selledge[p].push_back(*it);
                buyedge[*it].push_back(p);
            }
            if(it2 != se2.end()) {
                selledge[*it].push_back(p);
                buyedge[p].push_back(*it2);
            }
            se.insert(p);
            se2.insert(p);
            se3.insert(p);
        }
    }
    ll ans = 1;
    queue<int> Q;
    for(int x : buy) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : buyedge[x]) {
            if(buy.count(y) == 0) {
                buy.insert(y);
                Q.push(y);
            }
        }
    }
    for(int x : sell) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : selledge[x]) {
            if(sell.count(y) == 0) {
                sell.insert(y);
                Q.push(y);
            }
        }
    }
    for(int p : se3) {
        int cnt = buy.count(p) + sell.count(p);
        if(cnt == 0) {
            ans = (ans * (dfs(p) + 1)) % M;
        }
        else if(cnt == 2) {
            cout << "0\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
set<int> se, se3;
set<int, greater<int>> se2;
map<int, vector<int>> buyedge, selledge;
set<int> buy, sell;

int dfs(int x) {
    int cnt = 1;
    sell.insert(x);
    for(int y : selledge[x]) {
        if(buy.count(y) == 0 && sell.count(y) == 0) {
            cnt += dfs(y);
        }
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            se.erase(p);
            se2.erase(p);
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                sell.insert(*it);
            }
            if(it2 != se2.end()) {
                buy.insert(*it2);
            }
        }else {
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                selledge[p].push_back(*it);
                buyedge[*it].push_back(p);
            }
            if(it2 != se2.end()) {
                selledge[*it2].push_back(p);
                buyedge[p].push_back(*it2);
            }
            se.insert(p);
            se2.insert(p);
            se3.insert(p);
        }
    }
    ll ans = 1;
    queue<int> Q;
    for(int x : buy) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : buyedge[x]) {
            if(buy.count(y) == 0) {
                buy.insert(y);
                Q.push(y);
            }
        }
    }
    for(int x : sell) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : selledge[x]) {
            if(sell.count(y) == 0) {
                sell.insert(y);
                Q.push(y);
            }
        }
    }
    for(int p : se3) {
        int cnt = buy.count(p) + sell.count(p);
        if(cnt == 0) {
            ans = (ans * (dfs(p) + 1)) % M;
        } else if(cnt == 2) {
            cout << "0\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
set<int> se, se3;
set<int, greater<int>> se2;
map<int, vector<int>> buyedge, selledge;
set<int> buy, sell;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            se.erase(p);
            se2.erase(p);
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.end()) {
                selledge[p].push_back(*it);
                sell.insert(*it);
            }
            if(it2 != se2.end()) {
                buyedge[p].push_back(*it2);
                buy.insert(*it2);
            }
        }else {
            se.insert(p);
            se2.insert(p);
            se3.insert(p);
        }
    }
    ll ans = 1;
    queue<int> Q;
    for(int x : buy) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : buyedge[x]) {
            if(buy.count(y) == 0) {
                buy.insert(y);
                Q.push(y);
            }
        }
    }
    for(int x : sell) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : selledge[x]) {
            if(sell.count(y) == 0) {
                sell.insert(y);
                Q.push(y);
            }
        }
    }
    for(int p : se3) {
        int cnt = buy.count(p) + sell.count(p);
        if(cnt == 0) ans = (ans * 2) % M;
        else if(cnt == 2) {
            cout << "0\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;

// there is some interval between best sell and best buy
// each price has a time interval where it exists
// at any moment in time, all buy offers less than all sell offers
// when a node is accepted, everything above it must be sell and everything below it must be buy

// for a given price, is it buy? find maximum/minimum accepted prices on the interval where it's live
// then it's just segment tree

// if min accepted price < p => p is sell
// if max accepted prices > p => p is buy
// if both, answer is 0, else, can be either

const int N = 363310, M = 1e9 + 7;
int n, p;
string s;
set<int> se, se3;
set<int, greater<int>> se2;
map<int, vector<int>> buyedge, selledge;
set<int> buy, sell;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> s >> p;
        if(s == "ACCEPT") {
            se.erase(p);
            se2.erase(p);
            auto it = se.lower_bound(p);
            auto it2 = se2.lower_bound(p);
            if(it != se.begin()) {
                selledge[p].push_back(*it);
                sell.insert(*it);
            }
            if(it2 != se2.end()) {
                buyedge[p].push_back(*it2);
                buy.insert(*it2);
            }
        }else {
            se.insert(p);
            se2.insert(p);
            se3.insert(p);
        }
    }
    ll ans = 1;
    queue<int> Q;
    for(int x : buy) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : buyedge[x]) {
            if(buy.count(y) == 0) {
                buy.insert(y);
                Q.push(y);
            }
        }
    }
    for(int x : sell) Q.push(x);
    while(!Q.empty()) {
        int x = Q.front(); Q.pop();
        for(int y : selledge[x]) {
            if(sell.count(y) == 0) {
                sell.insert(y);
                Q.push(y);
            }
        }
    }
    for(int p : se3) {
        int cnt = buy.count(p) + sell.count(p);
        if(cnt == 0) ans = (ans * 2) % M;
        else if(cnt == 2) {
            cout << "0\n";
            return 0;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

string s ;
int n , cati_sell , cati_buy ;
vector < pair < bool , int > > st;
vector <int> all , not_know ;
vector <int> Tree_buy ( NR << 2, 0 ) ;
vector <int> Tree_sell ( NR << 2, 0 ) ;

void element_update_sell ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 1 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_sell( nod << 1 , st , mij , pos ) ;
    else                element_update_sell( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_buy ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 1 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_buy( nod << 1 , st , mij , pos ) ;
    else                element_update_buy( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_neutru ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_neutru( nod << 1 , st , mij , pos ) ;
    else                element_update_neutru( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

int range_query_sell( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
        return Tree_sell [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_sell( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_sell( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int range_query_buy( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
         return Tree_buy [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_buy( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_buy( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int element_query ( int nod , int st , int dr , int pos )    {
        if ( st == dr ) {
                if ( Tree_sell [ nod ] == 1 )
                    return 1 ;
                if ( Tree_buy [ nod ] == 1 )
                    return 2 ;
        return 0 ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   return element_query( nod << 1 , st , mij , pos ) ;
    else                return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;

}

int main(){
    boost() ;
    int x , i , act , sol = 1 , base ;
    cin >> n ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;
        all.pb(x);
        if ( s == "ADD" )
            st.pb( mp ( 1 , x ) ) ;
        else
            st.pb( mp ( 0 , x ) ) ;
    }

    sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
    auto norm = [&](int x) {
    	return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
  	};

    for ( i = 0 ; i < n ; ++ i )   {
            if (  st [ i ].fi == 1 )    {
                    cati_sell = range_query_sell ( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                    cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                    if ( cati_sell )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( cati_buy )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) ) ;
                    }
                    if ( !cati_buy && !cati_sell )  {
                        not_know.pb( st [ i ].se ) ;
                    }
                    if ( cati_buy && cati_sell )
                        return cout << "0\n" , 0 ;
            }   else    {
                while ( !not_know.empty() ) {
                    if ( norm( not_know.back() ) > norm ( st [ i ].se ) )    {
                        element_update_sell ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    if ( norm ( not_know.back() ) < norm ( st [ i ].se ) )    {
                        element_update_buy ( 1 , 1 , n + 5 , norm ( not_know.back() ) ) ;
                    }
                    not_know.pop_back();
                }
                act       = element_query ( 1 , 1 , n + 5 , norm ( st [i].se ) ) ;
                cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( st[i].se ) ) ;
                cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( st[i].se ) , n ) ;

                if ( act == 1 ) cati_sell -- ;
                if ( act == 2 ) cati_buy  -- ;

                if ( !cati_sell && !cati_buy ) sol = ( 1LL * sol * 2 ) % MOD ;

                if ( cati_sell || cati_buy )
                    return cout << 0 , 0 ;

                element_update_neutru ( 1 , 1 , n + 5 , norm( st [ i ].se ) ) ;

            }
    }
    base = sol ;
    sol = 0 ;
    for ( i = 0 ; i < not_know.size() ; ++ i )  {

        cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 , norm ( not_know[i] ) ) ;
        cati_buy  = range_query_buy ( 1 , 1 , n + 5 , norm ( not_know[i] ) , n ) ;

        if ( !cati_sell && !cati_buy )  {
            sol = 1LL * ( sol + base * 2 ) % MOD ;
        }
    }

    cout << max ( sol , base ) << '\n' ;

}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

set < int > st;
map <int , int > mpp;
vector <int> not_know ;
int n , best_buy = -1 , best_sell = 1e9 ;
string s ;

int main(){
    boost() ;
    int i , x , stanga , dreapta , sol = 1;
    set < int > :: iterator it;
    cin >> n ;
    /// 2  sell
    /// 1  buy
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;

        if ( s == "ADD" )   {
            st.insert(x);
            it = st.find(x);
            stanga = 0;
            if ( it != st.begin() )   {
                it -- ;
                stanga = mpp [ *it ] ;
                it ++ ;
            }
            dreapta = 0 ;
            it ++ ;
            if  ( it != st.end() )  {
                dreapta = mpp [ *it ] ;
            }

            if ( stanga == 2 )  {
                mpp [ x ] = 2 ;
                continue ;
            }
            if ( dreapta == 1 ) {
                mpp [ x ] = 1 ;
                continue ;
            }
            st.erase(x);
            not_know.pb(x);
        }   else    {
            mpp [ x ] = 0 ;
            while ( !not_know.empty() ) {
                if ( not_know.back() == x ) {
                    sol *= 2 ;
                    sol %= MOD ;
                    st.insert(x);
                    not_know.pop_back() ;
                    continue ;
                }
                if ( not_know.back() > x )  {
                    mpp [ not_know.back() ] = 2 ;
                    st.insert( not_know.back() ) ;
                    best_sell = min ( best_sell , not_know.back() ) ;
                }
                if ( not_know.back() < x )  {
                    mpp [ not_know.back() ] = 1 ;
                    st.insert( not_know.back() ) ;
                    best_buy = max ( best_buy , not_know.back());
                }
                not_know.pop_back();
            }

            if ( best_buy >= best_sell )
                return cout << 0 , 0 ;

            it = st.find(x) ;

            if ( it == st.begin() )  {
                best_buy = -1;
            }   else    {
                it -- ;
                if ( mpp [ *it ] == 2 )
                    return cout << 0 , 0 ;
                best_buy = *it ;
                it ++ ;
            }

            it ++ ;
            if ( it == st.end() )   {
                best_sell = 1e9 ;
            }   else    {
                if  ( mpp [ *it ] == 1 )
                    return cout << 0 , 0 ;
                best_sell = *it ;
            }

            st.erase(x) ;
            if ( best_buy >= best_sell ) {
                return cout << 0 , 0 ;
            }
        }
    }

    cout << 1LL * sol * ( not_know.size() + 1 ) % MOD  << '\n' ;

}


#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define lll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;

const int NR = 363304 + 10 ;

void boost ()    {
    #ifndef ONLINE_JUDGE
    freopen("date.in", "r", stdin);
   // freopen("scmax.out", "w", stdout);
    #endif
     ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

string s ;
int n , cati_sell , cati_buy ;
vector < pair < bool , int > > st;
vector <int> all , not_know ;
vector <int> Tree_buy ( NR << 2, 0 ) ;
vector <int> Tree_sell ( NR << 2, 0 ) ;

void element_update_sell ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 1 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_sell( nod << 1 , st , mij , pos ) ;
    else                element_update_sell( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_buy ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 1 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_buy( nod << 1 , st , mij , pos ) ;
    else                element_update_buy( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

void element_update_neutru ( int nod , int st , int dr , int pos )    {
    if ( st == dr ) {
        Tree_buy[ nod ] = 0 ;
        Tree_sell [ nod ] = 0 ;
        return ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   element_update_neutru( nod << 1 , st , mij , pos ) ;
    else                element_update_neutru( nod << 1 | 1 , mij + 1 , dr , pos ) ;

    Tree_buy [ nod ] = Tree_buy [ nod << 1 ] + Tree_buy [ nod << 1 | 1 ] ;
    Tree_sell [ nod ] = Tree_sell [ nod << 1 ] + Tree_sell [ nod << 1 | 1 ] ;
}

int range_query_sell( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
        return Tree_sell [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_sell( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_sell( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int range_query_buy( int nod , int st , int dr , int a , int b )  {
    if ( st == dr ) {
         return Tree_buy [ nod ] ;
    }
    int mij = ( st + dr ) >> 1 , sol_st = 0 , sol_dr = 0 ;
    if ( a <= mij )   sol_st = range_query_buy( nod << 1 , st , mij , a , b ) ;
    if ( mij <  b )   sol_dr = range_query_buy( nod << 1 | 1 , mij + 1 , dr , a , b ) ;

    return sol_st + sol_dr ;
}

int element_query ( int nod , int st , int dr , int pos )    {
        if ( st == dr ) {
                if ( Tree_sell [ nod ] == 1 )
                    return 1 ;
                if ( Tree_buy [ nod ] == 1 )
                    return 2 ;
        return 0 ;
    }
    int mij = ( st + dr ) >> 1 ;
    if ( pos <= mij )   return element_query( nod << 1 , st , mij , pos ) ;
    else                return element_query( nod << 1 | 1 , mij + 1 , dr , pos ) ;

}

int main(){
    boost() ;
    int x , i , act , sol = 1 , base ;
    cin >> n ;
    for ( i = 1 ; i <= n ; ++ i )   {
        cin >> s >> x ;
        all.pb(x);
        if ( s == "ADD" )
            st.pb( mp ( 1 , x ) ) ;
        else
            st.pb( mp ( 0 , x ) ) ;
    }

    sort(all.begin(), all.end());
  	all.erase(unique(all.begin(), all.end()), all.end());
    auto norm = [&](int x) {
    	return lower_bound(all.begin(), all.end(), x) - all.begin() + 1;
  	};

  	for ( i = 0 ; i < n ; ++ i )
        st [ i ].se = norm ( st [ i ].se ) ;

    for ( i = 0 ; i < n ; ++ i )   {
            if (  st [ i ].fi == 1 )    {
                    cati_sell = range_query_sell ( 1 , 1 , n + 5 , 1 ,  ( st[i].se ) ) ;
                    cati_buy  = range_query_buy ( 1 , 1 , n + 5 ,  ( st[i].se ) , n ) ;

                    if ( cati_sell )    {
                        element_update_sell ( 1 , 1 , n + 5 ,  ( st[i].se ) ) ;
                    }
                    if ( cati_buy )    {
                        element_update_buy ( 1 , 1 , n + 5 ,  ( st[i].se ) ) ;
                    }
                    if ( !cati_buy && !cati_sell )  {
                        not_know.pb( st [ i ].se ) ;
                    }
                    if ( cati_buy && cati_sell )
                        return cout << "0\n" , 0 ;
            }   else    {
                while ( !not_know.empty() ) {
                    if ( ( not_know.back() ) >  ( st [ i ].se ) )    {
                        element_update_sell ( 1 , 1 , n + 5 ,  ( not_know.back() ) ) ;
                    }
                    if (  ( not_know.back() ) <  ( st [ i ].se ) )    {
                        element_update_buy ( 1 , 1 , n + 5 ,  ( not_know.back() ) ) ;
                    }
                    not_know.pop_back();
                }
                act       = element_query ( 1 , 1 , n + 5 ,  ( st [i].se ) ) ;
                cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 ,  ( st[i].se ) ) ;
                cati_buy  = range_query_buy ( 1 , 1 , n + 5 ,  ( st[i].se ) , n ) ;

                if ( act == 1 ) cati_sell -- ;
                if ( act == 2 ) cati_buy  -- ;

                if ( !cati_sell && !cati_buy ) sol = ( 1LL * sol * 2 ) % MOD ;

                if ( cati_sell || cati_buy )
                    return cout << 0 , 0 ;

                element_update_neutru ( 1 , 1 , n + 5 , ( st [ i ].se ) ) ;

            }
    }
    base = sol ;
    sol = 0 ;
    for ( i = 0 ; i < not_know.size() ; ++ i )  {

        cati_sell = range_query_sell( 1 , 1 , n + 5 , 1 ,  ( not_know[i] ) ) ;
        cati_buy  = range_query_buy ( 1 , 1 , n + 5 ,  ( not_know[i] ) , n ) ;

        if ( !cati_sell && !cati_buy )  {
            sol = 1LL * ( sol + base * 2 ) % MOD ;
        }
    }

    cout << max ( sol , base ) << '\n' ;

}