Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for _ in range(2)]
M = 1000000007

if S[0][0] == S[1][0]:
    last_kind = 0
    ans = 3
else:
    last_kind = 1
    ans = 6
i = 1
while i < N:
    if last_kind == 0 and S[0][i] == S[1][i]:
        ans *= 2
        last_kind = 0
        i += 1
    elif last_kind == 0 and S[0][i] == S[0][i+1]:
        ans *= 2
        last_kind = 1
        i += 2
    elif last_kind == 1 and S[0][i] == S[1][i]:
        last_kind = 0
        i += 1
    elif last_kind == 1 and S[0][i] == S[0][i+1]:
        ans *= 3
        last_kind = 1
        i += 2
    print(i, ans)
    ans %= M

print(ans)


Fixed submission:
N = int(input())
S = [input() for _ in range(2)]
M = 1000000007

if S[0][0] == S[1][0]:
    last_kind = 0
    ans = 3
    i = 1
else:
    last_kind = 1
    ans = 6
    i = 2
while i < N:
    if last_kind == 0 and S[0][i] == S[1][i]:
        ans *= 2
        last_kind = 0
        i += 1
    elif last_kind == 1 and S[0][i] == S[1][i]:
        last_kind = 0
        i += 1
    elif last_kind == 0 and S[0][i] == S[0][i+1]:
        ans *= 2
        last_kind = 1
        i += 2
    elif last_kind == 1 and S[0][i] == S[0][i+1]:
        ans *= 3
        last_kind = 1
        i += 2
    ans %= M

print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = [input() for _ in range(2)]
M = 1000000007

if S[0][0] == S[1][0]:
    last_kind = 0
    ans = 3
else:
    last_kind = 1
    ans = 6
for i in range(1, N):
    if last_kind == 0 and S[0][i] == S[1][i]:
        ans *= 2
        last_kind = 0
    elif last_kind == 0 and S[0][i] == S[0][i+1]:
        ans *= 2
        last_kind = 1
    elif last_kind == 1 and S[0][i] == S[1][i]:
        last_kind = 0
    elif last_kind == 1 and S[0][i] == S[0][i+1]:
        ans *= 3
        last_kind = 1
    ans %= M

print(ans)


Fixed submission:
N = int(input())
S = [input() for _ in range(2)]
M = 1000000007

if S[0][0] == S[1][0]:
    last_kind = 0
    ans = 3
    i = 1
else:
    last_kind = 1
    ans = 6
    i = 2
while i < N:
    if last_kind == 0 and S[0][i] == S[1][i]:
        ans *= 2
        last_kind = 0
        i += 1
    elif last_kind == 1 and S[0][i] == S[1][i]:
        last_kind = 0
        i += 1
    elif last_kind == 0 and S[0][i] == S[0][i+1]:
        ans *= 2
        last_kind = 1
        i += 2
    elif last_kind == 1 and S[0][i] == S[0][i+1]:
        ans *= 3
        last_kind = 1
        i += 2
    ans %= M

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = map(int, input().split())


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(d[x]+d[y])


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = map(int, input().split())


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(d[x]+d[y])

Buggy python submission (verdict: Runtime Error):
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = map(int, input().split())


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(d[x]+d[y])


Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N = int(input())
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a, b, c = map(int, input().split())
    G[a].append((b, c))
    G[b].append((a, c))
Q, K = map(int, input().split())


d = [-1]*(N+1)


def dfs(v, c):
    d[v] = c
    for nv, cost in G[v]:
        if d[nv] == -1:
            dfs(nv, cost+c)

dfs(K, 0)

for _ in range(Q):
    x, y = map(int, input().split())
    print(d[x]+d[y])
Buggy python submission (verdict: Runtime Error):
import math.factorial as F
N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
mod = 10**9+7

if M-N > 1:
    print(0)
elif M-N == 1:
    print(F(M)*F(N) % mod)
else:
    print(F(M)**2*2 % mod)


Fixed submission:
N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
mod = 10**9+7

g1 = [1, 1]
for i in range(2, M+1):
    g1.append((g1[-1] * i) % mod)

if M-N > 1:
    print(0)
elif M-N == 1:
    print(g1[M]*g1[N] % mod)
else:
    print(g1[M]**2*2 % mod)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1

    if l != r:
        res = min(C[l], C[r]) - 1
    else:
        res = C[l]//2
    C[l] -= res
    C[r] -= res
    ans -= 2*res
print(ans)


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = len(C)
if (N-ans) % 2 == 1:
    ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1

    if l != r:
        res = min(C[l], C[r]) - 1
    else:
        res = C[l]//2
    C[l] -= res
    C[r] -= res
    ans -= 2*res
print(ans)


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = len(C)
if (N-ans) % 2 == 1:
    ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = N
l = 1
r = 10**5
while l != r or (l == r and C[l] > 1):
    while C[l] <= 1:
        l += 1
    while C[r] <= 1:
        r -= 1
    C[l] -= 1
    C[r] -= 1
    ans -= 2
print(ans)


Fixed submission:
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = len(C)
if (N-ans) % 2 == 1:
    ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
sys.setrecursionlimit(1000000)
N, K, L = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(K)]
rs = [list(map(int, input().split())) for _ in range(L)]

G_r = [[] for _ in range(N+1)]
for elem in pq:
    G_r[elem[0]].append(elem[1])
    G_r[elem[1]].append(elem[0])
G_t = [[] for _ in range(N+1)]
for elem in rs:
    G_t[elem[0]].append(elem[1])
    G_t[elem[1]].append(elem[0])


field_r = [[] for _ in range(N+1)]


def dfs_r(i):
    q = deque()
    q.append(i)
    field_r[i].append(i)
    while q:
        tmp = q.pop()
        for pos in G_r[tmp]:
            if pos not in field_r[i]:
                field_r[i].append(pos)
                q.append(pos)
            else:
                continue
for i in range(1, N+1):
    if not field_r[i]:
        dfs_r(i)

field_t = [[] for _ in range(N+1)]
cnt = [1 for _ in range(N+1)]


def dfs_t(i):
    q = deque()
    q.append(i)
    field_t[i].append(i)
    while q:
        tmp = q.pop()
        for pos in G_t[tmp]:
            if pos not in field_t[i]:
                field_t[i].append(pos)
                if pos in field_r[i]:
                    cnt[i] += 1
                q.append(pos)
            else:
                continue
for i in range(1, N+1):
    if not field_t[i]:
        dfs_t(i)

ans = []
for i in range(1, N+1):
    ans.append(cnt[i])
print(' '.join(map(str, ans)))


Fixed submission:
import sys
from collections import deque, Counter
sys.setrecursionlimit(1000000)
N, K, L = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(K)]
rs = [list(map(int, input().split())) for _ in range(L)]

G_r = [[] for _ in range(N+1)]
for elem in pq:
    G_r[elem[0]].append(elem[1])
    G_r[elem[1]].append(elem[0])
G_t = [[] for _ in range(N+1)]
for elem in rs:
    G_t[elem[0]].append(elem[1])
    G_t[elem[1]].append(elem[0])


field_r = [None]*(N+1)


def dfs_r(i, idx):
    q = deque()
    q.append(i)
    field_r[i] = idx
    while q:
        tmp = q.pop()
        for pos in G_r[tmp]:
            if field_r[pos] is None:
                field_r[pos] = idx
                q.append(pos)
            else:
                continue
idx = 0
for i in range(1, N+1):
    if field_r[i] is None:
        dfs_r(i, idx)
        idx += 1


field_t = [None]*(N+1)


def dfs_t(i, idx):
    q = deque()
    q.append(i)
    field_t[i] = idx
    while q:
        tmp = q.pop()
        for pos in G_t[tmp]:
            if field_t[pos] is None:
                field_t[pos] = idx
                q.append(pos)
            else:
                continue
idx = 0
for i in range(1, N+1):
    if field_t[i] is None:
        dfs_t(i, idx)
        idx += 1

m = list(zip(field_r[1:], field_t[1:]))
cnt = Counter(m)
ans = []
for elem in list(m):
    ans.append(cnt[elem])
print(' '.join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input.split())

a *= 3

print((a+b)//2)

Fixed submission:
a, b = map(int, input().split())
a *= 3
print((a+b)//2)
Buggy python submission (verdict: Runtime Error):
S=int(input())
ans=[0]*(S+1)
MOD=10**9+7

if S<=2:
    print(0)
    exit(0)

ans[3]=1
for i in range(4,S+1):
    ans[i]=ans[i-1]+ans[i-3]

print(ans[i]%MOD)

Fixed submission:
S=int(input())
ans=[0]*(S+1)
MOD=10**9+7

if S<=2:
    print(0)
    exit(0)
elif S==3:
    print(1)
    exit(0)   
ans[3]=1
for i in range(4,S+1):
    ans[i]=ans[i-1]+ans[i-3]

print(ans[i]%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=[list(map(int, input().split()))  for _ in range(N)]
maxd=0
for i in range(N):
    for j in range(i+1,N):
        maxd=max(maxd,abs(A[i][0]-A[j][0])+abs(A[i][1]-A[j][1]))

print(maxd)

Fixed submission:
N=int(input())
A=[]
B=[]
for _ in range(N):
    x,y=map(int, input().split())
    A.append(x+y)
    B.append(x-y)

A=sorted(A)
B=sorted(B)

print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int, input().split()))]

temp1=cp.deepcopy(A[0])
temp2=cp.deepcopy(A[0])
for i in range(N-1):
    f=0
    x,y=map(int, input().split())
    if abs(temp1[0]-x)+abs(temp1[1]-y):
        temp2[0]=x
        temp2[1]=y
        f=1
    if f==1:
        for i,j in A:
           if max(abs(temp2[0]-i)+abs(temp2[1]-j),abs(temp2[0]-temp1[0])+abs(temp2[1]-temp1[1])):
               temp1[0]=i
               temp2[1]=j
    A.append([x,y])


print(abs(temp2[0]-temp1[0])+abs(temp2[1]-temp1[1]))

Fixed submission:
N=int(input())
A=[]
B=[]
for _ in range(N):
    x,y=map(int, input().split())
    A.append(x+y)
    B.append(x-y)

A=sorted(A)
B=sorted(B)

print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))
Buggy python submission (verdict: Runtime Error):
D,T,S=map(int, input().split())

if S*T>=D:
    print('Yes')
else:
    Print('No')

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

if S*T>=D:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K=int(input())

if K%2==0:
    print(-1)
    exit(0)
mod=7
for i in range(1,pow(10,6)):
    mod=mod%K
    if mod==0:
        print(i)
        exit(0)
    mod+=7*pow(10,i)
    #print(i,mod)


print(-1)

Fixed submission:
K=int(input())

if K%2==0:
    print(-1)
    exit(0)
    
ans=[0]*(pow(10,6)+1)
ans[0]=0

for i in range(1,pow(10,6)):
    ans[i]=(ans[i-1]*10+7)%K
    if ans[i]==0:
        print(i)
        exit(0)

print(-1)
Buggy python submission (verdict: Runtime Error):
import numpy as np

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R':
        j-=1
    if i>=n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)

Fixed submission:
import numpy as np

N=int(input())
c=np.array(list(input()))
n=np.count_nonzero(c == 'R')
i=0
j=N-1
cnt=0
if N==n:
    print(cnt)
    exit(0)
while 1:
    while c[i]!='W' and i<n:
        i+=1
    while c[j]!='R' and j>n-1:
        j-=1
    if i>=n or j<n:
        print(cnt)
        exit(0)
    temp=c[i]
    c[i]=c[j]
    c[j]=temp
    cnt+=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int, input().split())
A=list(map(int, input().split()))

ans=A[0]
for i in range(1,K):
   ans*=A[i]


for i in range(K,N):
    preans=ans
    ans=ans//A[i-K]*A[i]
    if ans>preans:
        print('Yes')
    else:
        print('No')


Fixed submission:
import numpy as np

N,K=map(int, input().split())
A=np.array(list(map(int, input().split())))

for i in range(K,N):
    if A[i]/A[i-K]>1:
        print('Yes')
    else:
        print('No')

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

ans=A[0]
for i in range(1,K):
   ans*=A[i]


for i in range(K,N):
    preans=ans
    ans=ans//A[i-K]*A[i]
    if ans>preans:
        print('Yes')
    else:
        print('No')


Fixed submission:
import numpy as np

N,K=map(int, input().split())
A=np.array(list(map(int, input().split())))

for i in range(K,N):
    if A[i]/A[i-K]>1:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N,M,K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

sumA, sumB = [0], [0]
for i in range(N):
    sumA.append(sumA[i] + A[i])
for i in range(M):
    sumB.append(sumB[i] + B[i])

#print(sumA)
    
#sumA = list(itertools.accumulate(A))
#sumB = list(itertools.accumulate(B))
ans=0
j=M
for i in range(N+1):
    if sumA[i]>K:
        break
    #j-=1
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    if i==0:
        best=j
    ans=max(ans,i+j)
    j=best
print(ans)

Fixed submission:
import itertools

N,M,K=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

sumA = list(itertools.accumulate(A))
sumB = list(itertools.accumulate(B))
j=M-1
while K<sumB[j] and j>=0:
    j-=1
ans=j+1
for i in range(N):
    if sumA[i]>K:
        break
    while K<sumA[i]+sumB[j] and j>=0:
        j-=1
    ans=max(ans,i+j+2)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
ans=0
A=[0]*(N+1)
for i in range(1,N+1):
    for j in range(i,N+1,i):
        A[j]+=j
print(sum(A))

Fixed submission:
N=int(input())
ans=0
A=[0]*(N+1)
for i in range(1,N+1):
    for j in range(i,N+1,i):
        A[j]+=j
print(sum(A))
Buggy python submission (verdict: Runtime Error):
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())

if W>=V and A!=B:
    print('NO')
    exit(0)

if A*B<0:
    if (abs(A)+abs(B))//(V-W)<=T:
        print('YES')
    else:
        print('NO')
else
    if abs(abs(A)-abs(B))//(V-W)<=T:
        print('YES')
    else:
        print('NO')

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

if W>=V:
    print('NO')
    exit(0)

if A*B<0:
    if (abs(A)+abs(B))/(V-W)<=T:
        print('YES')
    else:
        print('NO')
else:
    if abs(abs(A)-abs(B))/(V-W)<=T:
        print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Runtime Error):
A=input()
if A='ABC':
  print('ARC')
else:
  print('ABC')

Fixed submission:
A=input()
if A=='ABC':
  print('ARC')
else:
  print('ABC')
Buggy python submission (verdict: Runtime Error):
import math
X=int(input())

for i in range(X+1):
  #print(pow(X-pow(i,5),1/5),i)
  if pow(X-pow(i,5),1/5)%1==0:
    break
print(int(pow(X-pow(i,5),1/5)),-i)

Fixed submission:
import math
X=int(input())
c=0
for i in range(200):   
  for j in range(-200,200):
    if i**5-j**5==X:
      c=1
      break
      
  if c==1:
    break
      
print(i,j)

Buggy python submission (verdict: Runtime Error):
import math
X=int(input())

for i in range(X+1):
  print(pow(X-pow(i,5),1/5),i)
  if pow(X-pow(i,5),1/5)%1==0:
    break
print(int(pow(X-pow(i,5),1/5)),-i)

Fixed submission:
import math
X=int(input())
c=0
for i in range(200):   
  for j in range(-200,200):
    if i**5-j**5==X:
      c=1
      break
      
  if c==1:
    break
      
print(i,j)

Buggy python submission (verdict: Runtime Error):
import math
X=int(input())

for i in range(X):
  if　isinstance(pow(1/5, X+pow(5,i)), int)=='true'
    break
    
print(pow(1/5, X+pow(5,i),i)

Fixed submission:
import math
X=int(input())
c=0
for i in range(200):   
  for j in range(-200,200):
    if i**5-j**5==X:
      c=1
      break
      
  if c==1:
    break
      
print(i,j)
Buggy python submission (verdict: Time Limit Exceeded):
import math

A,B,N=map(int, input().split())
a=0
b=0
for i in range(max(N-B+1,1),N+1):
    a=i%B
    if b<a:
        b=a
c=math.floor(A*b/B)-A*math.floor(b/B)
print(c)

Fixed submission:
import math

A,B,N=map(int, input().split())

b=0

if N>=B:
  b=B-1
else:
  b=N

c=math.floor(A*b/B)-A*math.floor(b/B)
print(c)
Buggy python submission (verdict: Runtime Error):
import math

K=int(input())
S=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      S+=gcd(gcd(i,j),k)

print(S)

Fixed submission:
from math import gcd 

K=int(input())
S=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      S+=gcd(gcd(i,j),k)

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

K=int(input())
S=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      S+=gcd(i,j,k)

print(S)

Fixed submission:
from math import gcd 

K=int(input())
S=0

for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      S+=gcd(gcd(i,j),k)

print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    for k in range(j+1,N):
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a[0]*a[1]*a[2]-a[3])

Fixed submission:
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k>=N:
      break
    else:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a[0]*a[1]*a[2]-a[3])
Buggy python submission (verdict: Runtime Error):
s=input()
if s='hi' or s='hihi' or s='hihihi' or s='hihihihi' or s='hihihihihi':
  print(Yes)
else:
  print(No)

Fixed submission:
s=input()
if s=='hi' or s=='hihi' or s=='hihihi' or s=='hihihihi' or s=='hihihihihi':
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
A,B,M = map(int, input().split())

a=list(map(int, input().split()))
b=list(map(int, input().split()))
dis=[list(map(int,input().split()))  for l in range(M)]


comp1=a[dis[0][0]-1]+a[dis[0][0]-1]-dis[0][2]
for l in range(M):
    y=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]
    if comp1>y:
        comp1=y

comp2=int(a[0]+b[0])
for l in range(A):
    for m in range(B):
        x=int(a[l]+b[m])
        if comp2>x:
            comp2=x
                  
print(min(comp1,comp2))

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

a=list(map(int, input().split()))
b=list(map(int, input().split()))
dis=[list(map(int,input().split()))  for l in range(M)]

comp1=a[dis[0][0]-1]+b[dis[0][1]-1]-dis[0][2]
for l in range(M):
    y=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]
    if comp1>y:
        comp1=y

comp2=min(a)+min(b)
                  
print(min(comp1,comp2))

Buggy python submission (verdict: Time Limit Exceeded):
A,B,M = map(int, input().split())

a=list(map(int, input().split()))
b=list(map(int, input().split()))
dis=[list(map(int,input().split()))  for l in range(M)]

comp1=[0]*M

for l in range(M):
    comp1[l]=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]

comp2=int(a[0]+b[0])
for l in range(A):
    for m in range(B):
        x=int(a[l]+b[m])
        if comp2>=x:
            comp2=x
          
comp3=min(comp1)         
print(min(comp3,comp2))

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

a=list(map(int, input().split()))
b=list(map(int, input().split()))
dis=[list(map(int,input().split()))  for l in range(M)]

comp1=a[dis[0][0]-1]+b[dis[0][1]-1]-dis[0][2]
for l in range(M):
    y=a[dis[l][0]-1]+b[(dis[l][1])-1]-dis[l][2]
    if comp1>y:
        comp1=y

comp2=min(a)+min(b)
                  
print(min(comp1,comp2))
Buggy python submission (verdict: Runtime Error):
i=input()
j=i[0]
k=0

for n in range(2):
  if i[n+1]!=j:
	print('Yes')
	k=1
  
if k=0:
  print('No')

Fixed submission:
i=input()
j=i[0]
k=0

for n in range(2):
	if i[n+1]!=i[0]:
		k=1
if k==0:
	print('No')
else:
	print('Yes')
Buggy python submission (verdict: Runtime Error):
k=N%2
if k==0:
    print(round(N/2.0))
else:
    print(round(N/2+1/2.0))

Fixed submission:
n=input()
N=float(n)
k=N%2
if k==0:
    print(round(N/2.0))
else:
    print(round(N/2+1/2.0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = []
y = []

for i in range(n):
    a = int(input())
    x.append([])
    y.append([])
    for j in range(a):
        u, v = map(int, input().split())
        x[i].append(u)
        y[i].append(v)
ans = 0
for i in range(2 ** n):
    jdg = [False] * n
    used = [False] * n
    end = False
    for j in range(n):
        if ((i >> j) & 1):
            jdg[j] = True
    for j in range(n):
        for k in range(n):
            if ((not jdg[k]) or used[k]):
                continue
            used[k] = True
            for l in range(len(x[k])):
                if (y[k][l] == 1):
                    jdg[x[k][l] - 1] = True
                elif (jdg[x[k][l] - 1]):
                    end = True
                    break
            if (end):
                break
        if (end):
            break
    if (end):
        continue
    ans = max(sum(jdg), ans)

print(ans)


Fixed submission:
a = [int(i) for i in input().split()]

print('bust' if sum(a) > 21 else 'win')
Buggy python submission (verdict: Runtime Error):
[l, r] = [int(i) for i in input().split()]

if (r - l >= 672):
    print(0)
else:
    a = 2018
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            a = min(a, ((i % 2019) * (j % 2019)) % 2019)

print(a)


Fixed submission:
[l, r] = [int(i) for i in input().split()]

if (r - l >= 673):
    print(0)
else:
    a = 2018
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            b = i % 2019
            c = j % 2019
            d = (b * c) % 2019
            a = min(a, d)
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
[n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

for i in range(m):
    [b, c] = [int(i) for i in input().split()]
    a += [c for i in range(b)]

a.sort(reverse=True)
print(sum(a[:n]))


Fixed submission:
[n, m] = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l = [[int(j) for j in input().split()] for i in range(m)]
l.sort(reverse=True, key=lambda x:x[1])

k = []
for i in l:
    k += [i[1]] * i[0]
    if (len(k) >= n):
        break

k += a
k.sort(reverse = True)
print(sum(k[:n]))