answer = 0
enduranceLeft = 0
enduranceRight = 0
rightWalls = []
leftWalls = []
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)

rightWalls.sort()
leftWalls.sort()
del wall
if enduranceLeft < enduranceRight:
    value = True
else:
    value = False

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

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

if value is True:
    answer += maxRight
else:
    answer -= maxLeft

print(answer%1000000007)