#include <bits/stdc++.h>
using namespace std;
vector < pair<bool,long long int> > que;
vector <long long int> sz;
int main()
{
	// freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	int m;
	cin>>m;
	que.push_back(make_pair(false,1ll));
	sz.push_back(1ll);
	while(m--)
	{
		char ch;
		cin>>ch;
		if(ch == '+')
		{
			long long int k;
			cin>>k;
			if(k == 1)
			{
				if(que.back().first)
				{
					que.back().second++;
					sz.back()++;
				}
				else
				{
					que.push_back(make_pair(true,1ll));
					sz.push_back(1+sz.back());
				}
			}
			else
			{
				que.push_back(make_pair(false,k));
				sz.push_back(k*sz.back() + 1);
			}
		}
		else
		{
			long long int org_x,org_y,x,y;
			cin>>org_x>>org_y;
			x = org_x;
			y = org_y;
			long long int sep_depth = 0;
			bool found = false;
			for (int i = que.size()-1; i >= 0 && !found; --i)
			{
				if(que[i].first)
				{
					if(x > que[i].second && y > que[i].second)
					{
						x-=que[i].second;
						y-=que[i].second;
						sep_depth+=que[i].second;
					}
					else
					{
						sep_depth+=min(x,y);
						found = true;
					}
				}
				else
				{
					if(x > 1ll && y > 1ll)
					{
						x--;
						y--;
						sep_depth++;
						long long int v1 = (x-1ll)/sz[i-1];
						long long int v2 = (y-1ll)/sz[i-1];
						if(v1 == v2)
						{
							x = (x-1ll)%sz[i-1];
							y = (y-1ll)%sz[i-1];
							x++;
							y++;
						}
						else
						{
							found = true;
						}
					}
					else
					{
						sep_depth++;
						found = true;
					}
				}
			}
			// cout<<sep_depth<<"\n";
			x = org_x;
			long long int x_depth = 0;
			found = false;
			for (int i = que.size()-1; i >= 0 && !found; --i)
			{
				if(que[i].first)
				{
					if(x > que[i].second)
					{
						x-=que[i].second;
						x_depth+=que[i].second;
					}
					else
					{
						x_depth+=x;
						found = true;
					}
				}
				else
				{
					if(x > 1ll)
					{
						x--;
						x_depth++;
						x = (x-1ll)%sz[i-1];
						x++;
					}
					else
					{
						x_depth++;
						found = true;
					}
				}
			}
			// cout<<x_depth<<"\n";
			y = org_y;
			long long int y_depth = 0;
			found = false;
			for (int i = que.size()-1; i >= 0 && !found; --i)
			{
				// cout<<que[i].first<<" "<<que[i].second<<" "<<y<<"\n";
				if(que[i].first)
				{
					if(y > que[i].second)
					{
						y-=que[i].second;
						y_depth+=que[i].second;
					}
					else
					{
						y_depth+=y;
						found = true;
					}
				}
				else
				{
					if(y > 1ll)
					{
						y--;
						y_depth++;
						y = (y-1ll)%sz[i-1];
						y++;
					}
					else
					{
						y_depth++;
						found = true;
					}
				}
			}
			// cout<<y_depth<<"\n";
			assert(sep_depth <= x_depth && sep_depth <= y_depth);
			cout<<(x_depth-sep_depth)+(y_depth-sep_depth)<<"\n";
		}
	}
	return 0;
}