n = int(input())
sec = 0
a = []
b = []
l = 0

for i in range(n):
    x, s = map(int, input().split())
    a.append(x)
    b.append(s)

##for i in range(n-1):
##    if a[i] < a[i+1]:
##        a[i], a[i+1], b[i], b[i+1] = a[i+1], a[i], b[i+1], b[i]
##        
i = 0
br = 0
print(a,b)
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
    print(a, b, sec, l)
sec += abs(a[0] - l)
sec = sec % 1000000007
print(sec)