Buggy python submission (verdict: Runtime Error):
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


def f(hs, a_s):
    for h, a in zip(hs, a_s):
        update(h, get(h - 1) + a)
    print(max(bit))


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
bit = [0] * (n + 1)
f(n, hs, a_s)


Fixed submission:
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))

bit = [0] * (n + 1)
for h, a in zip(hs, a_s):
    update(h, get(h - 1) + a)
print(max(bit))

Buggy python submission (verdict: Runtime Error):
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


def f(hs, a_s):
    for h, a in zip(hs, a_s):
        update(h, get(h - 1) + a)
    print(max(bit))


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
bit = [0] * (n + 1)
f(n, hs, a_s)


Fixed submission:
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))

bit = [0] * (n + 1)
for h, a in zip(hs, a_s):
    update(h, get(h - 1) + a)
print(max(bit))

Buggy python submission (verdict: Time Limit Exceeded):
def f(n, hs, a_s):
    sum_a = [0] * n
    sum_a[0] = a_s[0]
    for ai, a in enumerate(a_s[1:]):
        mx = 0
        h = hs[ai + 1]
        for i in range(ai + 1):
            if h > hs[i]:
                if sum_a[i] > mx:
                    mx = sum_a[i]
        sum_a[ai + 1] = a + mx
    return sum_a[-1]


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
print(f(n, hs, a_s))


Fixed submission:
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))

bit = [0] * (n + 1)
for h, a in zip(hs, a_s):
    update(h, get(h - 1) + a)
print(max(bit))

Buggy python submission (verdict: Time Limit Exceeded):
def f(n, hs, a_s):
    sum_a = [0] * n
    sum_a[0] = a_s[0]
    for ai, a in enumerate(a_s[1:]):
        mx = 0
        h = hs[ai + 1]
        for i in range(ai + 1):
            if h > hs[i]:
                if sum_a[i] > mx:
                    mx = sum_a[i]
        sum_a[ai + 1] = a + mx
    return sum_a[-1]


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))
print(f(n, hs, a_s))


Fixed submission:
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))

bit = [0] * (n + 1)
for h, a in zip(hs, a_s):
    update(h, get(h - 1) + a)
print(max(bit))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
hs=list(map(int, input().split()))
a_s=list(map(int, input().split()))

sum_a=[0]*n
sum_a[0]=a_s[0]
for ai,a in enumerate(a_s[1:]):
    mx = 0
    h=hs[ai+1]
    for i in range(ai+1):
        if h>hs[i]:
            if sum_a[i]>mx:
                mx=sum_a[i]
    sum_a[ai+1]=a+mx
print(sum_a[-1])

Fixed submission:
def get(i):
    mx = 0
    while i > 0:
        if bit[i] > mx:
            mx = bit[i]
        i -= i & -i
    return mx


def update(i, x):
    while i < n + 1:
        if x > bit[i]:
            bit[i] = x
        i += i & -i


n = int(input())
hs = list(map(int, input().split()))
a_s = list(map(int, input().split()))

bit = [0] * (n + 1)
for h, a in zip(hs, a_s):
    update(h, get(h - 1) + a)
print(max(bit))