Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
antenna = []
for i in range(5):
  antenna.append(int(input()))
K = int(input())

d = True
for i in range(5):
  if d:
  for j in range(i,5):
    if antenna[j]-antenna[i] > K:
      print(':(')
      d = False
      break
if d:
  print('Yay!')

Fixed submission:
antenna = [int(input()) for i in range(5)]
k = int(input())
judge = ''
i,j = 1,1
for i in range(5):
  for j in range(i+1,5):
    if abs(antenna[i]-antenna[j]) > k:
      judge = ':('
      break

if judge==':(':
  print(':(')
else:
  print('Yay!')
Buggy python submission (verdict: Runtime Error):
A = list(map(int, open(0).read().split()))

last_order = A[min([(x%10, i) for i,x in enumerate(A) if x%10!=0])[1]]
import numpy as np
print(sum(A) + sum(10 - np.array([x%10 for x in A if x%10!=0])) - (10 - min([x%10 for x in A if x%10!=0])))

Fixed submission:
import math
cookT = {}
lastOrder = 0

for i in range(5):
  cookT[i] = int(input())
  
lastOrder = max(cookT.items(), key=lambda x:(10-x[1]%10)%10)[0]

totalT = 0
for i in range(5):
  if i == lastOrder:
    totalT += cookT[lastOrder]
  else:
    tempX = cookT[i]
    tempY = math.ceil(tempX%10 / 10)*10
    totalT += tempX//10 *10 + tempY
print(totalT)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q, S, *_LR = open(0).read().split()
N = int(N)
Q = int(Q)
LR = list(zip(*[map(int, iter(_LR))]*2))

AC = []

for i in range(1, N):
    if S[i-1: i+1] == "AC":
        AC.append(1)
    else:
        AC.append(0)
        
for L,R in LR:
    print(sum(AC[L-1: R-1]))

Fixed submission:
N, Q, S, *_LR = open(0).read().split()
N = int(N)
Q = int(Q)
LR = list(zip(*[map(int, iter(_LR))]*2))

AC = [0]*(N)

for i in range(1, N):
    if S[i-1] == "A":
        if S[i] == "C":
            is_AC = 1
        else:
            is_AC = 0
    else:
        is_AC = 0

    if i == 1:
        AC[i] = is_AC
    else:
        AC[i] = AC[i-1] + is_AC
        
for L,R in LR:
    print(AC[R-1] - AC[L-1])
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

def cf(x1,x2):
    cf=[]
    
    if 1 in [x1, x2]:
        cf.append(1)
    else:
        count = 0
        for i in range(2,min(x1,x2)+1):
            if count== K:
                break
            else:
                if x1 % i == 0 and x2 % i == 0:
                    cf.append(i)
            count += 1
    return cf

print(cf(A, B)[-1])

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

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

print(sorted(list(set(divisor(A)) & set(divisor(B))), reverse=True)[K-1])
Buggy python submission (verdict: Runtime Error):
D, N = map(int, input().split())

print([100 ** D * i for i in range(101) if i%100 != 0][N-1])

Fixed submission:
D, N = map(int, input().split())
print([100 ** D * i for i in range(102) if i%100 != 0][N-1])
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

L = list(range(A, B+1))
ans = set(L[:K] + L[-K:])
print(*sorted(ans), sep="\n")

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

L = list(range(A, min(B, A+K))) + list(range(max(A, B-K+1), B+1))
L_no_duplication = set(L)
print(*sorted(L_no_duplication), sep="\n")

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

L = list(range(A, B+1))
ans = L[:K] or L[-K:]
print(*ans, sep="\n")

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

L = list(range(A, min(B, A+K))) + list(range(max(A, B-K+1), B+1))
L_no_duplication = set(L)
print(*sorted(L_no_duplication), sep="\n")

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

L = list(range(A, B+1))
ans = L[:K] + L[-K:]
print(*ans, sep="\n")

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

L = list(range(A, min(B, A+K))) + list(range(max(A, B-K+1), B+1))
L_no_duplication = set(L)
print(*sorted(L_no_duplication), sep="\n")
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int, input().split())

count = 0

for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X+Y+Z == S:
        count += 1
  
print(count)

Fixed submission:
K,S = map(int, input().split())

count = 0

for X in range(K+1):
  for Y in range(K+1):
    Z = S-(X+Y)
    if 0<=Z and Z<=K:
      count += 1
  
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int, input().split())

count = 0

for X in range(K+1):
  for Y in range(K+1):
    for Z in range(K+1):
      if X+Y+Z == S:
        count += 1
  
print(count)

Fixed submission:
K,S = map(int, input().split())

count = 0

for X in range(K+1):
  for Y in range(K+1):
    Z = S-(X+Y)
    if 0<=Z and Z<=K:
      count += 1
  
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def get_primes(n):
    root_n = int(n ** 0.5)
    is_prime = [True] * (n + 1)
    is_prime[0], is_prime[1] = False, False
    for i in range(2, root_n + 1):
        if not is_prime[i]:
            continue
        # i の倍数の素数判定をFalseにする
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


def a(n):
    return 7 * (1 + ((10**n - 10) // 9))


INF = float('inf')


k = I()
if k % 2 == 0:
    print(-1)
    exit()

ans = 1
while True:
    if a(ans) % k == 0:
        break
    ans += 1
print(ans)


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


k = I()
ans = -1
a = [0] * (k+1)
a[1] = 7 % k
for i in range(2, k+1):
    a[i] = (a[i-1]*10 + 7) % k

for i in range(1, k+1):
    if a[i] == 0:
        print(i)
        exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def rle(s):
    t = s[0]
    cnt = 1
    res = []
    for i in range(1, len(s)):
        if t == s[i]:
            cnt += 1
        else:
            res.append([t, cnt])
            t = s[i]
            cnt = 1
    res.append([t, cnt])
    return res


INF = float('inf')


n = I()
c = S()
if len(set(list(c))) < 2:
    print(0)
    exit()

# R と W のまとまり
rw = rle(c)
# print(rw)
ans = 0
for i, elem in enumerate(rw):
    if i < n - 1 and elem[0] == 'W' and rw[i+1][0] == 'R':
        ans += min(elem[1], rw[i+1][1])
print(ans)


Fixed submission:
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
c = S()
# 最終的に RR...RWW...WWW という状態になる
# R の個数を r とすると、左から r 個の石のうち R はそのままで W だけ入れ替えたら良い
r = Counter(list(c))['R']
ans = 0
for elem in c[:r]:
    if elem == 'W':
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
import sys

INF = float('inf')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


n = I()
a = LI()
ans = 1
for ai in a:
    ans *= ai
    if ans > 10 ** 18:
        ans = -1
print(ans)


Fixed submission:
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())


n = I()
a = LI()
ans = a[0]
if 0 in a:
    print(0)
    sys.exit()

for ai in a[1:]:
    ans *= ai
    if ans > 10 ** 18:
        ans = -1
        break

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def bfs(n, g, start):
    d = [INF] * n
    que = deque([start])
    d[start] = 0
    while que:
        now = que.popleft()
        for next in g[now]:
            if d[next] != INF:
                continue
            que.append(next)
            d[next] = d[now] + 1
    return d


def main():
    n, x, y = LI()
    edges = defaultdict(list)
    edges[x - 1].append(y - 1)
    edges[y - 1].append(x - 1)
    for i in range(n - 1):
        edges[i].append(i + 1)
        edges[i + 1].append(i)
    ans = [0] * (n - 1)
    for i in range(n):
        d = bfs(n, edges, i)
        for k in range(1, n):
            ans[k - 1] += len([j for j in d if j == k])
    ans = list(map(lambda x: x//2, ans))
    print(*ans, sep='\n')


main()


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


def main():
    n, x, y = LI()
    x, y = x - 1, y - 1
    d = [[INF] * n for _ in range(n)]
    ans = [0] * n
    for i in range(n - 1):
        for j in range(i + 1, n):
            d[i][j] = min([j - i,
                           abs(x - i) + 1 + abs(j - y),
                           abs(y - i) + 1 + abs(j - x)])
            ans[int(d[i][j])] += 1
    print(*ans[1:], sep='\n')


main()
Buggy python submission (verdict: Runtime Error):
print(int(input())//2 + 1) if int(input()) % 2 else print(int(input())//2)


Fixed submission:
n = int(input())
if n%2 == 0: print(n//2)
else: print((n+1)//2)

Buggy python submission (verdict: Runtime Error):
print(int(input())//2 + 1) if n % 2 else print(int(input())//2)

Fixed submission:
n = int(input())
if n%2 == 0: print(n//2)
else: print((n+1)//2)
Buggy python submission (verdict: Runtime Error):
s = input()
ans = 'x' * len(s)
print(len(input()) * 'x')

Fixed submission:
s = input()
ans = 'x' * len(s)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    sump = 0
    ind = 0
    for i in range(n-k+1):
        for j in range(i, i+k):
            if sump < sum(p[i:i+k]):
                sump = sum(p[i:i+k])
                ind = i
    e = 0
    for i in range(ind, ind+k):
       e += (p[i]+1) / 2 
    print(e)
    
main()

Fixed submission:
def main():
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    ex = [0 for _ in range(n)]
    for i in range(n):
        ex[i] = (p[i]+1)/2
    
    sumex = sum(ex[:k])
    tmp = sum(ex[:k])
    for i in range(n-k):
        tmp = tmp + (ex[i+k] - ex[i])
        sumex = max(sumex, tmp)
    print(sumex)
    
main()
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=list(map(int, input().split()))
ans=1
for i in range(1,n):
  flag=True
  for j in range(i):
    if p[i] > p[j]:
      flag=False
      break
  if flag:
    ans+=1
print(ans)

Fixed submission:
n=int(input())
p=list(map(int, input().split()))

ans=1
minn=p[0]
for i in range(1,n):
  minn = min(p[i-1], minn)
  if minn >= p[i]: 
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
cnt=0
for a in range(1,n+1):
  for b in range(1, n+1):
    if str(a)[0]==str(b)[-1] and str(a)[-1]==str(b)[0]: cnt+=1
print(cnt)

Fixed submission:
n=int(input())
cnt=0
# c(i,j)={先頭がiで末尾がjであるkの個数}
c=[[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):
  l=int(str(i)[0])
  r=int(str(i)[-1])
  c[l][r]+=1
'''
for i in range(10):
  for j in range(10):
    print(c[i][j], end=' ')
  print('')
'''
sum=0
for i in range(1,10):
  for j in range(1,10):
    sum+=c[i][j]*c[j][i]
print(sum)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
ans = 1 if 1 not in (a, b) else 2 if not in (a, b) else 3
print(ans)

Fixed submission:
a, b = int(input()), int(input())
ans = 1 if 1 not in (a, b) else 2 if 2 not in (a, b) else 3
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
ans = 1 if 1 not in (a, b) else 2 if not in (a, b) else 3
print(ans)

Fixed submission:
a, b = int(input()), int(input())
ans = 1 if 1 not in (a, b) else 2 if 2 not in (a, b) else 3
print(ans)

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
ans = 1 if 1 not in (a, b) else 2 not in (a, b) else 3
print(ans)

Fixed submission:
a, b = int(input()), int(input())
ans = 1 if 1 not in (a, b) else 2 if 2 not in (a, b) else 3
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 5
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
s = S()
ciphers = [f'{i:03}' for i in range(1000)]
ans = 0
for v in ciphers:
    j = 0
    for i in range(n):
        if s[i] == v[j]:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)


Fixed submission:
# 5
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
s = S()
ciphers = [f'{i:03}' for i in range(1000)]
ans = 0
for v in ciphers:
    j = 0
    for i in range(n):
        if s[i] == v[j]:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
a, b, x = map(int, input().split())
ans =0
left = 0
right = 10**9+1

def dN(n):
  return len(str(n))

def cal_price(a, b, n):
  return a*n + b*dN(n)

while right - left > 1:
  mid = (left + right)//2
  if a*mid + b*dN(mid) > x: right = mid
  else: left = mid
    
print(left)

Fixed submission:
day = input()
days = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - days.index(day) if day != 'SAT' else 1)
Buggy python submission (verdict: Runtime Error):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
a = [0] * (n + 1)
for i in range(len(s)):
    if '<' == s[i]:
        a[i + 1] = a[i] + 1
for i in reversed(range(len(s))):
    if '>' == s[i]:
        a[i] = max(a[i], a[i + 1] + 1)
    print(a)
print(sum(a))


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
ans = 0
cnt = 0
before_cnt = 0
now = s[0]
for x in s:
    if now == x:  # 同じ不等号が連続しているとき
        cnt += 1
    else:  # 不等号が変わるとき
        ans += cnt * (cnt + 1) // 2
        if now == '>':  # > から < に変わるとき
            if before_cnt < cnt:
                ans -= before_cnt
            else:
                ans -= cnt

        before_cnt = cnt
        cnt = 1
        now = x

ans += cnt * (cnt + 1) // 2
if now == '>':
    if before_cnt < cnt:
        ans -= before_cnt
    else:
        ans -= cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
flag = False
a, b = 0
for i in range(2, 9):
    if(n % i): continue
    else: flag = True
if(flag and (n/i <= 9)): print('Yes')
else: print('No')


Fixed submission:
n = int(input())
ans = 'No'
for i in range(1, 10):
  if n % i == 0 and 1 <= n // i <= 9:
      ans = 'Yes'
      break
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))


# 条件を満たすかどうか
def is_ok(l, i, key):
    # ここが条件
    if l[i] >= key:
        return True


def binary_seach(l, key) -> int:
    left = -1
    right = len(l)

    while right - left > 1:
        mid = left + (right - left) // 2
        if is_ok(l, mid, key):
            right = mid
        else:
            left = mid

    return right


n = I()
l = LI()
l = sorted(l)
ans = 0
for i in range(n - 2):
    # 三角形のうち一番短い辺
    a = l[i]
    for j in range(i + 1, n - 1):
        # 三角形のうち二番目に短い辺
        b = l[j]
        # 三角形の中で一番大きい辺 かつ
        # a + b より小さい辺 を二分探索で探す
        # a + b 以上の要素の初めのindexを取得
        ind = binary_seach(l, a + b)
        # b 以上の辺のうち、a + b より小さい要素の数を足す
        ans += ind - j - 1
print(ans)


Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))


# 条件を満たすかどうか
def is_ok(l, i, key):
    # ここが条件
    if l[i] >= key:
        return True


def binary_seach(l, key) -> int:
    left = -1
    right = len(l)

    while right - left > 1:
        mid = left + (right - left) // 2
        if is_ok(l, mid, key):
            right = mid
        else:
            left = mid

    return right


n = I()
l = LI()
l = sorted(l)
ans = 0
for i in range(n - 2):
    # 三角形のうち一番短い辺
    a = l[i]
    for j in range(i + 1, n - 1):
        # 三角形のうち二番目に短い辺
        b = l[j]
        # 三角形の中で一番大きい辺 かつ
        # a + b より小さい辺 を二分探索で探す
        # a + b 以上の要素の初めのindexを取得
        ind = binary_seach(l, a + b)
        # b 以上の辺のうち、a + b より小さい要素の数を足す
        ans += ind - j - 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
#a = np.array(list(map(int, input().split())))
a = list(map(int, input().split()))

d = {a.index(i)+1: i for i in a}
#print(d)
d_sorted = sorted(d.items(), key=lambda x:x[1])
#print(d_sorted)
for i in d_sorted:
  print(i[0], end=' ')

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i in range(n):
  ans[a[i]-1] = i + 1
for i in ans:
  print(i, end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
#a = np.array(list(map(int, input().split())))
a = list(map(int, input().split()))

d = {a.index(i)+1: i for i in a}
#print(d)
d_sorted = sorted(d.items(), key=lambda x:x[1])
#print(d_sorted)
for i in d_sorted:
  print(i[0], end=' ')
'''
#sorted_a = np.sort(a)
#print(sorted_a)
print(a)
for i in range(n):
  #print(min(a))
  print((a.index(min(a)) + 1))
  a.remove(min(a))
  '''
  
'''
inds = [i for i in range(n)]
sorted_inds = sorted(inds)
print('sorted_inds={}'.format(sorted_inds))
sorted_a = [a[i] for i in sorted_inds]
for i in sorted_a:
  print(i, end=' ')
'''

Fixed submission:
import numpy as np
n = int(input())
a = list(map(int, input().split()))
ans = [0 for _ in range(n)]
for i in range(n):
  ans[a[i]-1] = i + 1
for i in ans:
  print(i, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
win = [0 for _ in range(n)]
p = np.array([k for _ in range(n)])
for ai in a:
  p -= 1
  p[ai-1] += 1
for pi in p:
  if pi<=0: print('No')
  else: print('Yes')

Fixed submission:
import numpy as np
n,k,q = map(int, input().split())
a = [int(input()) for i in range(q)]
#cnt = [0 for _ in range(n)]
win = [0 for _ in range(n)]
#p = np.array([k for _ in range(n)])
for ai in a:
  win[ai-1] += 1
#print(win)

for w in win:
  if k-q+w<=0: print('No')
  else: print('Yes')
Buggy python submission (verdict: Runtime Error):
2
1 2
50 50
50

Fixed submission:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
a = list(map(lambda x: x - 1, a))
b = LI()
c = LI()

ans = 0
for i in range(n):
    ans += b[a[i]]
    if i > 0 and a[i - 1] + 1 == a[i]:
        ans += c[a[i - 1]]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
l = []
cnt = 0
ans = 0
for i in reversed(range(1, n)):
  if h[i]<=h[i-1]:
    cnt += 1
  else:
    l.append(cnt)
    cnt = 0
ans = max(l)
print(ans)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
l = []
cnt = 0
ans = 0
for i in reversed(range(1, n)):
  if h[i]<=h[i-1]:
    cnt += 1
  else:
    l.append(cnt)
    cnt = 0
  if i==1:
    l.append(cnt)

if len(l)!=0: ans = max(l)
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
l = []
cnt = 0
for i in reversed(range(1, n)):
  if h[i]<=h[i-1]:
    cnt += 1
  else:
    l.append(cnt)
    cnt = 0
ans = max(l)
print(ans)

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
l = []
cnt = 0
ans = 0
for i in reversed(range(1, n)):
  if h[i]<=h[i-1]:
    cnt += 1
  else:
    l.append(cnt)
    cnt = 0
  if i==1:
    l.append(cnt)

if len(l)!=0: ans = max(l)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
n = int(input())
# アルファベットがキー、要素をカウント数の辞書にして比較する
s = [Counter(input()) for _ in range(n)]
#print(s)
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    #print('{} and {}'.format(s[i], s[j]))
    if s[i] == s[j]: cnt+=1
print(cnt)

Fixed submission:
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
d = {}
for i in range(n):
  sortsi = ''.join(sorted(s[i]))
  if sortsi in d:
    cnt+=d[sortsi]
    d[sortsi]+=1
  else: 
    d[sortsi]=1
print(cnt)