#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <fstream>
#include<stdlib.h>

#define rep( i, l, r ) for (int i = l; i <= r; i++)
#define down( i, l, r ) for (int i = l; i >= r; i--)

using namespace std;

const int DS = 80000;
const int MaxNum = 2147483647;

int o, now, h[DS], l[DS], r[DS], n[DS], last, a, m, ans, num[DS];

int NewTree()
{
	int w = last; last = n[w];
	n[w] = h[w] = l[w] = r[w] = num[w] = 0;
	return w;
}

void LRotato(int w)
{
	int o = h[w];
	if (l[h[o]] == o) l[h[o]] = w; else r[h[o]] = w; h[w] = h[o];
	r[o] = l[w]; h[l[w]] = o;
	h[o] = w; l[w] = o;
}

void RRotato(int w)
{
	int o = h[w];
	if (l[h[o]] == o) l[h[o]] = w; else r[h[o]] = w; h[w] = h[o];
	l[o] = r[w]; h[r[w]] = o;
	h[o] = w; r[w] = o;
}

void Splay(int w)
{
	if (w == 0) return;
	while (h[w] != 0)
	{
		if (l[h[w]] == w) RRotato(w); else LRotato(w);
	}
}

int Pre()
{
	int p = l[l[0]];
	if (p == 0) return 0;
	while (r[p] != 0) p = r[p];
	return p;
}

int Suf()
{
	int p = r[l[0]];
	if (p == 0) return 0;
	while (l[p] != 0) p = l[p];
	return p;
}

void Insert(int m)
{
	now++;
	int p = l[0], c = 0, w = 0; 
	bool b = true;
	while (p != 0)
	{
		if (m <= num[p])
		{
			c = p; p = l[p]; b = true;
		}
		else
		{
			c = p; p = r[p]; b = false;
		}
	}
	w = NewTree();
	h[w] = c; if (b) l[c] = w; else r[c] = w; num[w] = m;
	Splay(w);
}

void Delete(int w)
{
	now--;
	int o = h[w];
	if (l[o] == w) l[o] = 0; else r[o] = 0;
	n[w] = last; last = w;
}

int FindAim(int m)
{
	int w = last;
	Insert(m);
	int a = Pre(), b = Suf(), aa = 0, bb = 0;
	if (a != 0) aa = m - num[a]; else aa = MaxNum;
	if (b != 0) bb = num[b] - m; else bb = MaxNum;
	if (aa <= bb) 
	{
		Splay(a); Splay(b); Delete(w); 
		w = a; Splay(w); a = Pre(); b = Suf(); 
		Splay(a); Splay(b); Delete(w); 
		return aa;
	}
	else
	{
		Splay(a); Splay(b); Delete(w); 
		w = b; Splay(w); a = Pre(); b = Suf(); 
		Splay(a); Splay(b); Delete(w); 
		return bb;
	}
}

int main()
{
	ans = now = 0; 
	bool b = false; 
	rep(i, 1, DS-1) n[i] = i+1; last = 1; 
	scanf("%d", &o);
	rep(i, 1, o)
	{
		scanf("%d%d", &a, &m);
		if (now == 0) 
		{
			Insert(m);
			if (a == 0) b = true; else b = false;
		}
		else
		{
			if (b == (a == 0)) Insert(m); else ans += FindAim(m) % 1000000;
		}
		ans = ans % 1000000;
	}
	printf("%d", ans);
	return 0;
}
