Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03101 (python)

Fixed submission:
W,H=map(int,input().split())
w,h=map(int,input().split())
print(W*H-(h*W+w*H-w*h))

Buggy submission (verdict: Runtime Error):
W,H=map(int,input())
w,h=map(int,input())
print(W*H-(h*W+w*H-w*h))
Problem p03262 (python)

Fixed submission:
N, X = map(int, input().split())
l = list(map(int, input().split()))
g = X - l[0]
from fractions import gcd
for i in l[1:N]:
	if i == X: continue
	g = gcd(g, abs(X-i))

print(abs(g))

Buggy submission (verdict: Runtime Error):
from math import gcd
N, X = map(int, input().split())
l = list(map(int, input().split()))
g = X - l[0]
for i in l[1:N]:
	if i == X: continue
	g = gcd(g, abs(X-i))

print(abs(g))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
l = list(map(int, input().split()))
g = X - l[0]
from math import gcd
for i in l[1:N]:
	if i == X: continue
	g = gcd(g, abs(X-i))

print(abs(g))

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
l = list(map(int, input().split()))
g = X - l[0]
from math import gcd
for i in l[1:N]:
	if i == X: continue
	g = gcd(g, abs(X-i))

print(abs(g))
Problem p03455 (python)

Fixed submission:
a,b = map(int, input().split())
if (a*b) % 2 == 0:
	print('Even')
else:
	print('Odd')

Buggy submission (verdict: Runtime Error):
n = int(input())
t_now = 0
x_now = 0
y_now = 0
flag = True
for _ in range(n):
    t, x, y = map(int, input().split())
    if t < abs(x - x_now) or t < abs(y - y_now) or (y == y_now and x == x_now):
        print('No')
        flag = False
        break
    t_now = t
    x_now = x
    y_now = y
if flag:
    print('Yes')
Problem p03494 (python)

Fixed submission:
from time import sleep
n = input()
A = list(map(int, input().split()))
i = 0
while True:
    if len([a for a in A if a % 2]) > 0:
        break
    A = list(map(lambda x: x/2, A))
    i+=1
print(i)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int, input().split())
while True:
	sum(a)
	if sum % 2:
		break
	for num in a:
		num = num / 2
	i += 1
print(i)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int, input().split())
while True:
	sum += [num for num in a]
	if sum % 2:
		break
	for num in a:
		num /= 2
	i += 1
print(i)

Buggy submission (verdict: Runtime Error):
n = input()
a = list(map(int, input().split())
while True:
	sum += a[num for num in len(a)]
	if sum % 2:
		break
	for num in a:
		num /= 2
	i += 1
print(i)
Problem p03998 (python)

Fixed submission:
s=[input().replace('a','0').replace('b','1').replace('c','2') for _ in '111'];t=0
while True:
	if len(s[t])==0:
		print('ABC'[t])
		exit()
	a=int(s[t][0])
	s[t]=s[t][1:]
	t=a

Buggy submission (verdict: Runtime Error):
s=[input().replace('a','0').replace('b','1').replace('c','2') for _ in '111'];
while True:
	t=int(s[t][0])
	s[t]=s[t][1:]
	if len(s[t])==0:
		print('ABC'[t])
		exit()
Problem p02999 (python)

Fixed submission:
x, a = map(int, input().split())
 
if x < a:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = list(map(int, input().split()))

d = 0
cnt = 0
if l[0] == 0:
    print(0)
else:
    cnt += 1
    for i in range(1,n):
        d += l[i - 1]
        if d <= x:
            cnt += 1
    print(cnt)

Buggy submission (verdict: Runtime Error):
x, a = map(int, input())
 
if x < a:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
x a = map(int, input())

if x < a:
  print(0)
else:
  print(10)
Problem p03067 (python)

Fixed submission:
A, B, C = map(int, input().split())
if A > B:
    tmp = A
    A =  B
    B = tmp 

if C >= A and C <= B:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N-1):
    if S[i-1] == "#" and S[i] == ".":
        s[i] = "."
         cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N-1):
    if S[i-1] == "#":
        for j in range(i, N-1):
             if S[j] ==  ".":
                 cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
    if S[i-1] == "#" and S[i] == ".":
        s[i] = "#"
         cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
    if S[i-1] == "#" and S[i] == ".":
        s[i-1] = "."
         cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
    if S[i-1] == "#" :
        s[i] = "."
         cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
     if S[i-1] == "#":
         if S[i] == ".":
             S[i] = "#"
             cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = lisr(input())
cnt = 0
for i in range(1, N):
    if S[i-1] == "#" and S[i] == ".":
        cnt += 1
print(cnt)
Problem p03068 (python)

Fixed submission:
N = int(input())
S = list(input())
K = int(input())
 
for i in S:
    if S[K-1] == i:
        print(i, end="")
    else:
        print("*", end="")
print()

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(input())
K = int(input())

for i in S:
    if S[K] == i:
        print(i, end="")
    else:
        print("*", end="")
print()
Problem p03605 (python)

Fixed submission:
l = list(input())
for i in l:
    if i == "9":
        print("Yes")
        break
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b = input().split('')

if a == "9" or b == "9":
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split(''))

if a == 9 or b == 9:
    print("Yes")
else:
    print("No")
Problem p03623 (python)

Fixed submission:
x, a, b = map(int, input().split())

if abs(x - a) < abs(x - b):
    print("A")
else:
    print("B")

Buggy submission (verdict: Runtime Error):
x, a, b = map(int, input().split())

if abs(x - a) < abs(x - b):
    print(A)
else:
    print(B)
Problem p03657 (python)

Fixed submission:
A, B = map(int, input().split())

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())
        print("No")

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print("Possible")
else:
    print("Impossible")

Buggy submission (verdict: Runtime Error):
A, B = maP(int, input().split())

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print("Possible")
else:
    print("Impossible")
Problem p03693 (python)

Fixed submission:
r, g, b = map(int, input().split())

if (r * 100 + g * 10 + b) % 4 == 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

print(["error", A + B] [A + B < 10])
Problem p03697 (python)

Fixed submission:
A, B = map(int, input().split())

print(["error", A + B] [A + B < 10])

Buggy submission (verdict: Runtime Error):
A, B = map(int, input().split())

print(["error", A + B] A + B < 10)
Problem p03711 (python)

Fixed submission:
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, input().split())

print(["No", "Yes"] [L[x] == L[y]])

Buggy submission (verdict: Runtime Error):
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, input().split())

if L(x) == L(y):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, intput().split())

print(["Yes", "No"] [L(x) == l(y)])

Buggy submission (verdict: Runtime Error):
L = [0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0]

x, y = map(int, intput().split())

print(["Yes", "No"] [if L(x) == l(y)]
Problem p03844 (python)

Fixed submission:
ans = eval(input())
print(ans)

Buggy submission (verdict: Runtime Error):
print(eval(input())
Problem p03000 (python)

Fixed submission:
nx = map(int, raw_input().split())
l = map(int, raw_input().split())
 
n = nx[0]
x = nx[1]
 
d = 0
i = 1
 
while True:
    if d <= x:
        d += l[i-1]
        i += 1
    if d > x:
        print(i-1)
        break
    if i == n + 1:
      print(i)
      break

Buggy submission (verdict: Runtime Error):
nx = map(int, raw_input().split())
l = map(int, raw_input().split())
 
n = nx[0]
x = nx[1]
 
d = L[0]
i = 1
L = 1
 
while d <= x:
    d += l[L]
    i += 1
    L += 1  
    if i == n + 1:
      break
print(i)

Buggy submission (verdict: Runtime Error):
nx = map(int, raw_input().split())
l = map(int, raw_input().split())
 
n = nx[0]
x = nx[1]
 
d = 0
i = 0
 
while d <= x:
    if i  == n + 1:
      break
    d += l[i]
    i += 1 
print(i)

Buggy submission (verdict: Runtime Error):
nx = list(map(int, input().split()))
l = list(map(int, input().split()))
x = nx[1]
n = nx[0]
l[0]= 0
d = 0

for i in range(101):
    d = d + l[i]
    print(d)
    if d >= x:
        print(i+1)
        break

Buggy submission (verdict: Runtime Error):
nx = list(map(int, input().split()))
l = list(map(int, input().split()))
x = nx[1]
d = 0
i = 0

while d <= x:
    d = d + l[i]
    i += 1

print(i)

Buggy submission (verdict: Runtime Error):
nx = map(int, input().split())
l = map(int, input().split())
x = nx[1]
d = 0
i = 0

while d <= x:
    d = d + l[i]
    i += 1

print(i)

Buggy submission (verdict: Runtime Error):
nx = map(int, raw_input().split())
l = map(int, raw_input().split())

x = nx[1]

d = 0
i = 0

while d <= x:
    d = d + l[i]
    i = i + 1

print(i)

Buggy submission (verdict: Runtime Error):
nx = map(int, raw_input().split())
l = map(int, raw_input().split())

n = nx[0]
x = nx[1]

d = 0
i = 0

while d <= x:
    d = d + l[i]
    i = i + 1

print(i)
Problem p02999 (python)

Fixed submission:
# -*- coding: utf-8 -*-
tmp = list(map(int, input().split()))
if tmp[0] < tmp[1]:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
tmp = map(int, input().split())
if tmp[0] < tmp[1]:
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
tmp = map(int, input().split(' '))
if tmp[0] < tmp[1]:
  print(0)
else:
  print(10)
Problem p03000 (python)

Fixed submission:
# -*- coding: utf-8 -*-
info = list(map(int, input().split(' ')))
N, X = info[0], info[1]
info = list(map(int, input().split(' ')))
len = 0

count = 1

for for1 in info:
  len += for1
  if len <= X:
    count += 1
  else:
    break

print(count)

Buggy submission (verdict: Runtime Error):
info = map(int, input().split(' '))
N, X = info[0], info[1]
info = map(int, input().split(' '))
len = 0

count = 1

for for1 in info:
  len += for1
  if len <= X:
    count += 1
  else:
    break

print(count)
Problem p03160 (python)

Fixed submission:
# coding: utf-8

n = int(input())    # 2 <= n <= 10^5
h = list(map(int, input().rstrip().split()))
dp = [0]
for i in range(1, n):
    dp.append(min( \
        dp[i - 1] + abs(h[i - 1] - h[i]), \
        float('inf') if i < 2 else dp[i - 2] + abs(h[i - 2] - h[i])))
print(dp[- 1])

Buggy submission (verdict: Runtime Error):
# coding: utf-8

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

dp = [0]
for i in range(1, n):
    dp.append(min(dp[j] + abs(h[i] - h[j]) \
        for j in range(max(i - k, 0), i)))
print(dp[-1])

Buggy submission (verdict: Runtime Error):
# coding: utf-8

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

dp = [0] * 100010
for i in range(1, n):
    c = float('inf')
    for j, d in enumerate(dp[:i]):
        c_ = d + abs(h[i - j] - h[i])
        if c_ < c:
            c = c_
    dp[i] = c
print(dp[i])

Buggy submission (verdict: Runtime Error):
# coding: utf-8

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

dp = [0] * 100010
for i in range(1, n):
    c = float('inf')
    for j in range(1, k + 1):
        if j > i:
            break
        else:
            c_ = dp[i - j] + abs(h[i - j] - h[i])
            if c_ < c:
                c = c_
    dp[i] = c
print(dp[i])
Problem p03161 (python)

Fixed submission:
# coding: utf-8

def f(n, k, h):
    dp = [0 for _ in range(n)]
    for i in range(1, n):
        js = max(i - k, 0)
        dp[i] = min(dp[j] + abs(h[i] - h[j]) \
            for j in range(js, i))
        # print(dp)
    return(dp[i])

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

print(f(n, k, h))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))
#
dp = [0] * 100010
for i in range(1, n):
    for j in range(1, k + 1):
        if j > i:
            break
        else:
            c_ = dp[i - j] + abs(h[i - j] - h[i])
            if c_ < c:
                c = c_
    dp[i] = c
print(dp[i])
Problem p03166 (python)

Fixed submission:
# coding: utf-8
from functools import lru_cache

import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)

@lru_cache(maxsize = None)
def f(v):
    if not arc[v]:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().split())
    arc[x - 1].append(y - 1)
print(max(f(v) for v in range(n)))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from functools import lru_cache
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

@lru_cache(maxsize = None)
def f(v):
    if not arc[v]:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n)]
for _ in range(m):
    x, y = map(int, input().split())
    arc[x - 1].append(y - 1)
print(max(f(v) for v in range(n)))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from functools import lru_cache
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

@lru_cache(maxsize = None)
def f(v):
    if len(arc[v]) == 0:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n + 1)]
for i in range(m):
    x, y = map(int, input().split())
    arc[x].append(y)
print(max(f(v + 1) for v in range(n)))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from functools import lru_cache
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)

@lru_cache(maxsize = None)
def f(v):
    if len(arc[v]) == 0:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n + 1)]
for i in range(m):
    x, y = map(int, input().split())
    arc[x].append(y)
print(max(f(v + 1) for v in range(n)))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from functools import lru_cache
sys.setrecursionlimit(10000)

import sys
input = sys.stdin.readline

@lru_cache(maxsize = None)
def f(v):
    if len(arc[v]) == 0:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n + 1)]
for i in range(m):
    x, y = map(int, input().split())
    arc[x].append(y)
print(max(f(v + 1) for v in range(n)))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
input = sys.stdin.readline

def f(v):
    if len(arc[v]) == 0:
        return(0)
    return(max(f(nv) for nv in arc[v]) + 1)

n, m = map(int, input().split()) # 2 <= n <= 10^5, 1 <= m <= 10^5
arc = [[] for _ in range(n + 1)]
for i in range(m):
    x, y = map(int, input().split())
    arc[x].append(y)
print(max(f(v + 1) for v in range(n)))
Problem p03170 (python)

Fixed submission:
# coding: utf-8

import sys
input = sys.stdin.readline

def f(N, A, K):
    dp = [0] * (K + 1)
    for i in range(K + 1):
        for x in A:
            if i < x:
                break
            if not dp[i - x]:
                dp[i] = 1
                break
    return(dp[K])

ans = [ "Second", "First" ]
n, k = map(int, input().split()) # 1 <= n <= 100, 1 <= k <= 10^5
a = list(map(int, input().split()))
print(ans[f(n, a, k)])

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import sys
input = sys.stdin.readline

def f(N, A, K):
    dp = [0] * (K + 1)
    mina = min(A)
    minmax = mina + max(A)
    for i in range(mina, minmax):
        for x in A:
            i_ = i - x
            dp[i] = 1 if i_ < mina else dp[i_] ^ 1
            if dp[i]:
                break
    for i in range(minmax, K + 1):
        for x in A:
            dp[i] = dp[i - x] ^ 1
            if dp[i]:
                break
    return(dp[K])

ans = [ "Second", "First" ]
n, k = map(int, input().split()) # 1 <= n <= 100, 1 <= k <= 10^5
a = list(map(int, input().split()))
print(ans[f(n, a, k)])
Problem p03171 (python)

Fixed submission:
# coding: utf-8

import sys
input = sys.stdin.readline

def f(n, a):
    dp = [[0] * n for _ in range(n)]
    # dp[i][i] を a[i] で初期化
    for i in range(n):
        dp[i][i] = a[i]
    for i in range(n - 2, -1, -1):
        dpi = dp[i]
        dpi1 = dp[i + 1]
        for j in range(i + 1, n):
            r = a[i] - dpi1[j]
            l = a[j] - dpi[j - 1]
            dp[i][j] = r if r > l else l
            # dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
    return(dp[0][-1])

n = int(input()) # 1 <= n <= 3000
a = list(map(int, input().split()))
print(f(n, a))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from functools import lru_cache
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

@lru_cache(maxsize = None)
def f2(i, j, a):
    if i == j:
        return(a[i])
    return(max(a[i] - f2(i + 1, j, a), a[j] - f2(i, j - 1, a)))

n = int(input()) # 1 <= n <= 3000
a = list(map(int, input().split()))
print(f2(0, n - 1, a))
Problem p03172 (python)

Fixed submission:
# coding: utf-8

from itertools import accumulate as accum
import sys
input = sys.stdin.readline

def f(n, k, ai):
    mod = int(1e9 + 7)
    dp = [0] * (k + 1)
    dp[0] = 1
    for a in ai:
        # csum: Cumulative sum
        # dp[j] = dp[0] + dp[1] + ... + dp[j]
        # dp = list(accum(dp, lambda x, y: (x + y) % mod))
        dp = list(accum(dp))
        # j = 0 ～ a[i] までは累積和の結果そのままで a[i] + 1 以降は
        # dp[j] -= dp[j] - dp[j - a[i] - 1]
        dp[a + 1:] = [x - y for x, y in zip(dp[a + 1:], dp)]
        dp = [x % mod for x in dp]
    return(dp[k])

n, k = map(int, input().split()) # 1 <= n <= 100, 0 <= k <= 10^5
a = list(map(int, input().split()))
print(f(n, k, a))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def f2(n):

    dp = [[0] * n for _ in range(n)]
    s = [1] * n

    def dfs(i, j):  # from i to j
        dpi = dp[i]
        if dpi[j]:
            return(dpi[j])
        dpij = 1
        for u in U[i]:
            if u != j:
                dpij = dpij * (dfs(u, i) + 1) % M
        s[j] = s[j] * (dpij + 1) % M
        dpi[j] = dpij
        return(dpij)

    for i in range(n):
        for u in U[i]:
            dfs(u, i)
    print("\n".join([str(x) for x in s]))

N, M = map(int, input().split()) # 1 <= N <= 10^5, 2 <= M <= 10^9
U = [set() for _ in range(N)]
for x, y in [map(int, input().split()) for _ in range(N - 1)]:
    U[x - 1].add(y - 1)
    U[y - 1].add(x - 1)
f2(N)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def f2(n):

    dp = [[0] * n for _ in range(n)]
    s = [1] * n

    def dfs(i, j):  # from i to j
        dpi = dp[i]
        if dpi[j]:
            return(dpi[j])
        dpij = 1
        for u in U[i]:
            if u != j:
                dpij = dpij * (dfs(u, i) + 1) % M
        s[j] = s[j] * (dpij + 1) % M
        dpi[j] = dpij
        return(dpij)

    for i in range(n):
        for u in U[i]:
            dfs(u, i)
    print("\n".join([str(x) for x in s]))

N, M = map(int, input().split()) # 1 <= N <= 10^5, 2 <= M <= 10^9
U = [set() for _ in range(N)]
for x, y in [map(int, input().split()) for _ in range(N - 1)]:
    U[x - 1].add(y - 1)
    U[y - 1].add(x - 1)
f2(N)
Problem p03176 (python)

Fixed submission:
# coding: utf-8

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

powof2 = lambda x: len("{:b}".format(x))

def f2(n, h, a):
    p = powof2(n)
    N = 2 ** p
    segt = [0] * (2 * N - 1)

    def getmax(a, b, i = 0, l = 0, r = N - 1):
        if r <= a or b <= l:
            return(0)
        if a <= l and r <= b:
            return(segt[i])
        i1 = 2 * i + 1
        i2 = i1 + 1
        lr = (l + r) // 2
        lmax = getmax(a, b, i1, l, lr)
        rmax = getmax(a, b, i2, lr, r)
        return(lmax if lmax > rmax else rmax)

    def setmax(i, v):
        si = i + N - 1
        segt[si] = v
        while si > 0:
            si = (si - 1) // 2
            si1 = 2 * si + 1
            si2 = si1 + 1
            segt[si] = segt[si1] if segt[si1] > segt[si2] else segt[si2]

    for i in range(1, n + 1):
        m = getmax(0, h[i])
        setmax(h[i], m + a[i])

    return(getmax(0, n))

n = int(input()) # 1 <= n <= 2 x 10^5
h = [0] + list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
print(f2(n, h, a))

Buggy submission (verdict: Runtime Error):
# coding: utf-8

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

powof2 = lambda x: len("{:b}".format(x))

def f2(n, h, a):
    p = powof2(n)
    N = 2 ** p
    segt = [0] * (2 * N - 1)

    def getmax(a, b, i = 0, l = 0, r = N - 1):
        if r <= a or b <= l:
            return(0)
        if a <= l and r <= b:
            return(segt[i])
        lmax = getmax(a, b, 2 * i + 1, l, (l + r) // 2)
        rmax = getmax(a, b, 2 * i + 2, (l + r) // 2, r)
        return(lmax if lmax > rmax else rmax)

    def setmax(i, v):
        si = i + N - 1
        segt[si] = v
        while si > 0:
            si = (si - 1) // 2
            si1 = 2 * si + 1
            si2 += 1
            segt[si] = segt[si1] if segt[si1] > segt[si2] else segt[si2]

    for i in range(1, n + 1):
        m = getmax(0, h[i])
        setmax(h[i], m + a[i])

    return(getmax(0, n))

n = int(input()) # 1 <= n <= 2 x 10^5
h = [0] + list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
print(f2(n, h, a))