n = int(input())
sec = 0
a = []
b = []
l = 0
poz = []
poz1 = []
neg = []
neg1 = []
a1 = []
b1 = []

for i in range(n):
    x, s = map(int, input().split())
    a.append(x)
    b.append(s)
    if x > 0:
        poz.append(x)
        poz1.append(s)
    else:
        neg.append(x)
        neg1.append(s)
  
minp = a[0]
maxn = a[0]
for i in range(n):
    if len(poz) > 0:
        minp = min(poz)
        h = poz.index(minp)
    if len(neg) > 0:
        maxn = max(neg)
        h1 = neg.index(maxn)
    if i == 0:
        a1.append(minp)
        b1.append(poz1[h])
        a1.append(maxn)
        b1.append(neg1[h1])
        del poz[h]
        del poz1[h]
        del neg[h1]
        del neg1[h1]
    else:
        if b1[i] > b1[i-1] and len(poz) > 0:
            a1.append(minp)
            b1.append(poz1[h])
            del poz[h]
            del poz1[h]
        elif b1[i] <= b1[i-1] and len(neg) > 0:
            a1.append(maxn)
            b1.append(neg1[h1])
            del neg[h1]
            del neg1[h1]
        

i = 0
br = 0

while len(a) > 1:
    if br % 2 == 0:
        sec += abs(a[i] - l)
        l = a[i]
        b[i] -= 1
    else:
        sec += abs(a[i+1] - l)
        l = a[i+1]
        b[i+1] -= 1
    if b[i] == 0:
        del b[i]
        del a[i]
    elif b[i+1] == 0:
        del b[i+1]
        del a[i+1]
    br += 1
    
sec += abs(a[0] - l)
sec = sec % 1000000007
print(sec)