#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define MOD 1000000
#define IT multiset<int>::iterator
using namespace std;
typedef long long LL;
typedef long double LD;
multiset<int> s1,s2;int n;
int main()
{
ios::sync_with_stdio(false);
scanf("%d",&n);int c1=0,c2=0,i,op,x;IT itl,itr;
s1.insert(-2e9);s1.insert(2e9);
s2.insert(-2e9);s2.insert(2e9);LL res=0;
FOR(i,1,n)
{
scanf("%d%d",&op,&x);
if (op==0)
{
if (c2)
{
itl=itr=s2.lower_bound(x);itl--;
int lv=*itl,rv=*itr;
if (abs(lv-x)<=abs(rv-x)) {res+=abs(lv-x),res%=MOD;s2.erase(lv);}
else {res+=abs(rv-x),res%=MOD;s2.erase(rv);}
c2--;
}else {s1.insert(x);c1++;}
}else
{
if (c1)
{
itl=itr=s1.lower_bound(x);itl--;
int lv=*itl,rv=*itr;
if (abs(lv-x)<=abs(rv-x)) {res+=abs(lv-x),res%=MOD;s1.erase(lv);}
else {res+=abs(rv-x),res%=MOD;s1.erase(rv);}
c1--;
}else {s2.insert(x);c2++;}
}
}
printf("%lld\n",res);
return 0;
}