Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
if len(x_list) >= 3:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    print(c[1])
else:
  print(x_list[1]-x_list[0])

Fixed submission:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
def u(o,p):
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    return c[1]
    
if 4 >= len(x_list) >= 3:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  print(u(a[1],a[0]))

elif len(x_list) > 4:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  u = u(a[1],a[0])
  for i in a:
    if i/u == int(i/u):
      pass
    else:
      u = i%u
  print(u)
else:
  print(x_list[1]-x_list[0])

Buggy python submission (verdict: Runtime Error):
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)

if len(x_list) >= 3:
  a = []
  for i in range(1,n):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    print(c[1])
else:
  print(x_list[1]-x_list[0])

Fixed submission:
n,x = map(int,input().split())
x_list = list(map(int,input().split()))
x_list.append(x)
x_list = sorted(x_list)
def u(o,p):
  c = [a[1],a[0]]
  while c[0]%c[1] != 0:
    c.append(c[0]%c[1])
    c.pop(0)
  else:
    return c[1]
    
if 4 >= len(x_list) >= 3:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  print(u(a[1],a[0]))

elif len(x_list) > 4:
  a = []
  for i in range(1,n+1):
    a.append(x_list[i] - x_list[i-1])
  a = sorted(a)
  u = u(a[1],a[0])
  for i in a:
    if i/u == int(i/u):
      pass
    else:
      u = i%u
  print(u)
else:
  print(x_list[1]-x_list[0])
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())
cnt = 0
for i in range(b-a):
  cnt += i
print(cnt-a)

Fixed submission:
x = int(input())
if x < 1000:
  print('ABC')
else:
  print('ABD')
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())
s_list = []
for i in range(len(s)):
  s_list.append(s[i:i+k])
s_list = sorted(list(set(s_list)))
if len(s_list[0]) == k:
  print(s_list[0])
else:
  n = len(s_list[0]) + len(s_list[1])
  if n == k:
    print(s_list[2][0])
  elif n < k:
    print(s_list[2][0:k-n+1])
  else:
    print(s_list[1][0:n-k+1])

Fixed submission:
s = input()
k = int(input())
s_list = []
for i in range(len(s)):
  for j in range(k):
    s_list.append(s[i:i+j+1])
s_list = sorted(list(set(s_list)))
print(s_list[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
ans=0
ans_r=0
for i in a:
  if i==l:
    continue
  b=cmb(l,i)
  if ans<b:
    ans=b
    ans_r=i
print(l,ans_r)

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
b=[abs(i-l/2) for i in a]
c=float("inf")
for i in range(n-1):
  c=min(c,b[i])
print(l,a[b.index(c)])

Buggy python submission (verdict: Time Limit Exceeded):
from math import factorial
n=int(input())
a=sorted(list(map(int,input().split())))
def f(n,r):
  return factorial(n) // factorial(r) // factorial(n - r)
ans=0
n=a[-1]
for j,i in enumerate(a):
  b=f(n,i)
  ans=max(ans,b)
  if b<ans:
    print(n,a[max(0,j-1)])
    exit()
print(n,a[-2]) 

Fixed submission:
n=int(input())
a=sorted(list(map(int,input().split())))
l=a[-1]
b=[abs(i-l/2) for i in a]
c=float("inf")
for i in range(n-1):
  c=min(c,b[i])
print(l,a[b.index(c)])
Buggy python submission (verdict: Runtime Error):
x = input()
if int(x) % (int(x[0])+int(x[1])) == 0:
  print('Yes')
else:
  print('No')

Fixed submission:
x = input()
c = 0
for i in range(len(x)):
  c += int(x[i])
if int(x) % c == 0:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
t = sorted([int(input()) for _ in range(n)],reverse = True)
def c_mul(x,y):
  d = x
  e = y
  while y%x != 0:
    z = y%x
    y = x
    x = z
  else:
    return d*e//x
for i in range(1,n):
  a = c_mul(t[0],t[i])
  if a != t[0]:
    t[0] = a
print(a)

Fixed submission:
n = int(input())
t = sorted([int(input()) for _ in range(n)],reverse = True)
def c_mul(x,y):
  d = x
  e = y
  while y%x != 0:
    z = y%x
    y = x
    x = z
  else:
    return d*e//x
for i in range(1,n):
  a = c_mul(t[0],t[i])
  if a != t[0]:
    t[0] = a
print(t[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
ans = abs(a[0]-a[-1])
for i in range(1,n):
  sumu = a[0:i]
  arai = a[i:]
  kari = abs(sum(sumu)-sum(arai))
  if kari < ans:
    ans = kari
print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
max_ans = sum(a)
ans = abs(a[0]-(max_ans - a[0]))
sumu = a[0]
for i in range(1,n-1):
  sumu += a[i]
  arai = max_ans - sumu
  kari = abs(sumu-arai)
  if kari < ans:
    ans = kari
print(ans)
Buggy python submission (verdict: Runtime Error):
o = input()
e = input()
if len(o) > len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a+o[-1])
if len(o) == len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a)
else:
  a = e[0]+o[0]
  for i in range(1,len(o)):
    a += e[i] + o[i]
  print(a+e[-1])

Fixed submission:
o = input()
e = input()
if len(o) > len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a+o[-1])
elif len(o) == len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a)
else:
  a = e[0]+o[0]
  for i in range(1,len(o)):
    a += e[i] + o[i]
  print(a+e[-1])
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(m):
  for j in range(m):
    if a[i][j] == b[i][j]:
      pass
    else:
      a = []
if a == []:
  print('No')
else:
  print('Yes')

Fixed submission:
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    count = 0
    for x in range(m):
      for y in range(m):
        if b[x][y]!=a[i+x][j+y]:
          break
        else:
          count += 1
    if count == m**2:
      print('Yes')
      exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<ta[i][0]) and (ta[i-1][1]<ta[i][1]):
    pass
  else:
    r=ta[i][0]
    l=ta[i][1]
    while (ta[i-1][0]>ta[i][0]) or (ta[i-1][1]>ta[i][1]):
      ta[i][0]+=r
      ta[i][1]+=l
print(sum(ta[-1]))

Fixed submission:
n=int(input())
ta=[list(map(int,input().split())) for _ in range(n)]
ans=ta[0]
for i in range(1,n):
  if (ta[i-1][0]<=ta[i][0]) and (ta[i-1][1]<=ta[i][1]):
    pass
  else:
    l=ta[i-1][0]//ta[i][0]
    if ta[i-1][0]%ta[i][0]!=0:
      l+=1
    r=ta[i-1][1]//ta[i][1]
    if ta[i-1][1]%ta[i][1]!=0:
      r+=1
    ta[i][0]*=max(l,r)
    ta[i][1]*=max(l,r)
print(sum(ta[-1]))
Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print(ans-1)
    else:
        print(ans)


Fixed submission:
from itertools import product
h, w, m = map(int, input().split())


row = [set()for _ in range(h)]
col = [set()for _ in range(w)]
for _ in range(m):
    x, y = map(lambda x: int(x)-1, input().split())
    row[x].add(y)
    col[y].add(x)

crow = 0
ic = []
for i, x in enumerate(row):
    if crow < len(x):
        crow = len(x)
        ic = [i]
    elif crow == len(x):
        ic.append(i)

ccol = 0
jc = []
for j, x in enumerate(col):
    if ccol < len(x):
        ccol = len(x)
        jc = [j]
    elif ccol == len(x):
        jc.append(j)


ans = crow+ccol
for i, j in product(ic, jc):
    if j not in row[i]:
        print(ans)
        break
else:
    print(ans-1)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))


def dfs(i):
    if 0 <= visited[i]:
        return
    visited[i] = idx
    cycle.append(i)
    global csum
    csum += C[i]
    dfs(P[i])


visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
    if 0 <= visited[i]:
        continue
    cycle = []
    csum = 0
    dfs(i)
    cycles.append((cycle, csum))
    idx += 1


INF = 10**18
ans = -INF
for i in range(n):
    cycle, csum = cycles[visited[i]]
    cmem = len(cycle)

    if 0 < csum:
        a, b = divmod(k, cmem)
        scoreA = csum*a
        score = 0
        INF = 10**18
        scoreB = -INF
        for _ in range(b):
            i = P[i]
            score += C[i]
            if scoreB < score:
                scoreB = score
        X = scoreA+scoreB
    else:
        b = min(k, cmem)
        score = 0
        INF = 10**18
        X = -INF
        for _ in range(b):
            i = P[i]
            score += C[i]
            if X < score:
                X = score

    if ans < X:
        ans = X
print(ans)


Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))


def dfs(i):
    if 0 <= visited[i]:
        return
    visited[i] = idx
    cycle.append(i)
    global csum
    csum += C[i]
    dfs(P[i])


visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
    if 0 <= visited[i]:
        continue
    cycle = []
    csum = 0
    dfs(i)
    cycles.append((cycle, csum))
    idx += 1


INF = 10**18
ans = -INF
for i in range(n):
    cycle, csum = cycles[visited[i]]
    cmem = len(cycle)

    if 0 < csum:
        a, b = divmod(k, cmem)
        scoreA = csum*(a-1)
        b += cmem
        score = 0
        scoreB = 0
        for _ in range(b):
            i = P[i]
            score += C[i]
            if scoreB < score:
                scoreB = score
        X = scoreA+scoreB
    else:
        b = min(k, cmem)
        score = 0
        INF = 10**18
        X = -INF
        for _ in range(b):
            i = P[i]
            score += C[i]
            if X < score:
                X = score

    if ans < X:
        ans = X
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c = map(int, input().split())
k = int(input())
while k:
    if not a < b:
        b *= 2
        k -= 1
        continue
    elif not b < c:
        c *= 2
        k -= 1


if a < b < c:
    print('Yes')
else:
    print('No')


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

while k:
    if not a < b:
        b *= 2
        k -= 1
        continue
    elif not b < c:
        c *= 2
        k -= 1
        continue
    else:
        break


if a < b < c:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce
n, k = map(int, input().split())
A = list(map(int, input().split()))


score = reduce(mul, A[:k])
for i in range(k, n):
    nscore = score//A[i-k]*A[i]
    if score < nscore:
        print('Yes')
    else:
        print('No')

    score = nscore


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


for i in range(k, n):
    if A[i-k] < A[i]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n = int(input())


def sieve(n):
    n += 1
    res = [i for i in range(n)]
    for p in range(2, int(n**.5)+1):
        if res[p] < p:
            continue
        for q in range(p**2, n, p):
            if res[q] == q:
                res[q] = p
    return res


U = 10**7
min_factor = sieve(U)


def prime_factor(n):
    res = defaultdict(int)
    while 1 < n:
        res[min_factor[n]] += 1
        n //= min_factor[n]
    return res


ans = 0
for i in range(1, n+1):
    x = 1
    for v in prime_factor(i).values():
        x *= v+1
    ans += x*i


print(ans)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n+1):
    ans += (i+(n//i)*i)*(n//i)//2
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())-1


ans = []
while n > 0:
    n, y = divmod(n, 26)
    ans.append(y)
ans.reverse()
*x, y = ans


def to_alpha(x):
    if x == 0:
        return 'z'
    else:
        return chr(x+ord('a')-1)


print(''.join(map(to_alpha, x))+chr(y+ord('a')))

Fixed submission:
n = int(input())-1

ans = []
while n >= 0:
    n, y = divmod(n, 26)
    ans.append(y)
    n -= 1
ans.reverse()


def to_alpha(x):
    return chr(x+ord('a'))


print(''.join(map(to_alpha, ans)))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
INF = 10**18
t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = defaultdict(lambda: INF)

    def dfs(n, cost):

        if memo[n] <= cost:
            return 0

        memo[n] = cost
        if n == 0:
            return 0

        dfs(0, cost+n*d)

        r = n % 2
        dfs((n-r)//2, cost+a+r*d)
        if r != 0:
            dfs((n+(2-r))//2, cost+a+(2-r)*d)

        r = n % 3
        dfs((n-r)//3, cost+b+r*d)
        if r != 0:
            dfs((n+(3-r))//3, cost+b+(3-r)*d)

        r = n % 5
        dfs((n-r)//5, cost+c+r*d)
        if r != 0:
            dfs((n+(5-r))//5, cost+c+(5-r)*d)
            
    dfs(n, 0)
    print(memo[0])


Fixed submission:
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
INF = 10**18
t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    memo = defaultdict(lambda: INF)

    def dfs(n, cost):

        if memo[n] <= cost:
            return 0

        memo[n] = cost
        if n == 0:
            return 0

        dfs(0, cost+n*d)

        r = n % 2
        dfs((n-r)//2, cost+a+r*d)
        if r != 0:
            dfs((n+(2-r))//2, cost+a+(2-r)*d)

        r = n % 3
        dfs((n-r)//3, cost+b+r*d)
        if r != 0:
            dfs((n+(3-r))//3, cost+b+(3-r)*d)

        r = n % 5
        dfs((n-r)//5, cost+c+r*d)
        if r != 0:
            dfs((n+(5-r))//5, cost+c+(5-r)*d)
            
    dfs(n, 0)
    print(memo[0])
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
cnt = 0
decrement = 0
profit = []
loss = []

for _ in range(n):
    s = input()
    min_p = 0
    end_p = 0
    point = 0
    for c in s:
        if c == '(':
            point += 1
        elif c == ')':
            point -= 1
            if point < min_p:
                min_p = point
    else:
        end_p = point
    if 0 <= min_p:
        cnt += end_p
    else:
        if min_p == end_p:
            decrement += end_p
        else:
            if 0 <= end_p:
                profit.append((min_p, end_p))
            else:
                loss.append((min_p, end_p))


profit.sort(reverse=True)
while profit:
    min_p, end_p = profit.pop()
    if cnt+min_p < 0:
        print('No')
        exit()
    cnt += end_p


loss.sort()
while loss:
    min_p, end_p = profit.pop()
    if cnt+min_p < 0:
        print('No')
        exit()
    cnt += end_p

print('Yes' if cnt+decrement == 0 else 'No')


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

n = int(input())
cnt = 0
decrement = 0
profit = []
loss = []

for _ in range(n):
    s = input().rstrip()
    min_p = 0
    end_p = 0
    point = 0
    for c in s:
        if c == '(':
            point += 1
        elif c == ')':
            point -= 1
            if point < min_p:
                min_p = point
    else:
        end_p = point
    if 0 <= min_p:
        cnt += end_p
    else:
        if min_p == end_p:
            decrement += end_p
        else:
            if 0 <= end_p:
                profit.append((min_p, end_p))
            else:
                loss.append((min_p, end_p))



profit.sort()
while profit:
    min_p, end_p = profit.pop()
    if cnt+min_p < 0:
        print('No')
        exit()
    cnt += end_p


loss.sort(reverse=True)
while loss:
    min_p, end_p = loss.pop()
    if cnt+min_p < 0:
        print('No')
        exit()
    cnt += end_p

print('Yes' if cnt+decrement == 0 else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n = int(input())
A = list(map(int, input().split()))
edges = [[]for _ in range(n)]
for _ in range(n-1):
    u, v = list(map(lambda x: int(x)-1, input().split()))
    edges[u].append(v)
    edges[v].append(u)
INF = 10**18
ans = [INF]*n


def dfs(v, parent, lis):
    x = bisect.bisect_left(lis, A[v])
    lis[x] = A[v]
    ans[v] = bisect.bisect_left(lis, INF)
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v, lis.copy())


dfs(0, -1, [INF]*n)
for x in ans:
    print(x)

Fixed submission:
import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)


n = int(input())
A = list(map(int, input().split()))
edges = [[]for _ in range(n)]
for _ in range(n-1):
    u, v = list(map(lambda x: int(x)-1, input().split()))
    edges[u].append(v)
    edges[v].append(u)
INF = 10**18
ans = [INF]*n

def dfs(v, parent):
    x = bisect.bisect_left(lis, A[v])
    prev = lis[x]
    lis[x] = A[v]
    ans[v] = bisect.bisect_left(lis, INF)
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)
    lis[x] = prev


lis = [INF]*n
dfs(0, -1)
for x in ans:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
for L in range(n+1):
    for R in range(n+1):
        if n <= L+R-1:
            break
        a, i = A[L+R-1]
        if 0 <= R-1:
            dp[L][R] = max(dp[L][R], dp[L][R-1]+abs((n-R)-i)*a)
        if 0 <= L-1:
            dp[L][R] = max(dp[L][R], dp[L-1][R]+abs(i-(L-1))*a)
        ans = max(ans, dp[L][R])
print(ans)


Fixed submission:
n = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
for L in range(n+1):
    for R in range(n+1):
        if n <= L+R-1:
            continue
        a, i = A[L+R-1]
        if 0 <= R-1:
            dp[L][R] = max(dp[L][R], dp[L][R-1]+abs((n-R)-i)*a)
        if 0 <= L-1:
            dp[L][R] = max(dp[L][R], dp[L-1][R]+abs(i-(L-1))*a)
        ans = max(ans, dp[L][R])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
n = int(input())
A = list(map(int, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
    for j in range(1, n+1):
        dp[i][j] = abs(i-j)*A[i-1]
ans = 0
for x in itertools.permutations(range(1, n+1), n):
    cnt = 0
    for i, j in enumerate(x):
        cnt += dp[i+1][j]
    ans = max(ans, cnt)
print(ans)


Fixed submission:
n = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
dp = [[0]*(n+1) for _ in range(n+1)]
ans = 0
for L in range(n+1):
    for R in range(n+1):
        if n <= L+R-1:
            continue
        a, i = A[L+R-1]
        if 0 <= R-1:
            dp[L][R] = max(dp[L][R], dp[L][R-1]+abs((n-R)-i)*a)
        if 0 <= L-1:
            dp[L][R] = max(dp[L][R], dp[L-1][R]+abs(i-(L-1))*a)
        ans = max(ans, dp[L][R])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
from functools import reduce
from math import gcd
k = int(input())
ans = 0
for abc in product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)
print(ans)


Fixed submission:
import itertools
from functools import reduce


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


k = int(input())
ans = 0
for abc in itertools.product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)

print(ans)

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


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


k = int(input())
ans = 0
for abc in itertools.product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)

print(ans)


Fixed submission:
import itertools
from functools import reduce


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


k = int(input())
ans = 0
for abc in itertools.product([i for i in range(1, k+1)], repeat=3):
    ans += reduce(gcd, abc)

print(ans)
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())
INF = 10**5
MAP = ["."*(w+2)]
for _ in range(h):
    MAP.append("."+input()+".")
MAP.append("."*(w+2))
ROUTE = [[0]*(w+2) for _ in range(h+2)]
for i in range(2, w+1):
    ROUTE[0][i] = INF
    ROUTE[i][0] = INF

for i in range(1, h+1):
    for j in range(1, w+1):
        if MAP[i][j] == ".":
            x1 = ROUTE[i][j-1]
            x2 = ROUTE[i-1][j]
        else:
            if MAP[i][j-1] == "#":
                x1 = ROUTE[i][j-1]
            else:
                x1 = ROUTE[i][j-1]+1

            if MAP[i-1][j] == "#":
                x2 = ROUTE[i-1][j]
            else:
                x2 = ROUTE[i-1][j]+1
        ROUTE[i][j] = min(x1, x2)


print(ROUTE[h][w])


Fixed submission:
h, w = map(int, input().split())
INF = 10**5
MAP = ["."*(w+2)]
for _ in range(h):
    MAP.append("."+input()+".")
MAP.append("."*(w+2))
ROUTE = [[0]*(w+2) for _ in range(h+2)]
for i in range(2, w+1):
    ROUTE[0][i] = INF
for i in range(2, h+1):
    ROUTE[i][0] = INF

for i in range(1, h+1):
    for j in range(1, w+1):
        if MAP[i][j] == ".":
            x1 = ROUTE[i][j-1]
            x2 = ROUTE[i-1][j]
        else:
            if MAP[i][j-1] == "#":
                x1 = ROUTE[i][j-1]
            else:
                x1 = ROUTE[i][j-1]+1

            if MAP[i-1][j] == "#":
                x2 = ROUTE[i-1][j]
            else:
                x2 = ROUTE[i-1][j]+1
        ROUTE[i][j] = min(x1, x2)


print(ROUTE[h][w])
Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal, getcontext
getcontext().prec = 10000
a, b, c = map(Decimal, input().split())
print("Yes" if a**Decimal(0.5)+b**Decimal(0.5) < c**Decimal(0.5) else "No")


Fixed submission:
from decimal import Decimal, getcontext
getcontext().prec = 1000
a, b, c = map(Decimal, input().split())
print("Yes" if a+b+Decimal(2)*((a*b)**Decimal(0.5)) < c else "No")

Buggy python submission (verdict: Time Limit Exceeded):
from decimal import Decimal, getcontext
getcontext().prec = 100000
a, b, c = map(Decimal, input().split())
print("Yes" if a**Decimal(0.5)+b**Decimal(0.5) < c**Decimal(0.5) else "No")


Fixed submission:
from decimal import Decimal, getcontext
getcontext().prec = 1000
a, b, c = map(Decimal, input().split())
print("Yes" if a+b+Decimal(2)*((a*b)**Decimal(0.5)) < c else "No")