inf = -10 ** 9
n = int(input())
t = [0] * (n + 1)
p = [0] * (n + 1)
for i in range(1, n + 1):
    t[i], p[i] = map(int, input().split())
ans = 0


def go(day, s):
    global ans
    if day == n + 1:
        ans = max(ans, s)
        return
    if day > n + 1:
        return
    go(day + 1, s)
    go(day + t[day], s + p[day])


go(1, 0)
print(ans)

9d02cd0cd95fa6fac2925cb5eeeb619fb587f562
<mask token>

<mask token>


def go(day, s):
    global ans
    if day == n + 1:
        ans = max(ans, s)
        return
    if day > n + 1:
        return
    go(day + 1, s)
    go(day + t[day], s + p[day])


<mask token>

<mask token>
for i in range(1, n + 1):
    t[i], p[i] = map(int, input().split())
<mask token>


def go(day, s):
    global ans
    if day == n + 1:
        ans = max(ans, s)
        return
    if day > n + 1:
        return
    go(day + 1, s)
    go(day + t[day], s + p[day])


go(1, 0)
print(ans)

inf = -10 ** 9
n = int(input())
t = [0] * (n + 1)
p = [0] * (n + 1)
for i in range(1, n + 1):
    t[i], p[i] = map(int, input().split())
ans = 0


def go(day, s):
    global ans
    if day == n + 1:
        ans = max(ans, s)
        return
    if day > n + 1:
        return
    go(day + 1, s)
    go(day + t[day], s + p[day])


go(1, 0)
print(ans)
