#include <ctype.h>
#include <cstdio>
#define N 100000
#define INF 0x7fffffff
inline void read(int &x)
{
x=0;bool f=0;
register char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch==‘-‘) f=1;
for(; isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+ch-‘0‘;
x=f?(~x)+1:x;
}
int v1,v2,zr,ans,root,n,cn,data[N],cnt[N],siz[N],fa[N],ch[N][2];
inline void pushup(int rt) {siz[rt]=siz[ch[rt][0]]+siz[ch[rt][1]]+cnt[rt];}
inline int son(int x) {return ch[fa[x]][1]==x;}
inline void rotate(int x)
{
int y=fa[x],z=fa[y],b=son(x),c=son(y),a=ch[x][!b];
if(z) ch[z][c]=x;else root=x;fa[x]=z;
if(a) fa[a]=y;ch[y][b]=a;
ch[x][!b]=y;fa[y]=x;
pushup(y);pushup(x);
}
void splay(int x,int i)
{
while(fa[x]!=i)
{
int y=fa[x],z=fa[y];
if(z==i) rotate(x);
else
{
if(son(x)==son(y))
{
rotate(y);
rotate(x);
}
else
{
rotate(x);
rotate(x);
}
}
}
}
void ins(int &rt,int x)
{
if(rt==0)
{
rt=++cn;
data[cn]=x;
cnt[cn]=siz[cn]=1;
splay(cn,0);
return;
}
if(data[rt]==x)
{
cnt[rt]++;
siz[rt]++;
splay(rt,0);
return;
}
if(x<data[rt])
{
ins(ch[rt][0],x);
fa[ch[rt][0]]=rt;
pushup(rt);
}
else
{
ins(ch[rt][1],x);
fa[ch[rt][1]]=rt;
pushup(rt);
}
}
void getpre(int rt,int x)
{
int p=rt;v1=-1;
while(p)
{
if(x<=data[p]) p=ch[p][0];
else
{
v1=p;
p=ch[p][1];
}
}
}
void getsuc(int rt,int x)
{
int p=rt;v2=-1;
while(p)
{
if(x>=data[p]) p=ch[p][1];
else
{
v2=p;
p=ch[p][0];
}
}
}
int getmn(int rt)
{
int p=rt,ans=-1;
while(p)
{
ans=p;
p=ch[p][0];
}
return ans;
}
void del(int rt,int x)
{
if(data[rt]==x)
{
if(cnt[rt]>1)
{
cnt[rt]--;
siz[rt]--;
}
else
{
splay(rt,0);
int p=getmn(ch[rt][1]);
if(p!=-1)
{
splay(p,rt);
root=p;fa[p]=0;
ch[p][0]=ch[rt][0];
fa[ch[rt][0]]=p;
}
else
{
root=ch[rt][0];
fa[ch[rt][0]]=0;
}
}
return ;
}
if(x<data[rt])
{
del(ch[rt][0],x);
pushup(rt);
}
else
{
del(ch[rt][1],x);
pushup(rt);
}
}
int main(int argc,char *argv[])
{
read(n);
for(int x,y;n--;)
{
read(x);
read(y);
if((x&&zr<0)||(!x&&zr>0))
{
int o,p,pos;
ins(root,y);
getpre(root,y);
getsuc(root,y);
del(root,y);
int x1=(v1!=-1)?y-data[v1]:INF,x2=(v2!=-1)?data[v2]-y:INF;
if(x1>x2) o=x2,p=data[v2],pos=v2;
else o=x1,p=data[v1],pos=v1;
ans=(ans+o)%1000000;
del(root,p);
}
else ins(root,y);
zr+=x?1:-1;
}
printf("%d\n",ans%1000000);
return 0;
}