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

Fixed submission:
import sys
h,w,d = map(int, sys.stdin.readline().split())

x = [[0]*1600 for i in range(1600)]
for i in range(1600):
    for j in range(1600):
        a = i//d 
        b = j//d
        if (a%2 ==0 and b%2 == 0):
            x[i][j] = "R"
        elif (a%2 ==1 and b%2 == 0):
            x[i][j] = "Y"
        elif (a%2 ==1 and b%2 == 1):
            x[i][j] = "G"
        else:
            x[i][j] = "B"
for i in range(h):
    result = ""
    for j in range(w):
        result+= x[800+j-i][0+j+i] 
    print(result)

Buggy submission (verdict: Runtime Error):
import sys
h,w,d = map(int, sys.stdin.readline().split())
def ironuri(x,b,c):
    a = []
    if b-d >= 0:
        a.append(x[b-d][c])
    if c-d >= 0:
        a.append(x[b][c-d])
    nu = ["R","Y","G","B"]
    for ia in nu:
        if ia not in a:
            return ia
e = [[0] * w for i in range(h)]
for i in range(w):
    for j in range(h):
        if e[j][i] != 0:
            continue
        e[j][i] = "R"
        for k in range(w//d):
            for l in range(h//d):
                e[j+k*d][i+l*d] = ironuri(e,j+k*d,i+l*d) 
for i in e:
    print("".join(i))
Problem p03662 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2000000)
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p: 
    l[pi[0]].append([pi[0],pi[1]])
    l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    kyo[a[1]] = kyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    nkyo[a[1]] = nkyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(1,n+1):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")

Buggy submission (verdict: Runtime Error):
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
l = [[] for i in range(n+1)]
for pi in p: 
    l[pi[0]].append([pi[0],pi[1]])
    l[pi[1]].append([pi[1],pi[0]])
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    kyo[a[1]] = kyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(l[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[1]] == 1:
      continue
    nkyo[a[1]] = nkyo[a[0]] + 1
    dfs(a[1],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(1,n+1):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")

Buggy submission (verdict: Runtime Error):
n = int(input())
p = []
for i in range(n-1):
    p.append(list(map(int, input().split()))+ [1])
lw = [[] for i in range(n+1)]
for path in p:
    lw[path[0]].append((path[1],path[2]))
    lw[path[1]].append((path[0],path[2]))
kyo = [float("inf")]*(n+1)
kyo[1] = 0
memo = [0] * (n+1)
memo[1] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(lw[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[0]] == 1:
      continue
    kyo[a[0]] = kyo[start] + 1
    dfs(a[0],ruto)
  return
dfs(1,ruto)

nkyo = [float("inf")]*(n+1)
nkyo[n] = 0
memo = [0] * (n+1)
memo[n] = 1
ruto = []
def dfs(start,ruto):
  ruto.extend(lw[start])
  memo[start] = 1
  while ruto:
    a = ruto.pop()
    if memo[a[0]] == 1:
      continue
    nkyo[a[0]] = nkyo[start] + 1
    dfs(a[0],ruto)
  return
dfs(n,ruto)
iti = 0
nko = 0
for i in range(n):
  if kyo[i] <= nkyo[i]:
    iti += 1
  else:
    nko += 1
if iti <= nko:
  print("Snuke")
else:
  print("Fennec")
Problem p04014 (python)

Fixed submission:
import math
n = int(input())
s = int(input())
if n == s:
  print(n+1)
  exit()
ru = math.ceil(math.sqrt(n))+1
for i in range(2,ru+1):
  b = n+0
  a = 0
  while b:
    a +=b%i
    b//=i
  if s == a:
    print(i)
    exit()
for i in range(ru,0,-1):
  q = s-i
  if q <0:
    continue
  c = (n-q)// i
  if c <= ru-1:
    continue
  b = n+0
  a = 0
  while b:
    a+=b%c
    b//=c
  if a == s:
    print(c)
    exit()
print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = int(input())
if n == s:
  print(n+1)
  exit()
ru = math.ceil(math.sqrt(n))+1
for i in range(2,ru+1):
  b = n+0
  a = []
  while b:
    a.append(b%i)
    b//=i
  kota = sum(a)
  if s == kota:
    print(i)
    exit()
for i in range(ru,0,-1):
  q = s-i
  if q <0:
    continue
  c = (n-q)// i
  b = n+0
  a = []
  while b:
    a.append(b%c)
    b//=c
  kota = sum(a)
  if kota == s:
    print(c)
    exit()
print(-1)
Problem p03089 (python)

Fixed submission:
"""
A - Limited Insertion
"""
import numpy as np

N = input()
b_list = list(map(int, input().split()))
# N = 9
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]
# b_list = [1,1,3,1,2]
# b_list = [2,2]


def make_idx(tmp_list):
    return np.arange(1, len(tmp_list)+1, 1)[::-1]

b_list = b_list[::-1]
idx_list = make_idx(b_list)
rm_list = []

while len(b_list):
    for idx, b in zip(idx_list, b_list):
        if idx==b:
            b_list = b_list[::-1]
            b_list.remove(b)
            rm_list.append(b)
            b_list = b_list[::-1]
            break
        elif idx-b<0:
            print(-1)
            exit()
    idx_list = make_idx(b_list)
    
for r in rm_list[::-1]:
    print(r)

Buggy submission (verdict: Runtime Error):
N = input()
b_list = list(map(int, input().split()))

# N = 3
# b_list = [1,1,3,1,2]
# b_list = [1, 1, 1, 2, 2, 1, 2, 3, 2]
# b_list = [1,1,1,2,2,1,2,3,2]

a_list = []

def insert(tmp_list, x, new):

    tmp = tmp_list[x:]
    tmp_list[x] = new
    tmp_list += tmp
    return tmp_list

p_list = []
m_list = []
z_list = []

for num, b in enumerate(b_list):
    num+=1
    
    idx = b-num
    
#     " 実現不可能 "
    if idx>0:
        print(-1)
#         exit()
    elif idx<0:
        m_list.append(b)
    elif idx==0:
        if num==1:
            continue
        z_list.append(b)

m_list.sort(reverse=True)
z_list.sort()

sol_list = []
sol_list.append(1)

m_max = max(m_list)

import numpy as np
care_dict = {}
for num, i in enumerate(n_list):
    if i!=m_max:
        continue
    d_list = []
    for j in n_list[num+1:]:
        diff = i-j
        d_list.append(diff)
    d_list = np.array(d_list)
    d_list = d_list[d_list>0]
    if len(d_list):
        care_dict[i] = len(d_list)
        
m_list = iter(m_list)
o_list = []

for m in m_list:
    
    for o in o_list:
        gr = care_dict[o]
        if len(sol_list)>= o+(gr-1):
            sol_list.append(o)
            o_list.remove(o)
    
    if m in care_dict.keys():
        gr = care_dict[m]
        
#         print(len(sol_list), m+(gr-1))
        
        if len(sol_list)>= m+(gr-1):
            sol_list.append(m)
        else:
            o_list.append(m)
    else:
        sol_list.append(m)
        
for o in o_list:
    gr = care_dict[o]
    if len(sol_list)>= o+(gr-1):
        sol_list.append(o)
        o_list.remove(o)
        
for z in z_list:
    sol_list.append(z)

for s in sol_list:        
    print(s)
Problem p03095 (python)

Fixed submission:
N = input()
S = input()
m = 1

for i in set(S):
    m *= S.count(i)+1
#     print(m, S.count(i))
print( (m-1) % (10**9+7) )

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

T = ''

cnt = 0
cnt_list = []
for i in S:
  if len(T)==0:
    cnt+=1
    bef = i
  elif bef!=i:
    cnt+=1
    bef = i
  elif bef==i:
    cnt_list.append(cnt)
    cnt = 0
    
m = max(cnt_list)
print(m%(10**9+7))
Problem p03147 (python)

Fixed submission:
import numpy as np
N = int(input())
h = np.array(list(map(int, input().split())))

# N =  8
# h = np.array(list(map(int, "4 23 75 0 23 96 50 100".split())))

a = np.zeros(N)
h_min = min(h)
h_max = max(h)
n_loop = h_max - h_min

cnt = 0
for zzz in range(n_loop):
    tmp = (h >= h_min+1+zzz)*1
#     print(tmp)
    for idx, i in enumerate(tmp):
        if idx==0:
            first = i
            a0 = i
            continue
            
        if i==a0:
            continue
        else:
            if i==1:
                cnt+=1
            a0 = i
    else:
        if first==1:
            cnt+=1
            
print(cnt+h_min)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = input()
h = np.array(list(map(int, input().split())))

a = np.zeros(N)
h_min = min(h)
tmp = (h >= h_min+1)*1

cnt = 0
for idx, i in enumerate(tmp):
    if idx==0:
        a0 = i
        if i==1:
            cnt+=1
        continue
        
    if idx==a0:
        continue
    else:
        cnt+=1
else:
    if i==0:
        cnt-=1
        
print(cnt+h_min)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = input()
h = list(map(int, input().split()))

a = np.zeros(N)
h_min = min(h)
tmp = (h >= h_min+1)*1

cnt = 0
for idx, i in enumerate(tmp):
    if idx==0:
        a0 = i
        if i==1:
            cnt+=1
        continue
        
    if idx==a0:
        continue
    else:
        cnt+=1
else:
    if i==0:
        cnt-=1
        
print(cnt+h_min)
Problem p03261 (python)

Fixed submission:
def main():
    n = int(input())
    before = ''
    words = set()

    for i in range(n):
        w = input()
        if w not in words:
            words.add(w)
        else:
            print('No')
            return

        if before == '':
            before = w
            continue

        if before[-1] != w[0]:
            print('No')
            return
        before = w

    print('Yes')


main()

Buggy submission (verdict: Runtime Error):
def main():
    n = input()
    before = ''
    words = set()

    for i in range(n):
        w = input()
        if w not in words:
            words.add(w)
        else:
            print('No')
            return

        if before == '':
            before = w
            continue

        if before[-1] != w[0]:
            print('No')
            return

    print('Yes')


main()
Problem p03273 (python)

Fixed submission:
import numpy as np


def yoko(row):
    cnt = sum(row)
    return cnt == len(row)


def main():
    h, w = map(int, input().split(' '))
    a = []

    for i in range(h):
        b = input()
        a += [1 if c == '.' else 0 for c in b]
    a = np.array(a).reshape(h, w)

    while True:
        cnt = 0
        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            del_cnt = 0
            for idx in del_list:
                a = np.delete(a, idx - del_cnt, axis=0)
                del_cnt += 1
        else:
            cnt += 1

        a = a.T

        if cnt >= 2:
            break

    for i in range(len(a)):
        r = ''
        for j in a[i]:
            if j == 1:
                r += '.'
            else:
                r += '#'
        print(r)


main()

Buggy submission (verdict: Runtime Error):
import numpy as np


def yoko(row):
    cnt = sum(row)
    return cnt == len(row)


def main():
    h, w = map(int, input().split(' '))
    a = []

    for i in range(h):
        b = input()
        a += [1 if c == '.' else 0 for c in b]
    a = np.array(a).reshape(h, w)

    while True:
        cnt = 0
        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            for idx in del_list:
                a = np.delete(a, idx, axis=0)
        else:
            cnt += 1

        a = a.T

        del_list = []
        for i in range(len(a)):
            judge = yoko(a[i])
            if judge:
                del_list.append(i)

        if len(del_list):
            for idx in del_list:
                a = np.delete(a, idx, axis=0)
        else:
            cnt += 1

        a = a.T

        if cnt >= 2:
            break

    for i in range(len(a)):
        r = ''
        for j in a[i]:
            if j == 1:
                r += '.'
            else:
                r += '#'
        print(r)


main()
Problem p02732 (python)

Fixed submission:
from collections import defaultdict
from math import factorial

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial    N = int(input())
A = list(map(int, input().split()))

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    print(combination_all - (combi[a] - combi2[a]))

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

number = defaultdict(int)
for a in A:
    number[a] += 1

def combination(n, r):
    denominator = 1
    for i in range(n, n - r, -1):
        denominator *= i
    numerator = factorial(r)
    return denominator // numerator

combi = {}
combi2 = {}
for k, v in number.items():
    combi[k] = combination(v, 2)
    combi2[k] = combination(v - 1, 2)
combination_all = sum(combi.values())
# print(f"number:{number} combi:{combi} combi2:{combi2} combination_all:{combination_all}", file=sys.stderr)

for a in A:
    # print(f"a:{a} n:{n}", file=sys.stderr)
    print(combination_all - (combi[a] - combi2[a]))
Problem p02755 (python)

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

begin = int(min(A // 0.08, B // 0.10))
end = int(max((A + 1) // 0.08, (B + 1) // 0.10))

for n in range(begin, end+1):
    if int(n * 0.08) == A and int(n * 0.1) == B:
        print(n)
        break
else:
    print(-1)

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

begin = int(min(A // 0.08, B // 0.10))
end = int(max((A + 1) // 0.08, (B + 1) // 0.10))

for n in range(begin, end+1):
  if int(n * 0.08) == A and int(n * 0.1) == B:
    print(n)
    break
    else:
      print(-1)
Problem p02780 (python)

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

expected_value = []
for i in range(len(p)):
    expected_value.append((p[i] + 1)/ 2)

### K個合算した数値の配列
cumsum = []
cumsum_temp = 0
for i in range(len(p) - K + 1):
    if i == 0:
        cumsum_temp = sum(expected_value[:K])
    else:
        cumsum_temp = cumsum_temp - expected_value[i - 1] + expected_value[i + K - 1]
    cumsum.append(cumsum_temp)
# print(f"N:{N} K:{K} expected_value:{expected_value} cumsum:{cumsum}")

print(max(cumsum))

Buggy submission (verdict: Runtime Error):
N, K = list(map(int, input().split()))
p = list(map(int, input().split()))

expected_value = []
for i in range(len(p)):
    value = 0
    for j in range(1, p[i] + 1):
        value += j / p[i]
    expected_value.append(value)

### K個合算した数値の配列
cumsum = []
cumsum_temp = 0
for i in range(len(p) - K):
    if i == 0:
        cumsum_temp = sum(expected_value[:K])
    else:
        cumsum_temp = cumsum_temp - expected_value[i - 1] + expected_value[i + K]
    cumsum.append(cumsum_temp)

print(max(cumsum))
Problem p02939 (python)

Fixed submission:
S = '_' + input()
### dp[i文字目まで読んだ][直前に読んだ文字] = 分割数
dp = []
for _ in range(len(S) + 1):
    dp += [{}]
if len(S) == 2:
    print(1)
else:
    dp[2][S[1:2]] = 1
    dp[3][S[1:3]] = 1
    index = 2
    while index < len(S):
        for k, v in dp[index].items():
            if index + 1 <= len(S):
                s = S[index: index + 1]
                # print(f"index:{index} k:{k} v:{v} s:{s}", file=sys.stderr)
                if s != k:
                    if not s in dp[index + 1]:
                        dp[index + 1][s] = v + 1
                    elif s in dp[index + 1] and dp[index + 1][s] < v + 1:
                        dp[index + 1][s] = v + 1
            if index + 2 <= len(S):
                s = S[index: index + 2]
                if s != k:
                    if not s in dp[index + 2]:
                        dp[index + 2][s] = v + 1
                    elif s in dp[index + 2] and dp[index + 2][s] < v + 1:
                        dp[index + 2][s] = v + 1
        index += 1
    # print(f'len:{len(S)} dp:{dp}', file=sys.stderr)
    print(max([v for k, v in dp[-1].items()]))

Buggy submission (verdict: Runtime Error):
S = '_' + input()
### dp[i文字目][直前に見た文字] = 分割数
dp = []
for _ in range(len(S)):
    dp += [{}]
dp[1][S[1:2]] = 1
index = 1
while index < len(S):
    for k, v in dp[index].items():
        if index + 1 < len(S):
            s = S[index: index + 1]
            if s != k:
                if not s in dp[index + 1]:
                    dp[index + 1][s] = v + 1
                elif s in dp[index + 1] and dp[index + 1][s] < v + 1:
                    dp[index + 1][s] = v + 1
        if index + 2 < len(S):
            s = S[index: index + 2]
            if s != k:
                if not s in dp[index + 2]:
                    dp[index + 2][s] = v + 1
                elif s in dp[index + 2] and dp[index + 2][s] < v + 1:
                    dp[index + 2][s] = v + 1
    index += 1
# print(f'dp:{dp}', file=sys.stderr)
print(max([v for k, v in dp[-1].items()]))
Problem p03262 (python)

Fixed submission:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x2 = x.copy() + [X]
x2 = sorted(x2)
diffs = []
for i in range(1, len(x2)):
    diffs.append(x2[i] - x2[i - 1])
if len(diffs) == 1:
    print(diffs[0])
else:
    diffs_gcd = gcd(diffs[0], diffs[1])
    for i in range(2, len(diffs)):
        diffs_gcd = gcd(diffs_gcd, diffs[i])
    print(diffs_gcd)

Buggy submission (verdict: Runtime Error):
from math import gcd

N, X = list(map(int, input().split()))
x = list(map(int, input().split()))

x2 = x.copy() + [X]
x2 = sorted(x2)
diffs = []
for i in range(1, len(x2)):
    diffs.append(x2[i] - x2[i - 1])
if len(diffs) == 1:
    print(diffs[0])
else:
    diffs_gcd = gcd(diffs[0], diffs[1])
    for i in range(2, len(diffs)):
        diffs_gcd = gcd(diffs_gcd, diffs[i])
    print(diffs_gcd)
Problem p03471 (python)

Fixed submission:
N, Y = list(map(int, input().split()))

result = (-1, -1, -1)
for x in range(N + 1):
    for y in range(N + 1):
        if x + y > N:
            break
        if 10000 * x + 5000 * y + 1000 * (N - x - y) == Y:
            result = (x, y, N - x - y)
print("{} {} {}".format(result[0], result[1], result[2]))

Buggy submission (verdict: Runtime Error):
N, Y = list(map(int, input().split()))

q = [(N, 0, 0)]
while len(q) > 0:
    hyp = q.pop()
    num = hyp[0] + hyp[1] + hyp[2]
    currency = 10000 * hyp[0] + 5000 * hyp[1] + 1000 * hyp[2]
    if num == N and currency == Y:
        q.append(hyp)
        break
    if currency < Y:
        continue
    
    #### 10000円札 → 5000円札 x 2 の場合
    q.append((hyp[0] - 1, hyp[1] + 1, hyp[2]))
    q.append((hyp[0] - 1, hyp[1], hyp[2] + 1))

    #### 5000円札 x 1 → 1000円札 x 5 の場合
    if hyp[1] >= 1:
        q.append((hyp[0], hyp[1] - 1, hyp[2] + 1))

if len(q) > 0:
    print(f"{q[-1][0]} {q[-1][1]} {q[-1][2]}")
else:
    print("-1 -1 -1")
Problem p02748 (python)

Fixed submission:
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
ans = min(a) + min(b)

for xyci in xyc:
    x, y, c = xyci
    tmp = a[x - 1] + b[y - 1] - c
    if ans > tmp:
        ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
mans = min(a) + min(b)
ans = mans
for xyci in xyc:
    tmp = a[xyci[0] - 1] + a[xyci[1] - 1] - xyci[2]
    if ans > tmp:
        ans = tmp

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

A, B, M = map(int, sys.stdin.readline().rstrip().split())
a = list(map(int, sys.stdin.readline().rstrip().split()))
b = list(map(int, sys.stdin.readline().rstrip().split()))
xyc = [list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
ans = 10 ** 9 + 7
mans = min(a) + min(b)
for xyci in xyc:
    tmp = a[xyci[0] - 1] + a[xyci[1] - 1] - xyci[2]
    if ans > tmp:
        ans = tmp

print(min(tmp, mans))
Problem p02924 (python)

Fixed submission:
from sys import stdin

n = int(stdin.readline().rstrip())
ans = 0
ans = (n-1) * (n) // 2

print(ans)

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
ans = 0

def solve(n):
    for i in range(n):
        ans += i
    return ans

print(solve(n))

Buggy submission (verdict: Runtime Error):
from sys import stdin

n = int(stdin.readline().rstrip())
ans = 0

from numba import njit

@njit
def solve(n):
    for i in range(n):
        ans += i
    return ans

print(solve(n))