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

Fixed submission:
def resolve():
    n = int(input())
    name = []
    while n > 0:
        c = n % 26
        n //= 26
        if c == 0:
            name.append('z')
            n -= 1
        else:
            name.append(chr(c + 96))

    name.reverse()
    ans = ''.join(name)
    print(ans)

resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    n = int(input())
    flag = 0
    name = []
    if n < 27:
        print(chr(i + 96))
        return
    while n > 0:
        c = n % 26
        name.append(c)
        n //= 26
        if n == 1:
            flag = 1

    print(''.join([chr(i + 96) for i in reversed(name)]))

resolve()
Problem p02695 (python)

Fixed submission:
import itertools

n, m, q = map(int, input().split())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations_with_replacement(I, n)))
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d
print(max(ans))

Buggy submission (verdict: Runtime Error):
import itertools

n, m, q = map(int, input().split())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations(I, n)))
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d
print(max(ans))

Buggy submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations(I, n)))
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d
print(max(ans))

Buggy submission (verdict: Runtime Error):
import itertools
n, m, q = map(int, input().split())
I = list(range(1, m + 1))
A = list(map(list, itertools.combinations(I, n)))
l = len(A)
for i in range(l):
    if A[0][0] == 1:
        A.append(A[0])
    A.pop(0)
l = len(A)
ans = [0 for i in range(l)]
for _ in range(q):
    a, b, c, d = map(int, input().split())
    for i in range(l):
        if A[i][b - 1] - A[i][a - 1] == c:
            ans[i] += d

print(max(ans))
Problem p02785 (python)

Fixed submission:
N, K = map(int, input().split())
H = sorted(list(map(int, input().split())))
if N <= K:
    print('0')
elif K == 0:
    print(sum(H))
else:
    print(sum(H[:N - K]))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
if N <= K:
    print('0')
    return
H = sorted(list(map(int, input().split())))
if K == 0:
    print(sum(H))
else:
    print(sum(H[:K + 1]))
Problem p02580 (python)

Fixed submission:
import sys
input = sys.stdin.readline

h, w, m = map(int,input().split())

row = [0]*h
col = [0]*w
enemy = []

for i in range(m):
    hh, ww = map(lambda x:int(x)-1,input().split())
    row[hh] += 1
    col[ww] += 1
    enemy.append((hh,ww))

enemy = set(enemy)
rmax = max(row)
cmax = max(col)

on_r = row.count(rmax)
on_c = col.count(cmax)

on = 0
for hh, ww in enemy:
    if row[hh] == rmax and col[ww] == cmax:
        on += 1
if on == on_r*on_c:
    print(rmax+cmax-1)
else:
    print(rmax+cmax)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

h, w, m = map(int,input().split())

row = [0]*w
col = [0]*h
maze = [[0 for _ in range(w)] for _ in range(h)]

for i in range(m):
    hh, ww = map(lambda x:int(x)-1,input().split())
    row[hh] += 1
    col[ww] += 1
    maze[hh][ww] = 1

rmax = max(row)
cmax = max(col)
 
rind = [n for n, v in enumerate(row) if v == rmax]
cind = [n for n, v in enumerate(col) if v == cmax]
 
#print(rind)
#print(cind)
ans = 0
 
for r in rind:
    for c in cind:
        if maze[r][c] == 1:
            ans = rmax+cmax-1
        else:
            ans = rmax+cmax
            print(ans)
            exit()
print(ans)
Problem p02701 (python)

Fixed submission:
N = int(input())
ans = {}
for i in range(N):
  t = input()
  if t not in ans:
    ans[t] = 1
print(len(ans.keys()))

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = {}
for i in range(N):
  t = input()
  if t not in ans:
    ans[t] = 1
print(len(ans.keys())
Problem p02833 (python)

Fixed submission:
n = int(input())
if n%2:
    print(0)
else:
    #2と5があれば10ができる→5の方が少ない→素因数5の数を数える
    ans = (n//5)//2
    tmp = 5
    while True:
        tmp *= 5
        if tmp > n:
            break
        ans += (n//tmp)//2
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
if n%2:
    print(0)
else:
    ans = (n//5)//2
    tmp = 5
    while True:
        tmp *= 5
        if tmp > n:
            break
        ans += (n//tmp)//2
print(ans)
Problem p02873 (python)

Fixed submission:
S = input()

ans = [0]*(len(S)+1)

for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = max(ans[i+1], ans[i]+1)
    
for i in range(len(S)):
    i = len(S)-1 - i
    if S[i] == ">":
        ans[i] = max(ans[i],ans[i+1]+1)

print(sum(ans))

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

ans = [0]*(len(S)+1)

for i in range(len(S)):
    if S[i] == "<":
        ans[i+1] = max(ans[i+1], ans[i]+1)
    
for i in range(len(S)):
    if S[-(i+1)] == ">":
        ans[-(i+2)] = max(ans[(i+2)], ans[-(i+1)]+1)
        
print(sum(ans))
Problem p03017 (python)

Fixed submission:
n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,min(d+1,n-1)):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,d+1):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

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

n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = input()

ok = True
overtake = False

if c < d:
    overtake = True
    
for i in range(a,d):
    if S[i] == "#" and S[i+1] == "#":
        ok = False

for i in range(b,n-1):
    if S[i] == "." and S[i-1] == "." and S[i+1] == ".":
        overtake = True
        
if ok and overtake:
    print('Yes')
else:
    print('No')

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

n, a, b, c, d = map(lambda x:int(x)-1,input().split())
n += 1
S = [1 if s == "." else 0 for s in input()]

ok = True
overtake = False

if a<b and c<d:
    overtake= True
if b<a and d<c:
    overtake = True
    
groups = []
tmp = 0
zeros = 0
for n in S:
    if n == 1:
        if zeros != 0:#直前まで０だったとき
            groups.append(zeros)
            zeros = 0#リセット
        tmp += 1
    elif n == 0:
        if tmp != 0:#直前まで１だったとき
            groups.append(tmp)
            tmp = 0#リセット
        zeros -= 1
if tmp != 0:
    groups.append(tmp)
if zeros != 0:
    groups.append(zeros)

now = 0
for i in range(len(groups)):
    if now+abs(groups[i]) >= max(a,b):
        ind = i
        break
    now += abs(groups[i])

for i in range(ind+1,len(groups)):
    if groups[i] >= 3:
        overtake = True
    if groups[i] <= -2:
        ok = False

if now+groups[ind]-max(a,b) >= 2:
    overtake= True
if now+groups[ind]-max(a,b) >= 1 and max(a,b)-now >= 1:
    overtake = True

if overtake and ok:
    print('Yes')
else:
    print('No')
Problem p03038 (python)

Fixed submission:
import collections

N, M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()
op = [0]*M

for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b)

op.sort(reverse=True)

now = 0
flag = False
for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if now >= N:
        break
    if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
import collections

N, M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()
op = [0]*M

for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b)

op.sort(reverse=True)

now = 0
flag = False
for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if A[now] < val:
        for j in range(maisu):
            if now+j < N:
                if A[now+j] < val:
                    A[now+j] = val
                else:
                    flag = True
                    break
        now += maisu 
    else:
        break
    
print(sum(A))

Buggy submission (verdict: Runtime Error):
import collections

N, M = map(int,input().split())

A = list(map(int,input().split()))
A.sort()
op = [0]*M

for i in range(M):
    b,c = map(int,input().split())
    op[i] = (c, b)

op.sort(reverse=True)

now = 0
flag = False
for i in range(M):
    if flag:
        break
    val, maisu = op[i]
    if A[now] < val:
        for j in range(maisu):
            if A[now+j] < val:
                A[now+j] = val
            else:
                flag = True
                break
        now += maisu 
    else:
        break
    
print(sum(A))
Problem p03329 (python)

Fixed submission:
N = int(input())

dp = [10**5]*(N+1)
dp[0] = 0
dp[1] = 1
s = 6
n = 9
for i in range(2,N+1):
    if 6*s <= i:
        s *= 6
    if 9*n <= i:
        n *= 9
    if i < 6:
        dp[i] = dp[i-1]+1
    elif i < 9:
        dp[i] = min(dp[i-1], dp[i-s])+1
    else:
        dp[i] = min(dp[i-1], dp[i-s], dp[i-n])+1
print(dp[N])

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

dp = [10**5]*(N+1)
dp[0] = 0
dp[1] = 1
s = 6
n = 9
for i in range(2,N+1):
    if 6*s <= i:
        s *= 6
    if 9*n <= i:
        n *= 9
    dp[i] = min(dp[i-1], dp[i-s], dp[i-n])+1
print(dp[N])
Problem p02629 (python)

Fixed submission:
alpha = 'abcdefghijklmnopqrstuvwxyz'
N= int(input())
len_alpha = 26
tmp = N
calc = tmp
cnt = 1

while tmp > 0:
    calc = tmp
    tmp -= (len_alpha **cnt)
    cnt += 1

res =''
for i in range(1, cnt - 1):
    tmp = int((calc-1)/(len_alpha**(cnt - i - 1)))
    calc -= tmp * len_alpha**(cnt - i - 1)
    res += alpha[tmp]

res += alpha[calc-1]
print(res)

Buggy submission (verdict: Runtime Error):
alpha = 'abcdefghijklmnopqrstuvwxyz'
N= int(input())
len_alpha = 26
tmp = N
calc = tmp
cnt = 1

while tmp > 0:
    calc = tmp
    tmp -= (len_alpha **cnt)
    cnt += 1

res =''
for i in range(1, cnt - 1):
    tmp = int(calc/(len_alpha**(cnt - i - 1)))
    calc -= tmp * len_alpha**(cnt - i - 1)
    res += alpha[tmp]

res += alpha[calc-1]
print(res)
Problem p02550 (python)

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

seen = {}
ans = p%m
seen[p%m]=1
T = {}
T[1] = ans
T[0] = 0
last_p = p%m

r = 0

if n==1:
  print(p%m)
  exit()
else:
  for i in range(2,m+1000):
    p = p ** 2
    p = p % m
    
    if p not in seen:
      seen[p]=i
    else:
      r = i-seen[p]
      last_p = p
      break
    
    ans += p
    T[i] = ans
    
    if i==n:
      print(ans)
      exit()
    
    
temp = T[seen[p]-1]
ans -= temp
n -= seen[p]

k = n//r
ans *= k
ans += temp

n = n % r

if n==0:
  print(ans+last_p)
  exit()

for i in range(1,m+1000):
  p = p ** 2
  p = p % m
  ans += p
  if i==n:
    print(ans+last_p)
    exit()

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

seen = {}
ans = p%m
seen[p%m]=1
T = {}
T[1] = ans
last_p = p%m

r = 0

if n==1:
  print(p%m)
else:
  for i in range(2,m+1000):
    p = p ** 2
    p = p % m
    
    if p not in seen:
      seen[p]=i
    else:
      r = i-seen[p]
     # print(r, i, seen[p], p)
      last_p = p
      break
    
    ans += p
    T[i] = ans
    
    #last_p = p
    
    if i==n:
      print(ans)
      exit()
    
    
temp = T[seen[p]-1]
#print(temp)
ans -= temp
n -= seen[p]
#print(492443256176507)
#print(p, 'p')
    
k = n//r
ans *= k
ans += temp

n = n % r
if n==0:
  print(ans+last_p)
  exit()

for i in range(1,m+1000):
  p = p ** 2
  p = p % m
  ans += p
  if i==n:
    print(ans+last_p)
    exit()
Problem p02577 (python)

Fixed submission:
import sys
input = sys.stdin.readline
 
#a,b,c = list(map(int,input().split()))
 
a = list(input().rstrip())

ans = 0

for dig in a:
  ans += int(dig)
  
#print(ans)
  
if ans % 9 ==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
#a,b,c = list(map(int,input().split()))
 
a = list(input())

ans = 0

for dig in a:
  ans += int(dig)
  
if ans % 9 ==0:
  print('Yes')
else:
  print('No')
Problem p02580 (python)

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

R = [0]*h
C = [0]*w
G = {}

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[(a,b)] = 1
  
hhh = max(R)
ccc = max(C)
hei,wei = [],[]

for i in range(h):
  if R[i]==hhh:
    hei.append(i)
    
for i in range(w):
  if C[i]==ccc:
    wei.append(i)
  
  
best = 0
for i in hei:
  for j in wei:
    cor = 0
    if (i,j) in G:
      cor = 1
    best = max(best,R[i]+C[j] - cor)
    if cor==0:
      break
  if cor==0:
      break
      
print(best)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

R = [0]*h
C = [0]*w
G = [[0]*w for _ in range(h)]

for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[a][b] = 1
  
best = 0
for i in range(h):
  for j in range(w):
    best = max(best,R[i]+C[j] - G[i][j])
    
print(best)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
h,w,m = list(map(int,input().split()))

R = [0]*h
C = [0]*w

G = [[0]*w for _ in range(h)]


for _ in range(m):
  a,b = list(map(int,input().split()))
  a,b = a-1, b-1
  R[a] += 1
  C[b] += 1
  G[a][b] = 1
  
best = 0
for i in range(h):
  for j in range(w):
    best= max(best,R[i]+C[j] - G[i][j])
    
print(best)
Problem p02598 (python)

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

s = (10**9) // 2
step = s
best= 999999999999
import math

for j in range(50):
  c = 0
  arr = list(f)

  for i in range(n):
    if arr[i] > s:
      v = 0
      if arr[i] % s != 0:
        c += arr[i] // s
        v += arr[i] // s
      else:
        c += arr[i] // s
        v += arr[i] // s
        c -= 1
        v -= 1
      cor = 0
      if arr[i] % (v+1) != 0:
        cor = 1
      arr[i] = arr[i]//(v+1) + cor
    
  step = step//2
  step = max(1, step)
 
  if c<=k:
    best = min(best,max(arr))
   # print(s,best)
    s -= step
  else:
    s += step
    
  if s==0:
    s=1
      
print(best)

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

s = (10**9) // 2
step = s
best= 999999999999
import math

for j in range(50):
  c = 0
  arr = list(f)
  for i in range(n):
    c += arr[i] // s
    arr[i] /= (c+1)
    
  step = step//2
  step = max(1, step)
 
  if c<=k:
    s -= step
    best = min(best,math.ceil(max(arr)))
  else:
    s += step
      
print(best)
Problem p02891 (python)

Fixed submission:
s = list(input())
k = int(input())
n = len(s)
s.append(' ')

l = []
cnt = 1
for i in range(1, n + 1):
    if s[i - 1] != s[i]:
        l.append(cnt)
        cnt = 1
    else:
        cnt += 1
m = sum(map(lambda li: li // 2, l))
if len(l) == 1:
    ans = k * n // 2
elif s[0] == s[-2] and l[0] % 2 == l[-1] % 2 == 1:
    ans = k * m + k - 1
else:
    ans = k * m
print(ans)

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
n = len(s)
s += ' '

l = []
cnt = 1
for i in range(1, n + 1):
    if s[i - 1] != s[i]:
        l.append(cnt)
        cnt = 1
    else:
        cnt += 1
m = sum(map(lambda li: li // 2, l))
if s[0] == s[-2]:
    if len(l) == 1:
        ans = k * n // 2
    elif l[0] % 2 == l[-1] % 2 == 1:
        ans = k * m + k - 1
    else:
        ans = k * m
print(ans)
Problem p03723 (python)

Fixed submission:
A, B, C = map(int, input().split())
dict = {}
ans = 0
while ans < 1000000:
    tpl = tuple(sorted([A, B, C]))
    if tpl in dict:
        ans = -1
        break
    elif A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
        break
    dict[tpl] = True
    A, B, C = (B + C) // 2, (C + A) // 2, (A + B) // 2
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
def dist(r, c):
    return min(r, H - r - 1, c, W - c - 1)

H, W, K = map(int, input().split())
A = [list(input()) for _ in range(H)]

for r in range(H):
    for c in range(W):
        if A[r][c] == 'S':
            sr = r
            sc = c

dxy = [(1, 0), (0, -1), (-1, 0), (0, 1)]
pos = [(sr, sc)]
dic = {(sr, sc): K}
cnt = 0
ans = H * W
i = 0
while i < len(pos):
    r0, c0 = pos[i]
    d0 = dist(r0, c0)
    ans = min(ans, (d0 + K - 1) // K + 1)
    m0 = dic[(r0, c0)]
    if 0 < m0:
        m = m0 - 1
        for (dx, dy) in dxy:
            r = r0 + dy
            c = c0 + dx
            d = dist(r, c)
            if 0 <= r < H and 0 <= c < W and A[r][c] != '#' and (r, c) not in dic:
                pos.append((r, c))
                dic[(r, c)] = m
    i += 1

print(ans)
Problem p02623 (python)

Fixed submission:
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = 0
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        break
    cumsumB += [tmp]
j = 0
ans = 0
for i in range(ansA, -1, -1):
    t = cumsumA[i] + cumsumB[j]
    while True:
        tmp = B[j+1]
        if tmp + t <= K:
            t += tmp
            j += 1
        else:
            break
    ans = max(ans, i + j)
print(ans)

Buggy submission (verdict: Runtime Error):
# import sys
N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split())) + [10**13]
B = [0] + list(map(int, input().split())) + [10**13]
sum_t = 0
cumsumA = [0]
cumsumB = [0]
ansA = N
ansB = M
tmp = 0
for i in range(1, N+1):
    tmp = tmp + A[i]
    if tmp > K:
        ansA = i-1
        break
    cumsumA += [tmp]
tmp = 0
for i in range(1, M+1):
    tmp = tmp + B[i]
    if tmp > K:
        ansB = i-1
        break
    cumsumB += [tmp]

ans_t = cumsumA[ansA] + cumsumB[ansB]
ansAA = ansA
ansBB = ansB
ans = ansA + ansB
ans2 = max([ans, ansAA, ansBB])
visited_dict = {}
while K < ans_t:    
    ai, bi = A[ansA], B[ansB]
    if visited_dict.get((ai, bi)):
        break
    visited_dict[(ai, bi)] = 1
    if ai >= bi:
        ans_t -= ai
        ans -= 1
        ansA -= 1
        bi = B[ansB+1]
        while ans_t <= K:
            ans += 1
            ans_t += bi
            ansB += 1
            bi = B[ansB+1]
    else:
        ans_t -= bi
        ans -= 1
        ansB -= 1
        ai = A[ansA+1]
        while ans_t <= K:
            ans += 1
            ans_t += ai
            ansA += 1
            ai = A[ansA+1]
    
ans2 = max(ans-1, ans2)

print(ans2)
# print(ansA, ansB)
Problem p02990 (python)

Fixed submission:
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1) // math.factorial(K-i)
    if R < 0:
        ans = 0
    else:
        ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    print((ans*KC) % m)

Buggy submission (verdict: Runtime Error):
import math
N, K = map(int, input().split())
m = 10 ** 9 + 7
for i in range(1, K+1):
    R = N - K - i + 1
    if i == 1:
        KC = 1
    else:
        KC = math.factorial(K-1) // math.factorial(i-1)
    ans = math.factorial(R+i) // (math.factorial(R) * math.factorial(i))
    # print(R, KC, ans)
    print((ans*KC) % m)
Problem p03127 (python)

Fixed submission:
import functools
# import math
import fractions
N = int(input())
A = list(map(int, input().split()))
# ans = functools.reduce(math.gcd, A)
ans = functools.reduce(fractions.gcd, A)
print(ans)

Buggy submission (verdict: Runtime Error):
import functools
# import math
import fraction
N = int(input())
A = list(map(int, input().split()))
# ans = functools.reduce(math.gcd, A)
ans = functools.reduce(fraction.gcd, A)
print(ans)
Problem p03805 (python)

Fixed submission:
import copy
def explore(key, flags):
    flags = copy.copy(flags)
    if flags[key-1]:
        return 0
    flags[key-1] = True
    if False not in flags:
        return 1
    elif key in graph:
        value = graph[key]
        ans = 0
        for i in value:
            ans += explore(i, flags)
        return ans
    else:
        return 0

n, m = map(int, input().split())
graph = {}
for i in range(m):
    a, b = map(int, input().split())
    if a in graph:
        graph[a].append(b)
    else:
        graph[a] = [b]
    if b in graph:
        graph[b].append(a)
    else:
        graph[b] = [a]

flags = [False for i in range(n)]
ans = explore(1, flags)
print(ans)

Buggy submission (verdict: Runtime Error):
import copy
def explore(key, flags):
    flags = copy.copy(flags)
    if flags[key-1]:
        return 0
    flags[key-1] = True
    if False not in flags:
        return 1
    elif key in graph:
        value = graph[key]
        ans = 0
        for i in value:
            ans += explore(i, flags)
        return ans
    else:
        return 0

n, m = map(int, input().split())
graph = {}
for i in range(m):
    a, b = map(int, input().split())
    if a in graph:
        graph[a].append(b)
    else:
        graph[a] = [b]
    if b in graph:
        graph[b].append(a)
    else:
        graph[b] = [a]

flags = [False for i in range(m)]
ans = explore(1, flags)
print(ans)
Problem p02954 (python)

Fixed submission:
S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))
Problem p02754 (python)

Fixed submission:

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

ans = 0
S=A+B
Q=int(N/S)
#print(int(N/(A+B)))
#for i in range(1, int(N/(A+B))+1):
#    ans = ans + A
ans = Q*A

r = N-Q*S
#print(r)

if r <= A:
    ans = ans + r
else:
    ans = ans + A

print(ans)

Buggy submission (verdict: Runtime Error):

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

ans = 0
#print(int(N/(A+B)))
for i in range(1, int(N/(A+B))+1):
    ans = ans + A

r = N-(A+B)*i
#print(r)

if r <= A:
    ans = ans + r
else:
    ans = ans + A

print(ans)