Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
from collection import deque

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    G = [[] for _ in range(3*N)]
    for _ in range(M):
        u, v = map(int, input().split())
        u, v = u-1, v-1

        G[3*u].append(3*v+1)
        G[3*u+1].append(3*v+2)
        G[3*u+2].append(3*v)

    S, T = map(int, input().split())
    S, T = 3*(S-1), 3*(T-1)

    cnt = 0
    q = deque()
    q.append(S)
    visited = [False] * (3*N)
    visited[S] = True
    while len(q) > 0:
        q_ = deque()
        cnt += 1
        while len(q) > 0:
            n = q.pop()
            for m in G[n]:
                if visited[m]:
                    continue

                if m == T:
                    return cnt

                visited[m] = True
                q_.append(m)

        q = q_

    return -1


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10**6)

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        u, v = map(int, input().split())
        G[u-1].append(v-1)
    S, T = map(int, input().split())
    S, T = S-1, T-1

    q = deque()
    q.append(S)
    cnt = 0
    cnt_k = 0
    visited = [False] * N
    visited[S] = True
    while len(q) > 0:
        cnt += 1
        if cnt % 3 == 0:
            cnt_k += 1

        next_ = set()
        while len(q) > 0:
            n0 = q.pop()
            for n1 in G[n0]:
                if cnt % 3 == 0:
                    if n1 == T:
                        return cnt_k

                    if visited[n1]:
                        continue

                    visited[n1] = True

                next_.add(n1)

        q = deque()
        q.extend(list(next_))

    return -1


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    V = 10**5  # max size of x
    N = int(input())
    bgraph = [[] for _ in range(2*V)]
    for _ in range(N):
        x, y = map(int, input().split())
        x -= 1
        y += V - 1
        bgraph[x].append(y)
        bgraph[y].append(x)

    def dfs(i):
        if visited[i]:
            return cnt
        visited[i] = True
        cnt[i//V] += 1
        for j in bgraph[i]:
            dfs(j)
        return cnt

    visited = [False] * (2*V)
    ans = 0
    for i in range(V):
        if visited[i]:
            continue
        cnt = [0, 0]
        cnt = dfs(i)
        ans += cnt[0] * cnt[1]

    ans -= N
    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys
sys.setrecursionlimit(10**6)

def main():
    input = sys.stdin.readline
    V = 10**5  # max size of x
    N = int(input())
    bgraph = [[] for _ in range(2*V)]
    for _ in range(N):
        x, y = map(int, input().split())
        x -= 1
        y += V - 1
        bgraph[x].append(y)
        bgraph[y].append(x)

    def dfs(i):
        if visited[i]:
            return cnt
        visited[i] = True
        cnt[i//V] += 1
        for j in bgraph[i]:
            dfs(j)
        return cnt

    visited = [False] * (2*V)
    ans = 0
    for i in range(V):
        if visited[i]:
            continue
        cnt = [0, 0]
        cnt = dfs(i)
        ans += cnt[0] * cnt[1]

    ans -= N
    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    cnt = 0
    D = 0
    while D <= X:
        D += A[cnt]
        cnt += 1

    return cnt


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    cnt = 0
    D = 0
    for a in A:
        D += a
        cnt += 1
        if D > X:
            cnt -= 1
            break

    return cnt+1


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]

    dp = [0] * (N+2)
    dp[1] = 1
    for i in range(N):
        step = i+2
        if i+1 in A:
            dp[step] = 0
        else:
            dp[step] = dp[step-1] + dp[step-2]
            dp[step] %= MOD

    return dp[N+1]


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    is_safe = [True] * (N+1)
    for a in A:
        is_safe[a] = False

    dp = [0] * (N+2)
    dp[1] = 1
    for i in range(N):
        step = i+2
        if is_safe[i+1]:
            dp[step] = dp[step-1] + dp[step-2]
            dp[step] %= MOD
        else:
            dp[step] = 0

    return dp[N+1]


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    A = [int(input()) for _ in range(5)]

    ans = 0
    B = []
    for a in A:
        if a % 10 == 0:
            ans += a
        else:
            B.append(a)

    B = sorted(B, key=lambda x: -(x%10))
    n = len(B)
    for i in range(n-1):
        ans += (B[i] // 10 + 1) * 10

    ans += B[n-1]

    return ans


if __name__ == '__main__':
    print(main())


Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    A = [int(input()) for _ in range(5)]

    ans = 0
    B = []
    for a in A:
        if a % 10 == 0:
            ans += a
        else:
            B.append(a)

    B = sorted(B, key=lambda x: -(x%10))
    n = len(B)
    for i in range(n-1):
        ans += (B[i] // 10 + 1) * 10

    if n > 0:
        ans += B[n-1]


    return ans


if __name__ == '__main__':
    print(main())
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [str(c) for c in input().strip()]

    ans = 0
    SS = []
    for i in range(N):
        si = S[i]
        d = {}
        for j in S[i+1:]:
            if j == si:
                continue
            if j in d:
                d[j] += 1
            else:
                d[j] = 1

        t = 1
        for k in d:
            t *= d[k] + 1

        ans += t

    print(ans % (10**9 + 7))


if __name__ == '__main__':
    main()


Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [str(c) for c in input().strip()]

    ans = 0
    d = {}
    for i in range(N-1, -1, -1):
        s = S[i]
        if s in d:
            d[s] += 1
        else:
            d[s] = 1

        t = 1
        for k in d:
            if k == s:
                continue

            t *= d[k] + 1

        ans += t
    
    print(ans % (10**9 + 7))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
import sys

def f(A, c):
  n = len(A)
  B = []
  for i in range(len(A) -1):
    if A[i] != A[i+1]:
      c += 2
      B += A[i+2:]
      break
    else:
      B.append(A[i])
  if len(B) == n:
    return c
  else:
    return f(B, c)


def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  ans = f(S, 0)
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  S = [int(c) for c in input().strip()]
  n1 = 0
  n0 = 0
  for i in S:
    if i == 0:
      n0 += 1
    else:
      n1 += 1
  print(min(n1, n0) * 2)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import bisect
import sys

def main():
  input = sys.stdin.readline
  A, B, Q = map(int, input().split())
  INF = 10**18
  S = [-INF] + [int(input()) for _ in range(A)] + [INF]
  T = [-INF] + [int(inout()) for _ in range(B)] + [INF]
  
  for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for s in [S[b-1], S[b]]:
      for t in [T[d-1], T[d]]:
        d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
        res = min(res, d1, d2)
  print(res)


if __name__ == '__main__':
  main()

Fixed submission:
import bisect
import sys

def main():
  input = sys.stdin.readline
  A, B, Q = map(int, input().split())
  INF = 10**18
  S = [-INF] + [int(input()) for _ in range(A)] + [INF]
  T = [-INF] + [int(input()) for _ in range(B)] + [INF]
  
  for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(S, x), bisect.bisect_right(T, x)
    res = INF
    for s in [S[b-1], S[b]]:
      for t in [T[d-1], T[d]]:
        d1, d2 = abs(s-x) + abs(t-s), abs(t-x) + abs(s-t)
        res = min(res, d1, d2)
    print(res)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  A = list(map(int, input().split()))
  d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
  
  dp = [0 for _ in range(N+1)]
  for i in range(1, N+1):
    dpi = - float('inf')
    for a in A:
      if i % d[a] == 0:
        dpi = max(dpi, i // d[a])
      elif d[a] <= i:
        dpi = max(dpi, dp[i - d[a]] + 1)
    dp[i] = dpi

  ans = [0 for _ in range(dp[N])]
  for i in range(len(ans)):
    num = 0
    for a in A:
      if dp[N - d[a]] == dp[N] - 1:
        num = max(num, a)
    ans[i] = str(num)
    N -= d[num]

  print(''.join(ans))


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  A = list(map(int, input().split()))
  d = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
  
  dp = [0 for _ in range(N+1)]
  for i in range(1, N+1):
    dpi = - float('inf')
    for a in A:
      if d[a] <= i:
        dpi = max(dpi, dp[i - d[a]] + 1)
    dp[i] = dpi

  ans = [0 for _ in range(dp[N])]
  for i in range(len(ans)):
    num = 0
    for a in A:
      if (d[a] <= N) and (dp[N - d[a]] == dp[N] - 1):
        num = max(num, a)
    ans[i] = str(num)
    N -= d[num]

  print(''.join(ans))


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def get_bit_order(b):
  bo = format(b, 'b')
  return len(bo) - 1


def dp(A, N, K, start):
  ans = 0
  K_order = get_bit_order(K)
  S = 1 << (K_order - start)
  for b in range(40, -1, -1):
    power = 1 << b
    bit_count = sum([a & power != 0 for a in A])
    
    if (power <= S) and (N - bit_count >  bit_count):
      opt_count = N - bit_count
      S -= power
    else:
      opt_count = bit_count
    
    ans += power * opt_count
  return ans


def main():
  input = sys.stdin.readline
  N, K = map(int, input().split())
  A = [int(a) for a in input().split()]
  
  dp_from_1st_Kbit = dp(A, N, K, 0)
  dp_from_2nd_Kbit = dp(A, N, K, 1)

  ans = max(dp_from_1st_Kbit, dp_from_2nd_Kbit)
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def get_k_order(k):
  kb = format(k, 'b')
  return len(kb) - 1


def dp(A, N, K, start):
  ans = 0
  S = 1 << start
  for b in range(40, -1, -1):
    power = 1 << b
    bit_count = sum([a & power != 0 for a in A])
    
    if (power <= S) and (power <= K) and (N - bit_count >  bit_count):
      opt_count = N - bit_count
      K -= power
    else:
      opt_count = bit_count
    
    ans += power * opt_count
  return ans


def main():
  input = sys.stdin.readline
  N, K = map(int, input().split())
  A = [int(a) for a in input().split()]
  ko = get_k_order(K)
  
  dp_from_1st_order = dp(A, N, K, ko)
  if ko > 0:
    dp_from_2nd_order = dp(A, N, K, ko-1)
  else:
    dp_from_2nd_order = 0
  ans = max(dp_from_1st_order, dp_from_2nd_order)
  print(ans)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
c = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append((s, t))
  c.append(s + t)

taka = 0
aoki = 0
for i in range(n):
  p = c.index(max(c))
  x = a.pop(p)
  c.pop(p)
  
  if i % 2 == 0:
    taka += x[0]
  else:
    aoki += x[1]

print(taka - aoki)

Fixed submission:
n = int(input())
a = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append([s+t, s, t])

a = sorted(a, key=lambda x: -x[0])
taka = 0
aoki = 0
for i in range(n):
  if i % 2 == 0:
    taka += a[i][1]
  else:
    aoki += a[i][2]

print(taka - aoki)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = []
b = []
c = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append(s)
  b.append(t)
  c.append(s + t)

taka = 0
aoki = 0
for i in range(n):
  p = c.index(max(c))
  x = a.pop(p)
  y = b.pop(p)
  z = c.pop(p)
  
  if i % 2 == 0:
    taka += x
  else:
    aoki += y

print(taka - aoki)

Fixed submission:
n = int(input())
a = []
for _ in range(n):
  s, t = map(int, input().split())
  a.append([s+t, s, t])

a = sorted(a, key=lambda x: -x[0])
taka = 0
aoki = 0
for i in range(n):
  if i % 2 == 0:
    taka += a[i][1]
  else:
    aoki += a[i][2]

print(taka - aoki)
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  A = int(input())
  B = int(input())
  if N == 1:
    print('Hello World')
  else:
    print(A + B)


if __name__ == '__main__':
  main()

Fixed submission:
import sys
 
def main():
  input = sys.stdin.readline
  N = int(input())
  if N == 1:
    print('Hello World')
  else:
    A = int(input())
    B = int(input())
    print(A + B)
 
 
if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def is_center(x, y, P):
  H = [abs(x-p[0]) + abs(y-p[1]) + p[2] for p in P]
  return len(set(H)) == 1

def main():
  input = sys.stdin.readline
  N = int(input())
  P = [[0, 0, 0] for _ in range(N)]
  for i in range(N):
    x, y, h = map(int, input().split())
    P[i][0], P[i][1], P[i][2] = x, y, h
  for i in range(101):
    for j in range(101):
      if is_center(i, j, P):
        h = abs(i - P[0][0]) + abs(j - P[0][1]) + P[0][2]
        ans = '{} {} {}'.format(i, j, h)
        break
 
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def is_center(x, y, P):
  H = [abs(x-p[0]) + abs(y-p[1]) + p[2] for p in P if p[2] != 0]
  return H


def center(C, P):
  for c in C:
    check = [p[2] == max(c[2] - abs(p[0] - c[0]) - abs(p[1] - c[1]), 0) for p in P]
    if all(check):
      return '{} {} {}'.format(c[0], c[1], c[2])

def main():
  input = sys.stdin.readline
  N = int(input())
  P = [[0, 0, 0] for _ in range(N)]

  for i in range(N):
    x, y, h = map(int, input().split())
    P[i][0], P[i][1], P[i][2] = x, y, h

  C = []
  for i in range(101):
    for j in range(101):
      H = is_center(i, j, P)
      if len(set(H)) == 1:
        C.append([i, j, H[0]])
  
  ans = center(C, P)
  print(ans)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  T = str(input().strip())
  for i in range(len(S)):
    if S[i] == T[i]:
      continue
    else:
      c1, c2 = S[i], T[i]
      S = S.replace(c1, ' ')
      S = S.replace(c2, c1)
      S = S.replace(' ', c2)
  
  if S == T:
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  T = str(input().strip())
  
  C1, C2 = [], []
  ans = 'Yes'
  S2T = dict()
  T2S = dict()
  for c1, c2 in zip(S, T):
    if (c1 in S2T) and (c2 in T2S):
      if (S2T[c1] == c2) and (T2S[c2] == c1):
        continue
      else:
        ans = 'No'
        break
    elif (c1 in S2T):
      if S2T[c1] == c2:
        T2S[c2] = c1
        continue
      else:
        ans = 'No'
        break
    elif (c2 in T2S):
      if T2S[c2] == c1:
        S2T[c1] == c2
        continue
      else:
        ans = 'No'
        break
    else:
      S2T[c1] = c2
      T2S[c2] = c1
  print(ans)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
aimport sys

def main():
  input = sys.stdin.readline
  a, b = map(int, input().split())
  if (a % 2 == 1) and (b % 2 == 1):
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  a, b = map(int, input().split())
  if (a % 2 == 1) and (b % 2 == 1):
    print('Yes')
  else:
    print('No')


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  min_C = min(C)
  ans = 1
  for i in range(min_C, 1, -1):
    if all([c % i == 0 for c in C]):
      ans = i
      break
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N, S = map(int, input().split())
  C = list(map(int, input().split()))
  C = list(set([abs(c - S) for c in C]))
  min_C = min(C)
  ans = 1
  for i in range(min_C, 1, -1):
    if min_C % i != 0:
      continue
    
    if all([c % i == 0 for c in C]):
      ans = i
      break
  print(ans)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  x1, y1, x2, y2 = map(int, input().split())

  x4 = -(y2 - y1) + x1
  y4 = (x2 - x1) + y1
  x3 = x2 + x4 - x1
  y3 = y2 + y4 - y1
  print('{} {} {} {}'.format(x3, y3, x4, y4)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  x1, y1, x2, y2 = map(int, input().split())

  x4 = -(y2 - y1) + x1
  y4 = (x2 - x1) + y1
  x3 = x2 + x4 - x1
  y3 = y2 + y4 - y1
  print('{} {} {} {}'.format(x3, y3, x4, y4))


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  n, i = map(int, input().split())
  print(N-i+1)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  n, i = map(int, input().split())
  print(n-i+1)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  ans = 0
  for c in S:
    if c == +:
      ans += 1
    else:
      ans -= 1
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  ans = 0
  for c in S:
    if c == '+':
      ans += 1
    else:
      ans -= 1
  print(ans)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def S(n):
  return n / sum(map(int, str(n)))


def f(n):
  d = 0
  C = [n]
  while S(n) > (10**(d-1) / (9*d)):
    c = 10**(d+1) * (n // 10**(n+1) + 1) - 1
    C.append(c)
  
  Smin = float('inf')
  res = 0
  for c in C:
    if S(c) < Smin:
      res = c  
  return res
  
def main():
  input = sys.stdin.readline
  K = int(input())
  ans = 1
  while _ in range(K):
    print(ans)
    ans = f(ans+1)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def S(n):
  return n / sum(map(int, str(n)))


def f(n):
  d = 0
  C = [n]
  while S(n) > (10**d / 9*(d+1)):
    c = 10**(d+1) * (n // 10**(d+1) + 1) - 1
    C.append(c)
    d += 1
  Smin = float('inf')
  res = 0
  for c in C:
    if S(c) < Smin:
      Smin = S(c)
      res = c  
  return res


def main():
  input = sys.stdin.readline
  K = int(input())
  ans = 1
  for _ in range(K):
    print(ans)
    ans = f(ans+1)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  cur = N
  for i in range(N):
    j = i + 1
    s = A[i]
    while j < N:
      if s & A[j] == 0:
        cur += 1
        s += A[j]
        j += 1
      else:
        break
  print(cur)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  
  a = 0
  s = A[0]
  cur = 0
  right = 1
  for left in range(N):
    while right < N and s & A[right] == 0:
      s += A[right]
      right += 1
    cur += right - left
    s -= A[left]

  print(cur)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
  input = sys.stdin.readline
  X = int(input())
  while X > 0:
    index = []
    for i in range(2, X):
      c = 0
      x = X
      while x % i == 0 and x > 1:
        c += 1
        x //= i
      if c != 0:
        index.append(c)
    if len(index) == 0:
      X -= 1
    elif len(set(index)) == 1 and index[0] != 1:
      ans = X
      break
    elif all([i % 2 == 0 for i in index]):
      ans = X
      break
    else:
      X -= 1
  print(ans)


if __name__ == '__main__':
  main()

Fixed submission:
import sys

def main():
  input = sys.stdin.readline
  X = int(input())
  cur = 0
  for i in range(2, 11):
    for j in range(1, X+1):
      if int(j**i) <= X:
        cur = max(cur, int(j**i))
  print(cur)



if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
from math import factorial

def comb(a, b):
  return factorial(a) / (factorial(b) * factorial(a-b))


def f(A, a):
  if len(A) == 1:
    return A[0]
  
  if len(A) == 2:
    b1, b2 = A[0], A[1]
    if comb(a, b1) >= comb(a, b2):
      return b1
    else:
      return b2
  
  m = len(A) // 2
  b1, b2, b3 = A[m-1], A[m], A[m+1]
  c1, c2, c3 = comb(a, b1), comb(a, b2), comb(a, b3)
  c = max(c1, c2, c3)  
  
  if c2 == c:
    return b2
  elif c1 == c:
    return f(A[:m], a)
  else:
    return f(A[m+1:], a)


def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  ai = A[-1]
  A = A[:-1]
  aj = f(A, ai)
  print(ai, aj)


if __name__ == '__main__':
  main()

Fixed submission:
import sys
from math import factorial

def comb(a, b):
  return factorial(a) / (factorial(b) * factorial(a-b))


def f(A, a):
  if len(A) == 1:
    return A[0]
  
  if len(A) == 2:
    b1, b2 = A[0], A[1]
    if min(b1, a-b1) >= min(b2, a-b2):
      return b1
    else:
      return b2
  
  m = len(A) // 2
  b1, b2, b3 = A[m-1], A[m], A[m+1]
  c1, c2, c3 = min(b1, a-b1), min(b2, a-b2), min(b3, a-b3)
  c = max(c1, c2, c3)  
  
  if c2 == c:
    return b2
  elif c1 == c:
    return f(A[:m], a)
  else:
    return f(A[m+1:], a)


def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  A = sorted(A)
  ai = A[-1]
  A = A[:-1]
  aj = f(A, ai)
  print(ai, aj)


if __name__ == '__main__':
  main()
Buggy python submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    if K == 0:
        print(N * N)
        break
    for i in range(1, N+1):
        if i <= K:
            continue
        if N % i < K:
            ans += (N // i) * (i - K)
        else:
            ans += (N // i ) * (i - K) + (N % i - K + 1)
    print(ans)


if __name__ == '__main__':
    main()


Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    ans = 0
    if K == 0:
        print(N * N)
        return 0
    for i in range(1, N+1):
        if i <= K:
            continue
        if N % i < K:
            ans += (N // i) * (i - K)
        else:
            ans += (N // i ) * (i - K) + (N % i - K + 1)
    print(ans)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
4
20 18 2 18

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    A = sorted(A, key=lambda x: -x)
    a, b = 0, 0
    for i in range(N):
        if i % 2 == 0:
            a += A[i]
        else:
            b += A[i]
    print(a-b)


if __name__ == '__main__':
    main()