#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<ll, ll>
#define pii pair<ll, pair<ll, ll> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<ll>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

ll lsone(ll n)
{
	return (n&-n);
}

void mult(ll a[matmax][matmax], ll b[matmax][matmax], ll c[matmax][matmax], ll m, ll n, ll p)
{
	for (ll i = 1; i <= m; i++)
	{
		for (ll j = 1; j <= p; j++)
		{
			c[i][j] = 0;
			for (ll k = 1; k <= n; k++)
			{
				c[i][j] += (a[i][k]*b[k][j])%mod;
				c[i][j] %= mod;
			}
		}
	}
}

void mat_pow(ll a[matmax][matmax], ll c[matmax][matmax], ll n, ll p)
{
	if (p == 0)
	{
		for (ll i = 1; i <= n; i++)
			c[i][i] = 1;
	}
	else if (p == 1)
	{
		for (ll i = 1; i <= n; i++)
		{
			for (ll j = 1; j <= n; j++)
				c[i][j] = a[i][j];
		}
	}
	else
	{
		ll d[matmax][matmax];
		mat_pow(a, d, n, p/2);
		if (p % 2)
		{
			ll e[matmax][matmax];
			mult(d, d, e, n, n, n);
			mult(e, a, c, n, n, n);
		}
		else
		{
			mult(d, d, c, n, n, n);
		}
	}
}

ll pow1(ll a, ll b)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2);
		x *= x;
		x %= mod;
		if (b%2)
		{
			x *= a;
			x %= mod;
		}
		return x;
	}
}

ll t;
map<string, ll> m1;
string s;

void init()
{
	for (ll i = 1989; i <= 9999; i++)
	{
		string s = "";
		ll temp = i;
		s += char(temp%10 + '0');
		while (m1.count(s))
		{
			temp /= 10;
			s = char(temp%10 + '0') + s;
		}
		m1[s] = i;
	}
}

ll solve(string inp)
{
	if (m1.count(inp))
		return m1[inp];

	ll ans = solve(inp.substr(1, inp.size()-1));
	ll num = 0;

	for (int i = 0; i < inp.size(); i++)
	{
		num *= 10;
		num += (inp[i]-'0');
	}

	while (num < ans)
	{
		num += pow(10, inp.size());
	}

	return num;
}

int main()
{
	fastio;
	init();
	cin>>t;
	while (t--)
	{
		cin>>s;
		string t = "";
		for (ll i = 4; i < s.size(); i++)
			t += s[i];
		cout<<solve(t)<<endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<ll, ll>
#define pii pair<ll, pair<ll, ll> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<ll>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

ll lsone(ll n)
{
	return (n&-n);
}

void mult(ll a[matmax][matmax], ll b[matmax][matmax], ll c[matmax][matmax], ll m, ll n, ll p)
{
	for (ll i = 1; i <= m; i++)
	{
		for (ll j = 1; j <= p; j++)
		{
			c[i][j] = 0;
			for (ll k = 1; k <= n; k++)
			{
				c[i][j] += (a[i][k]*b[k][j])%mod;
				c[i][j] %= mod;
			}
		}
	}
}

void mat_pow(ll a[matmax][matmax], ll c[matmax][matmax], ll n, ll p)
{
	if (p == 0)
	{
		for (ll i = 1; i <= n; i++)
			c[i][i] = 1;
	}
	else if (p == 1)
	{
		for (ll i = 1; i <= n; i++)
		{
			for (ll j = 1; j <= n; j++)
				c[i][j] = a[i][j];
		}
	}
	else
	{
		ll d[matmax][matmax];
		mat_pow(a, d, n, p/2);
		if (p % 2)
		{
			ll e[matmax][matmax];
			mult(d, d, e, n, n, n);
			mult(e, a, c, n, n, n);
		}
		else
		{
			mult(d, d, c, n, n, n);
		}
	}
}

ll pow1(ll a, ll b)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2);
		x *= x;
		x %= mod;
		if (b%2)
		{
			x *= a;
			x %= mod;
		}
		return x;
	}
}

ll t;
map<string, ll> m1;
string s;

void init()
{
	for (ll i = 1989; i <= 9999; i++)
	{
		string s = "";
		ll temp = i;
		s += char(temp%10 + '0');
		while (m1.count(s))
		{
			temp /= 10;
			s = char(temp%10 + '0') + s;
		}
		m1[s] = i;
	}
}

int main()
{
	fastio;
	init();
	cin>>t;
	while (t--)
	{
		cin>>s;
		string t = "";
		for (ll i = 4; i < s.size(); i++)
			t += s[i];
		if (m1.count(t))
		{
			cout<<m1[t]<<endl;
		}
		else
		{
			ll num = 0;
			for (ll i = 0; i < t.size(); i++)
			{
				num *= 10;
				num += (t[i]-'0');
			}

			if (num < 10000)
				num += pow(10, t.size());

			string t1 = "";
			ll flag = 0;
			for (ll i = t.size()-1; i >= 0; i--)
			{
				t1 = t[i] + t1;
				if (m1.count(t1) == 0 and flag)
					num += pow(10, t.size());
				else if (m1.count(t1) == 0)
					flag = 1;
			}
			cout<<num<<endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            bool flag=false;
            if((b<="3098" && b>="1000" && s[0]=='1') || (s[0]=='1' && s[1]=='0')) printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=4000;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
               // cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            if(s[0]=='0')
            {
                printf("1");
                cout<<s<<endl;
                continue;
            }
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            if(b<="3098" && b>="1000") printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            bool flag=false;
            for(int i=0;i<len-4;i++) if(s[i]=='0') flag=true;
            if((b<="3098" && b>="1000" && s[0]=='1') || flag) printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            if(s[0]=='0')
            {
                printf("1");
                cout<<s<<endl;
                continue;
            }
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            if(b<="3098" && b>="1000" && s[0]=='1') printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            bool flag=false;
            for(int i=0;i<len;i++)
            {
                if(s[i]=='0')
                {
                    flag=true;
                    break;
                }
                else if(s[i]=='1') continue;
                else break;
            }
            if((b<="3098" && b>="1000" && s[0]=='1') || flag || (s[0]=='0')) printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#pragma warning(disable:4996)
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

#define INF 0x333f3f3f
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))

const ll mod = 1e9 + 7;
const int maxn = 3e2 + 5;
const double PI = acos(-1.0);

int n;
string x;

void solve()
{
    sa(n);
    repp(i, 1, n)
    {
        cin >> x;
        x = x.substr(4);
        if (x.length() == 1)
        {
            if (x[0] >= '0'&&x[0] <= '8')
            {
                cout << "199" + x << endl;
            }
            else
            {
                cout << "1989" << endl;
            }
        }
        else if (x.length() == 2)
        {
            if (x == "99")
            {
                cout << "1999" << endl;
            }
            else
            {
                cout << "20" + x << endl;
            }
        }
        else if (x.length() == 3)
        {
            if (x >= "000"&&x <= "098")
            {
                cout << "3" + x << endl;
            }
            else
            {
                cout << "2" + x << endl;
            }
        }
        else if (x.length() == 4)
        {
            if (x >= "3099"&&x <= "9999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
        else if (x.length() == 5)
        {
            if (x >= "13099"&&x <= "99999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
        else if (x.length() == 6)
        {
            if (x >= "113099"&&x <= "999999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
        else if (x.length() == 7)
        {
            if (x >= "1113099"&&x <= "9999999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
        else if (x.length() == 8)
        {
            if (x >= "11113099"&&x <= "99999999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
        else if (x.length() == 9)
        {
            if (x >= "111113099"&&x <= "999999999")
            {
                cout << x << endl;
            }
            else
            {
                cout << "1" + x << endl;
            }
        }
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("o.txt", "w", stdout);
#endif
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
               // cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            if(s[0]=='0')
            {
                printf("1");
                cout<<s<<endl;
                continue;
            }
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            if(b<="3098" && b>="1000") printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=4000;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<="3098")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            if(s[0]=='0')
            {
                printf("1");
                cout<<s<<endl;
                continue;
            }
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            if(b<="3098" && b>="1000" && s[0]=='1') printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string s;
int m;
int work(int len)
{
    int ans=0;
    for(int i=0;i<len;i++) ans*=10,ans+=s[i]-'0';
    return ans;
}
map<string,bool> mmp;
map<string,string> mp;
int main()
{
    scanf("%d",&m);
    for(int i=1989;i<=9999;i++)
    {
        string a; a.resize(4);
        int cur=i,cnt=3;
        while(cur)
        {
           a[cnt--]='0'+(cur%10);
           cur/=10;
        }
        for(int j=3;j>=0;j--)
        {
            string b=a.substr(j,4);
            if(!mmp[b])
            {
                mmp[b]=true;
                mp[b]=a;
                //printf("%d**\n",i);
                //cout<<b<<endl;
                break;
            }
        }
    }
    while(m--)
    {
        cin>>s;
        int len=s.size();
        s=s.substr(4,len);
        len=s.size();
        int cur=work(len);
        if(len<=4)
        {
            if(len==4 && s<"3000")
            {
                printf("1");
                cout<<s<<endl;
            }
            else cout<<mp[s]<<endl;
        }
        else
        {
            if(s[0]=='0')
            {
                printf("1");
                cout<<s<<endl;
                continue;
            }
            string b=s.substr(len-4,len);
            //cout<<b<<endl;
            if(b<"3000" && b>="1000") printf("1");
            cout<<s<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int Mod = 1000000000+7;
const int oo = 0x3f3f3f3f;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long LL;
typedef priority_queue<int> QQ;
typedef priority_queue<int,vector<int>,greater<int>> QQQ;
#define lbit(a) (a&-a)
#define SZ(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#ifdef CF
	#define FOPEN freopen("in.txt","r",stdin)
	#define BUG(x) cout<<x<<"_"<<endl;
#else
	#define FOPEN ;
	#define BUG(x) ;
#endif

const int N = 363304 + 5;

QQ L;
QQQ R;
int n;
LL res=1,t;
string s;
int l=0,r=oo;
map<int,bool> mp;
int main(){
	cin>>n;
	queue<int> Q;
	for(int i=0;i<n;i++){
		cin>>s>>t;
		if(s=="ADD"){
			if(t>l&&t<r){
				Q.push(t);
				mp[t]=1;
			}else if(t<=l){
				L.push(t);
			}else{
				R.push(t);
			}
		}else{
			if(mp[t]){
				res=res*2%Mod;
				while(!Q.empty()){
					mp[Q.front()]=0;
					if(Q.front()<t)L.push(Q.front());
					else if(Q.front()>t) R.push(Q.front());
					Q.pop();
				}
				if(!R.empty())r=R.top();
				else r=oo;
				if(!L.empty())l=L.top();
				else l=0;
			}else{
				bool fid=0;
				if(!R.empty()&&t==R.top()){
					fid=1;
					R.pop();
					if(R.empty())r=oo;
					else r=R.top();
				}
				if(!L.empty()&&t==L.top()){
					fid=1;
					L.pop();
					if(L.empty())l=0;
					else l=L.top();
				}
				if(fid==0){
					return printf("0\n"),0;
				}
			}
		}
	}
	res=res*(SZ(Q)+1)%Mod;
	cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int Mod = 1000000000+7;
const int oo = 0x3f3f3f3f;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long LL;
typedef priority_queue<int> QMax;
typedef priority_queue<int,vector<int>,greater<int>> QMin;
#define lbit(a) (a&-a)
#define SZ(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#ifdef CF
	#define FOPEN freopen("in.txt","r",stdin)
	#define BUG(x) cout<<x<<"_"<<endl;
#else
	#define FOPEN ;
	#define BUG(x) ;
#endif

const int N = 363304 + 5;

QMax L;
QMin R;
int n,t;
LL res=1;
string s;
int main(){
	cin>>n;
	queue<int> Q;
	L.push(0);
	R.push(oo);
	for(int i=0;i<n;i++){
		cin>>s>>t;
		if(s=="ADD"){
			if(t<=L.top()){
				L.push(t);
			}else if(t>=R.top()){
				R.push(t);
			}else{
				Q.push(t);
			}
		}else{
			if(L.top()>=t){
				if(L.top()==t)L.pop();
				else res=0;
			}
			else if(R.top()<=t){
				if(R.top()==t)R.pop();
				else res=0;
			}
			else{
				res=res*2%Mod;
				while(!Q.empty()){
					if(Q.front()<t)L.push(Q.front());
					else if(Q.front()>t) R.push(Q.front());
					Q.pop();
				}

			}
		}
	}
	res=res*(SZ(Q)+1)%Mod;
	cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int Mod = 1000000000+7;
const int oo = 0x3f3f3f3f;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long LL;
typedef priority_queue<int> QMax;
typedef priority_queue<int,vector<int>,greater<int>> QMin;
#define lbit(a) (a&-a)
#define SZ(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#ifdef CF
	#define FOPEN freopen("in.txt","r",stdin)
	#define BUG(x) cout<<x<<"_"<<endl;
#else
	#define FOPEN ;
	#define BUG(x) ;
#endif

const int N = 363304 + 5;

QMax L;
QMin R;
int n,t;
LL res=1;
string s;
int main(){
	cin>>n;
	queue<int> Q;
	L.push(0);
	R.push(oo);
	for(int i=0;i<n;i++){
		cin>>s>>t;
		if(s=="ADD"){
			if(t<=L.top()){
				L.push(t);
			}else if(t>=R.top()){
				R.push(t);
			}else{
				Q.push(t);
			}
		}else{
			if(L.top()==t)L.pop();
			else if(R.top()==t)R.pop();
			else{
				LL p=0;
				while(!Q.empty()){
					if(Q.front()<t)L.push(Q.front());
					else if(Q.front()>t) R.push(Q.front());
					else p=2;
					Q.pop();
				}
				res=res*p%Mod;
			}
		}
	}
	res=res*(SZ(Q)+1)%Mod;
	cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int Mod = 1000000000+7;
const int oo = 0x3f3f3f3f;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long LL;
typedef priority_queue<int> QMax;
typedef priority_queue<int,vector<int>,greater<int>> QMin;
#define lbit(a) (a&-a)
#define SZ(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#ifdef CF
	#define FOPEN freopen("in.txt","r",stdin)
	#define BUG(x) cout<<x<<"_"<<endl;
#else
	#define FOPEN ;
	#define BUG(x) ;
#endif

const int N = 363304 + 5;

QMax L;
QMin R;
int n,t;
LL res=1;
string s;
int main(){
	cin>>n;
	vi Q;
	L.push(-2020202020);
	R.push(2020202020);
	for(int i=0;i<n;i++){
		cin>>s>>t;
		if(s=="ADD"){
			if(t<=L.top()){
				L.push(t);
			}else if(t>=R.top()){
				R.push(t);
			}else{
				Q.pb(t);
			}
		}else{
			if(L.top()>=t){
				if(L.top()==t)L.pop();
				else res=0;
			}
			else if(R.top()<=t){
				if(R.top()==t)R.pop();
				else res=0;
			}
			else{
				res=res*2%Mod;
				for(int i:Q){
					if(i<t)L.push(i);
					else if(i>t)R.push(i);
				}
				Q.clear();
			}
		}
	}

	res=res*(SZ(Q)+1)%Mod;
	cout<<res<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int Mod = 1000000000+7;
const int oo = 0x3f3f3f3f;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long LL;
typedef priority_queue<int> QMax;
typedef priority_queue<int,vector<int>,greater<int>> QMin;
#define lbit(a) (a&-a)
#define SZ(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
#define all(a) (a).begin(),(a).end()
#ifdef CF
	#define FOPEN freopen("in.txt","r",stdin)
	#define BUG(x) cout<<x<<"_"<<endl;
#else
	#define FOPEN ;
	#define BUG(x) ;
#endif

const int N = 363304 + 5;

QMax L;
QMin R;
int n,t;
LL res=1;
string s;
int main(){
	cin>>n;
	vi Q;
	L.push(0);
	R.push(oo);
	for(int i=0;i<n;i++){
		cin>>s>>t;
		if(s=="ADD"){
			if(t<=L.top()){
				L.push(t);
			}else if(t>=R.top()){
				R.push(t);
			}else{
				Q.pb(t);
			}
		}else{
			if(L.top()>=t){
				if(L.top()==t)L.pop();
				else res=0;
			}
			else if(R.top()<=t){
				if(R.top()==t)R.pop();
				else res=0;
			}
			else{
				res=res*2%Mod;
				for(int i:Q){
					if(i<t)L.push(i);
					else if(i>t)R.push(i);
				}
				Q.clear();
			}
		}
	}
	res=res*(SZ(Q)+1)%Mod;
	cout<<res<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    vector <array <int, 2>> q;
    int lst = -1;
    rep(i, 0, n) {
        cin >> type >> x;
        q.push_back({{(type == "ADD" ? 1 : 2), x}});
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            lst = i;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    if (ans != 0) {
        int64_t ans2 = (int64_t)ans * (int64_t)((int)gre.size() + 1) % mod;
        ans = ans2;
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    int f = 0;
    rep(i, 0, n) {
        cin >> type >> x;
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            f = 1;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    if (f == 0) {
        rep(i, 0, n) {
            ans = (ans + ans) % mod;
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    vector <array <int, 2>> q;
    int lst = -1;
    rep(i, 0, n) {
        cin >> type >> x;
        q.push_back({{(type == "ADD" ? 1 : 2), x}});
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            lst = i;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
                for (auto y : gre) {
                    buy.insert(y);
                }
                gre.clear();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
                for (auto y : gre) {
                    sel.insert(y);
                }
                gre.clear();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    if (ans != 0) {
        int64_t ans2 = (int64_t)ans * (int64_t)((int)gre.size() + 1) % mod;
        ans = ans2;
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    vector <array <int, 2>> q;
    int lst = -1;
    rep(i, 0, n) {
        cin >> type >> x;
        q.push_back({{(type == "ADD" ? 1 : 2), x}});
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            lst = i;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    gre.clear();
    int ans2 = 0;
    rep(i, lst + 1, n) {
        int x = q[i][1];
        if (q[i][0] == 1) {
            ans2 = (ans2 + (int)gre.size() + 1) % mod;
            gre.insert(x);
        }
    }
    int64_t ans3 = (int64_t)ans * (int64_t)ans2 % mod;
    cout << ans3 << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    vector <array <int, 2>> q;
    int lst = -1;
    rep(i, 0, n) {
        cin >> type >> x;
        q.push_back({{(type == "ADD" ? 1 : 2), x}});
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            lst = i;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    gre.clear();
    ans = (ans + n - lst - 1) % mod;
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    rep(i, 0, n) {
        cin >> type >> x;
        if (type == "ADD") {
            if (x <= mx) {
                buy.insert(x);
            } else if (x >= mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            if (x == mn) {
                sel.erase(mn);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(mx);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
    }
    cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; ++i)

main() {
    int debug = 1;
    int n = 0, ans = 1, mod = 1e9 + 7, x, inf = 1e9, mn, mx;
    mx = -inf, mn = inf;
    string type;
    cin >> n;
    set <int> buy, gre, sel;
    buy.insert(mx);
    sel.insert(mn);
    vector <array <int, 2>> q;
    int lst = -1;
    rep(i, 0, n) {
        cin >> type >> x;
        q.push_back({{(type == "ADD" ? 1 : 2), x}});
        if (type == "ADD") {
            if (x < mx) {
                buy.insert(x);
            } else if (x > mn) {
                sel.insert(x);
            } else {
                gre.insert(x);
            }
        } else {
            lst = i;
            if (x == mn) {
                sel.erase(x);
                mn = *sel.begin();
            } else if (x == mx) {
                buy.erase(x);
                mx = *buy.rbegin();
            } else if (mx < x && x < mn) {
                ans = (ans + ans) % mod;
                for (auto y : gre) {
                    if (y < x) buy.insert(y);
                    if (y > x) sel.insert(y);
                }
                mx = *buy.rbegin();
                mn = *sel.begin();
                gre.clear();
            } else {
                ans = 0;
            }
        }
        assert(mx < mn);
        mx = *buy.rbegin();
        mn = *sel.begin();
        assert(mx < mn);
    }
    if (ans != 0) ans = (ans + gre.size()) % mod;
    cout << ans << '\n';
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if ((*buy.rbegin()) < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin()) == x){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin()) == x){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				while (!unkn.empty()){
					auto it = *unkn.begin();
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);

					unkn.erase(it);
				}
				continue;
			}
		}
	}
	ans %= mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if ((*buy.rbegin()) < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin()) == x){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin()) == x){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				for (auto it : unkn){
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);
				}
				unkn.clear();
				continue;
			}
		}
	}
	ans %= mod;
	if (!unkn.empty())
		ans = (ans + unkn.size() + 1) % mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	long long int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() || !buy.empty()){
				if ((*buy.rbegin()) < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin()) == x){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin()) == x){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				for (auto it : unkn){
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);
				}
				unkn.clear();
				continue;
			}
		}
	}
	ans %= mod;
	if (!unkn.empty())
		ans = (ans * (unkn.size() + 1)) % mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	long long int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if ((*buy.rbegin()) < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin()) == x){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin()) == x){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				for (auto it : unkn){
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);
				}
				unkn.clear();
				continue;
			}
		}
	}
	ans %= mod;
	if (!unkn.empty())
		ans = (ans * (unkn.size() + 1)) % mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if (*buy.rbegin() < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (!buy.empty() && x <= (*buy.rbegin())){
				if ((*buy.rbegin() == x))
					sell.insert(unkn.begin(), unkn.end());
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (!sell.empty() && x >= (*sell.begin())){
				if ((*sell.begin() == x))
					buy.insert(unkn.begin(), unkn.end());
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			ans *= 2;
			while (!unkn.empty()){
				if ((*unkn.begin()) < x)
					buy.insert(*unkn.begin());

				if ((*unkn.begin()) > x)
					sell.insert(*unkn.begin());

				unkn.erase(unkn.begin());
			}
		}
	}
	ans %= mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if (*buy.rbegin() < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin() == x)){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin() == x)){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				while (!unkn.empty()){
					auto it = *unkn.begin();
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);

					unkn.erase(it);
				}
				continue;
			}
			ans = 0;
		}
	}
	ans %= mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if ((*buy.rbegin()) < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin() == x)){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin() == x)){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (unkn.count(x)){
				ans *= 2;
				while (!unkn.empty()){
					auto it = *unkn.begin();
					if (it < x)
						buy.insert(it);

					if (it > x)
						sell.insert(it);

					unkn.erase(it);
				}
				continue;
			}
		}
	}
	ans %= mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (sell.empty() && buy.empty()){
				unkn.insert(x);
				continue;
			}

			if (!sell.empty() && !buy.empty()){
				if (*buy.rbegin() < x && x < (*sell.begin())){
					unkn.insert(x);
					continue;
				}
			}
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
		}
		if (s == "ACCEPT"){
			if (!buy.empty() && x <= (*buy.rbegin())){
				if ((*buy.rbegin() == x)){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (!sell.empty() && x >= (*sell.begin())){
				if ((*sell.begin() == x)){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			ans *= 2;
			while (!unkn.empty()){
				if ((*unkn.begin()) < x)
					buy.insert(*unkn.begin());

				if ((*unkn.begin()) > x)
					sell.insert(*unkn.begin());

				unkn.erase(unkn.begin());
			}
		}
	}
	ans %= mod;
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main(){ _
	int n;
	cin >> n;
	int mod = 1e9+7;
	string s;
	int x;
	set<int> sell;
	set<int> unkn;
	set<int> buy;
	long long int ans = 1;
	while (n--){
		cin >> s >> x;
		ans %= mod;
		if (s == "ADD"){
			if (!buy.empty() && x < (*buy.rbegin())){
				buy.insert(x);
				continue;
			}
			if (!sell.empty() && x > (*sell.begin())){
				sell.insert(x);
				continue;
			}
			unkn.insert(x);
		}
		if (s == "ACCEPT"){
			if (buy.count(x)){
				if ((*buy.rbegin()) == x){
					sell.insert(unkn.begin(), unkn.end());
					buy.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			if (sell.count(x)){
				if ((*sell.begin()) == x){
					buy.insert(unkn.begin(), unkn.end());
					sell.erase(x);
				}
				else
					ans = 0;
				unkn.clear();
				continue;
			}
			ans *= 2;
			for (auto it : unkn){
				if (it < x)
					buy.insert(it);

				if (it > x)
					sell.insert(it);
			}
			unkn.clear();
		}
	}
	ans %= mod;
	if (!unkn.empty())
		ans = (ans * (unkn.size() + 1)) % mod;
	cout << ans << endl;
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
string x;

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (cin >> n) {
		int minn = 0, maxn = 308983069;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			cin >> x >> v;
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				else if (v >= minn&&v <= maxn)
					ans = ans * 1 % mod;
				else
					ans *= 0;
				num.erase(v);
				auto ind = lower_bound(num.begin(), num.end(), v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v);
		}
		cout << ans << endl;
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
char x[100];

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (~scanf("%d", &n)) {
		int minn = 0, maxn = 308983069, vis = 0;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			scanf("%s%d", x, &v);
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				if (v<minn || v>maxn)
					ans *= 0;
				num.erase(v);
				vis = 1;
				auto ind = lower_bound(num.begin(), num.end(), v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v), vis += (v <= maxn && v >= minn ? 1 : 0);
		}
		printf("%d\n", ans*vis%mod);
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
string x;

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (cin >> n) {
		int minn = 0, maxn = 308983069;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			cin >> x >> v;
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				if (v<minn || v>maxn)
					ans *= 0;
				num.erase(v);
				auto ind = lower_bound(num.begin(), num.end(), v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v);
		}
		cout << ans << endl;
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
char x[100];

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (~scanf("%d", &n)) {
		int minn = 0, maxn = 308983069, vis = 0;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			scanf("%s%d", x, &v);
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				if (v<minn || v>maxn)
					ans *= 0;
				num.erase(v);
				vis = 1;
				auto ind = num.lower_bound(v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v), vis += (v <= maxn && v >= minn ? 1 : 0);
		}
		printf("%d\n", ans*vis%mod);
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
string x;

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (cin >> n) {
		int minn = 0, maxn = 308983069;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			cin >> x >> v;
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				else if (v > minn&&v < maxn)
					ans = ans * 1 % mod;
				else
					ans *= 0;
				num.erase(v);
				auto ind = lower_bound(num.begin(), num.end(), v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v);
		}
		cout << ans << endl;
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
string x;

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (cin >> n) {
		int minn = -1, maxn = -1;
		ans = 1;
		while (n--) {
			int ji = 0;
			cin >> x >> v;
			if (x[1] == 'C') {
				if (minn != -1 && v >= minn)
					minn = -1, ji++;
				if (maxn != -1 && v <= maxn)
					maxn = -1, ji++;
				ans *= ji;
				ans %= mod;
			}
			else {
				if (minn == -1)
					minn = v;
				else
					minn = min(minn, v);
				if (maxn == -1)
					maxn = v;
				else
					maxn = max(maxn, v);
			}
		}
		cout << ans << endl;
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
char x[100];

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (~scanf("%d", &n)) {
		int minn = 0, maxn = 308983069, vis = 1;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			scanf("%s%d", x, &v);
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				if (v<minn || v>maxn)
					ans *= 0;
				num.erase(v);
				vis = 1;
				auto ind = num.lower_bound(v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v), vis += (v <= maxn && v >= minn ? 1 : 0);
		}
		printf("%d\n", ans*vis%mod);
	}
	return 0;
}


#include<algorithm>
#include<typeinfo>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
#define pi acos(-1)
#define mod (1000000007)
#define fin(num,n) for(int aaa=1;aaa<=n;scanf("%d",&num[aaa++]))
#define fout(num,n) for(int aaa=1;aaa<=n;printf("%d%c",num[aaa++],aaa==n?'\n':' '))
#define ffin(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;scanf("%d",&num[aaa][bbb++]))
#define ffout(num,n,m) for(int aaa=1;aaa<=n;aaa++)for(int bbb=1;bbb<=m;printf("%d%c", num[aaa][bbb++], bbb==m?'\n':' '))
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef stack<int> si;
typedef stack<ll> sl;
typedef set<int> sti;
typedef set<ll> stl;
ll gcd(ll x, ll y) { return x > 0 ? gcd(y%x, x) : y; }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

ll ans;
int n, v;
string x;

int main() {
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(8);

	while (cin >> n) {
		int minn = 0, maxn = 308983069, vis = 0;
		sti num;
		num.insert(minn);
		num.insert(maxn);
		ans = 1;
		while (n--) {
			int ji = 0;
			cin >> x >> v;
			if (x[1] == 'C') {
				if (v > minn && v < maxn)
					ans = ans * 2 % mod;
				if (v<minn || v>maxn)
					ans *= 0;
				num.erase(v);
				vis = 1;
				auto ind = lower_bound(num.begin(), num.end(), v);
				maxn = *ind;
				minn = *--ind;
			}
			else
				num.insert(v), vis += (v <= maxn && v >= minn ? 1 : 0);
		}
		cout << ans*vis%mod << endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll PRICE_LIMIT = 1e9+1;
int main(){
    set<ll> orders;
    set<ll>::iterator it;
    set<ll>::iterator itup;
    ll bestBuy = 0;
    ll bestSell = PRICE_LIMIT;
    ll ans = 1;
    int n;
    cin >> n;
    string action;
    ll price;
    ll res = 1;
    for(int i=0; i<n;i++){
        cin >> action;
        scanf("%lld",&price);
        if(action == "ADD"){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else{
            res = 1;
            if(price < bestBuy || price > bestSell){
                ans = 0;
                break;
            }
            orders.erase(price);
            if(price > bestBuy && price < bestSell){
                ans = (ans * 2) % MOD;
            }
            itup = orders.upper_bound(price);
            if(itup != orders.end()) bestBuy = *(itup);
            else bestBuy = 0;
            if(itup != orders.begin()) bestSell = *(--itup);
            else bestSell = PRICE_LIMIT;
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll PRICE_LIMIT = 308983066+1;
int main(){
    set<int> orders;
    set<int>::iterator it,buyIt,sellIt;
    int bestBuy = 0;
    int bestSell = PRICE_LIMIT;
    ll ans = 1;
    int n;
    cin >> n;
    string action;
    int price;
    for(int i=0; i<n;i++){
        cin >> action >> price;
        if(action == "ADD"){
            orders.insert(price);
        }else if(action == "ACCEPT"){
            int len = orders.size();
            sellIt = orders.end();
            buyIt = orders.end();
            it = orders.end();
            for(it=orders.begin(); it!=orders.end();it++){
                it ++;
                sellIt  = it;
                it --;
                if((*it) == price){
                    break;
                }
                buyIt = it;
            }
            if(len == 0 || it == orders.end()){
                ans = 0;
                break;
            }else{
                if(price < bestBuy || price > bestSell){
                    ans = 0;
                    break;
                }
                if(price > bestBuy && price < bestSell){
                    ans = (ans * 2) % MOD;
                }
                if(buyIt != orders.end()) bestBuy = *(buyIt);
                else bestBuy = 0;
                if(sellIt != orders.end()) bestSell = *(sellIt);
                else bestSell = PRICE_LIMIT;
                orders.erase(it);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const int PRICE_LIMIT = 1e9;
int main(){
    set<int> orders;
    set<int>::iterator it;
    int bestBuy = 0;
    int bestSell = PRICE_LIMIT;
    orders.insert(PRICE_LIMIT);
    orders.insert(0);
    int ans = 1;
    int n;
    cin >> n;
    string action;
    int price = 0;
    ll res = 1;
    for(int i=0; i<n;i++){
        cin >> action >> price;
        if(action[1] == 'D'){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else{
            res = 1;
            if(price < bestBuy || price > bestSell){
                ans = 0;
                break;
            }
            orders.erase(price);
            if(price > bestBuy && price < bestSell){
                ans = (ans * 2) % MOD;
            }
            it = orders.lower_bound(price);
            bestSell = *(it);
            bestBuy = *(--it);
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll PRICE_LIMIT = 308983066+1;
int main(){
    set<int> orders;
    set<int>::iterator it;
    set<int>::iterator itup;
    int bestBuy = 0;
    int bestSell = PRICE_LIMIT;
    ll ans = 1;
    int n;
    cin >> n;
    string action;
    int price;
    int res = 1;
    for(int i=0; i<n;i++){
        cin >> action >> price;
        if(action == "ADD"){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else if(action == "ACCEPT"){
            res = 1;
            int len = orders.size();
            it = orders.find(price);
            if(len == 0 || it == orders.end()){
                ans = 0;
                break;
            }else{
                if(price < bestBuy || price > bestSell){
                    ans = 0;
                    break;
                }
                if(price > bestBuy && price < bestSell){
                    ans = (ans * 2) % MOD;
                }
                orders.erase(price);
                itup = orders.upper_bound(price);
                if(itup != orders.end()) bestBuy = *(itup);
                else bestBuy = 0;
                if(itup != orders.begin()) bestSell = *(--itup);
                else bestSell = PRICE_LIMIT;
            }
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll PRICE_LIMIT = 308983066+1;
int main(){
    set<int> orders;
    set<int>::iterator it;
    set<int>::iterator itup;
    int bestBuy = 0;
    int bestSell = PRICE_LIMIT;
    ll ans = 1;
    int n;
    cin >> n;
    string action;
    int price;
    int res = 1;
    for(int i=0; i<n;i++){
        cin >> action >> price;
        if(action == "ADD"){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else if(action == "ACCEPT"){
            res = 1;
            if(price < bestBuy || price > bestSell){
                ans = 0;
                break;
            }
            if(price > bestBuy && price < bestSell){
                ans = (ans * 2) % MOD;
            }
            orders.erase(price);
            itup = orders.upper_bound(price);
            if(itup != orders.end()) bestBuy = *(itup);
            else bestBuy = 0;
            if(itup != orders.begin()) bestSell = *(--itup);
            else bestSell = PRICE_LIMIT;
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll PRICE_LIMIT = 1e9;
int main(){
    set<ll> orders;
    set<ll>::iterator it;
    ll bestBuy = -PRICE_LIMIT;
    ll bestSell = PRICE_LIMIT;
    orders.insert(PRICE_LIMIT);
    orders.insert(-PRICE_LIMIT);
    ll ans = 1;
    int n;
    cin >> n;
    char action[10];
    ll price;
    ll res = 1;
    for(int i=0; i<n;i++){
        scanf("%s%lld",action,&price);
        //cout << price << endl;
        if(action[1] == 'D'){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else{
            res = 1;
            if(price < bestBuy || price > bestSell){
                ans = 0;
                break;
            }
            orders.erase(price);
            if(price > bestBuy && price < bestSell){
                ans = (ans * 2) % MOD;
            }
            it = orders.lower_bound(price);
            bestBuy = *(it);
            bestSell = *(--it);
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
const ll PRICE_LIMIT = 1e9+1;
int main(){
    set<ll> orders;
    set<ll>::iterator it;
    set<ll>::iterator itup;
    ll bestBuy = -PRICE_LIMIT;
    ll bestSell = PRICE_LIMIT;
    ll ans = 1;
    int n;
    cin >> n;
    string action;
    ll price;
    ll res = 1;
    for(int i=0; i<n;i++){
        cin >> action;
        scanf("%lld",&price);
        //cout << price << endl;
        if(action == "ADD"){
            if(price <= bestSell  && price >= bestBuy){
                res ++;
            }
            orders.insert(price);
        }else{
            res = 1;
            if(price < bestBuy || price > bestSell){
                ans = 0;
                break;
            }
            orders.erase(price);
            if(price > bestBuy && price < bestSell){
                ans = (ans * 2) % MOD;
            }
            itup = orders.upper_bound(price);
            if(itup != orders.end()) bestBuy = *(itup);
            else bestBuy = -PRICE_LIMIT;
            if(itup != orders.begin()) bestSell = *(--itup);
            else bestSell = PRICE_LIMIT;
        }
    }
    cout << ans * res % MOD << endl;
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	int a;
	int INF = (int)1 << 50;
	int l = -INF;
	int r = INF;
	set<int> st;
	st.insert(l);
	st.insert(r);
	int res = 1;
	for (int i = 0; i < N; i++) {
		cin >> S >> a;
		if (S[1] == 'D') {
			st.insert(a);
		}
		else {
			auto x = st.find(a);
			if (a >= l && a <= r) {
				if (a > l && a < r) {
					res = (res * 2) % MOD;
				}
				x--;
				l = (*x);
				x++; x++;
				r = (*x);
			}
			else {
				cout << 0 << endl;
				return 0;
			}
			st.erase(a);
		}
	}
	{
		auto x = st.find(l);
		x++;
		int c = 0;
		while ((*x) < r) {
			c++;
			x++;
		}
		res = (res * (c + 1)) % MOD;
	}
	cout << res << endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<int,int> mp;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>n)&&(pl<n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		        mp[n]=1;
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans*=(u+1);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
map<long long int,long long int>mp;
long long int m,n,a,b,c,d,e,f;
priority_queue<int> q1;
	long long ans=1;
priority_queue<int,vector<int>,greater<int> > q2;
int main()
{
	cin>>m;
	q1.push(-100000000);
	q1.push(100000000);

	for(int x=0;x<m;x++)
	{cin>>s>>n;
		if(s=="ADD")
		{
			mp[n]=2;
			q1.push(n);
			q2.push(n);
            f++;
		}
		else
		{
		    if(q1.top()>=n&&q2.top()<=n)
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()>=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		    }
		    else
            {

                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<int,int> mp;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		        mp[n]=1;
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans*=(u+1);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<long long int,long long int> mp;
priority_queue<long long int> q1;
long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        if(pr!=n&&pl!=n)
                {
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        mp[n]=1;
                }
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans=ans*(u+1)%(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                    u++;
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		        u=0;
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
         ans*=(u+1);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000];
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(pl<v[x]&&pr>v[x])
        {
         ans+=ans;
         ans%=(long long )(1e9+7);

        }
	}

	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<int,int> mp;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        if(pr!=n&&pl!=n)
                {
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        mp[n]=1;
                }
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans*=(u+1);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                    u++;
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		        u=1;
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
         ans*=(u);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
map<long long int,long long int>mp;
long long int m,n,a,b,c,d,e,f,p1,p2;
priority_queue<int> q1;
	long long ans=1;
priority_queue<int,vector<int>,greater<int> > q2;
int main()
{
	cin>>m;
	q1.push(-100000000);
	q2.push(100000000);

	for(int x=0;x<m;x++)
	{cin>>s>>n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<p2)
                {
                    q2.push(n);
                }
                else
                {
                    q1.push(n);
                }
            }

		}
		else
		{int vv=q1.top();
		int vvv=q2.top();
		    if((q1.top()>=n||q1.size()==2)&&(q2.top()<=n||q2.size()==1))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        p2=n;
		    }
		    else
            {

                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);

	for(int x=0;x<m;x++)
	{cin>>s>>n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<p2)
                {
                    q2.push(n);
                }
                else
                {
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((q1.top()>=n||q1.size()==1)&&(q2.top()<=n||q2.size()==1))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        p2=n;
		    }
		    else
            {

                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<int,int> mp;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        if(pr!=n&&pl!=n)
                {
		        ans*=2;
		        ans%=(long long )(1e9+7);
                }
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		        mp[n]=1;
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans*=(u+1);
         ans%=(long long )(1e9+7);
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);

	for(int x=0;x<m;x++)
	{cin>>s>>n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<p2)
                {
                    q2.push(n);
                }
                else
                {
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((q1.top()>=n||q1.size()==2)&&(q2.top()<=n||q2.size()==1))
		    {
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        p1=1;
		        p2=n;
		    }
		    else
            {

                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
map<int,int>mp;
int m,n,a,b,c,d,e,f;
priority_queue<int> q1;
priority_queue<int,vector<int>,greater<int> > q2;
int main()
{
	cin>>m;
	for(int x=0;x<m;x++)
	{
		cin>>s>>n;
		if(s=="ADD")
		{
			mp[n]=2;
			q1.push(n);
			q2.push(n);
            f++;
		}
		else
		{
		    mp[n]=0;
		    e++;
		    f--;
			while(!q1.empty()&&q1.top()>n)
			{
				q1.pop();
			}
			while(!q2.empty()&&q2.top()<n)
			{
				q2.pop();
			}
		}
	}
	while(!q1.empty())
	{
		mp[q1.top()]--;
		q1.pop();
		if(mp[q1.top()]==1)
		{
			f--;
		}
	}
	while(!q2.empty())
	{
		mp[q2.top()]--;
		q2.pop();
		if(mp[q2.top()]==1)
		{
			f--;
		}
		else if(mp[q2.top()]==0)
		{
			e++;
		}
	}
	if(f!=0)
	{
		cout<<"0"<<endl;
		return 0;
	}
	long long ans=1;
	while(e--)
	{
		ans*=2;
		ans%=(long long )(1e9+7);
	}
	cout<<ans<<endl;
}


#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
string s;
long long int m,n,a,b,c,d,e,f,p1,p2,p3,pr,pl,v[11000000],u;
map<int,int> mp;
priority_queue<long long int> q1;
	long long ans=1;
priority_queue<long long int,vector<long long int>,greater<long long int> > q2;
int main()
{
	cin>>m;
	q1.push(-10000000000ll);
	q2.push(10000000000ll);
    pl=-1100000000ll;
    pr=1100000000ll;
	for(int x=0;x<m;x++)
	{cin>>s>>n;
	v[d++]=n;
		if(s=="ADD")
		{
			if(p1==0)
			{q1.push(n);
			q2.push(n);
            }
            else
            {
                if(n<pl)
                {
                    q1.push(n);
                }
                else if(n>pr)
                {
                    q2.push(n);
                }
                else
                {
                    q2.push(n);
                    q1.push(n);
                }
            }

		}
		else
		{
		    if((pr>=n)&&(pl<=n))
		    {
		        if(pr!=n&&pl!=n)
                {
		        ans*=2;
		        ans%=(long long )(1e9+7);
		        mp[n]=1;
                }
		        while(!q1.empty()&&q1.top()>=n)
		        {
		            q1.pop();
		        }
		        while(!q2.empty()&&q2.top()<=n)
		        {
		            q2.pop();
		        }
		        p1=1;
		        pl=q1.top();
		        pr=q2.top();
		    }
		    else
            {
                cout<<"0"<<endl;
                return 0;
            }

		}
	}
	for(int x=0;x<d;x++)
	{
	    if(v[x]<pr&&v[x]<pl&&!mp[v[x]])
	    {
	        u++;
	    }
	}

         ans=ans*(u+1)%(long long )(1e9+7);
	cout<<ans<<endl;
}


#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);
                }
            }
        }
        if(n == 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')
            {
                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 <= 10)
        da = da*(sz + 1)%mod;
        printf("%lld\n",da);
    }

}