answer = 0
enduranceLeft = 0
enduranceRight = 0
rightWalls = []
leftWalls = []
mini = 0
for n in range(int(input())):

    wall = list(map(int, input().split()))
    if wall[0] < 0:
        enduranceLeft += wall[1]
        leftWalls.append(wall)
    else:
        enduranceRight += wall[1]
        rightWalls.append(wall)
        mini = min(mini, wall[0])

for wall in rightWalls:
    if enduranceLeft > 0:
        answer += min(wall[1], enduranceLeft) * wall[0] * 2
        enduranceLeft -= min(wall[1], enduranceLeft)
    else:
        break

for wall in leftWalls:
    if enduranceRight > 0:
        answer += min(wall[1], enduranceRight) * wall[0] * 2
        enduranceRight -= min(wall[1], enduranceRight)
    else:
        break

if enduranceLeft < enduranceRight:
    answer += mini

print(answer%1000000007)