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

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 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())
Problem p03000 (python)

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 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())
Problem p03008 (python)

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    dp = [0] * (N+1)
    for i in range(1, N+1):
        gold, silver, copper = 0, 0, 0
        if i >= A[0]:
            gold = dp[i-A[0]] + B[0]
        if i >= A[1]:
            silver = dp[i-A[1]] + B[1]
        if i >= A[2]:
            copper = dp[i-A[2]] + B[2]
        dp[i] = max(i, gold, silver, copper)

    M = dp[N]
    dp = [0] * (M+1)
    for i in range(1, M+1):
        gold, silver, copper = 0, 0, 0
        if i >= B[0]:
            gold = dp[i-B[0]] + A[0]
        if i >= B[1]:
            silver = dp[i-B[1]] + A[1]
        if i >= B[2]:
            copper = dp[i-B[2]] + A[2]
        dp[i] = max(i, gold, silver, copper)

    return dp[M]


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

Buggy submission (verdict: Runtime Error):
import sys

def trade(n, a, b):
    a0, a1, a2 = a
    b0, b1, b2 = b
    dp = [0] * (n+1)
    for i i range(1, n+1):
        gold, silver, copper = 0, 0, 0
        if i >= a0:
            gold = dp[i-a0] + b0
        if i >= a1:
            silver = dp[i-a1] + b1
        if i >= a2:
            copper = dp[i-a2] + b2
        dp[i] = max(i, gold, silver, copper)

    return dp[n]


def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    # Trade A -> B
    M = trade(N, A, B)
    # Trade B -> A
    return trade(M, B, A)


if __name__ == '__main__':
    print(main())
Problem p03039 (python)

Fixed submission:
import sys
from itertools import combinations

def comb_mod(n, r, MOD=10**9+7):
    if n < 0 or r < 0 or n < r:
        return 0

    factrial = [1] * (n+1)
    for k in range(1, n+1):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (n+1)
    fact_inv[n] = pow(factrial[n], MOD - 2, MOD)
    for k in range(n-1, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD


def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M, K = map(int, input().split())

    # The number of times that pieces are located on certain two tiles.
    num = comb_mod(N*M-2, K-2)

    ans = 0
    # Column-wise distance
    for i in range(M):
        ans += i * (M - i) * N**2 * num
        ans %= MOD

    # Row-wise distance
    for i in range(N):
        ans += i * (N - i) * M**2 * num
        ans %= MOD

    return ans


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

Buggy submission (verdict: Runtime Error):
import sys
from itertools import combinations
try:
    from scipy.special import comb
except ImportError:
    from scipy.misc import comb

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M, K = map(int, input().split())
    # The number of times that pieces are located on certain two tiles.
    num = int(comb(N*M-2, K-2))

    ans = 0
    # Column-wise distance
    for a, b in combinations(range(M), 2):
        ans += abs(a - b) * N**2 * num
        ans %= MOD

    # Row-wise distance
    for a, b in combinations(range(N), 2):
        ans += abs(a - b) * M**2 * num
        ans %= MOD

    return ans


if __name__ == '__main__':
    print(main())
Problem p03049 (python)

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    ba = 0  # Num. of str that the first letter is B and the last one is A.
    xa = 0  # Num. of str that the last letter is A and the first one is not B.
    bx = 0  # Num. of str that the first letter is B and the last one is not A.
    for _ in range(N):
        s = str(input().strip())

        # Count the number of AB contained in the initial strings.
        for i in range(len(s)):
            if s[i:i+2] == 'AB':
                ans += 1

        if s[0] == 'B' and s[-1] == 'A':
            ba += 1
        elif s[-1] == 'A':
            xa += 1
        elif s[0] == 'B':
            bx += 1

    if ba == 0:
        # One xa ans one bx make one new "AB".
        #   xa + bx -> xABx
        ans += min(xa, bx)

    elif max(xa, bx) == 0:
        # N of ba make N-1 new "AB".
        # BxxA + BxxA + ... + BxxA -> BxxABxxAB...ABxxA
        ans += ba - 1

    else:  # There is at least one bx or ax and at least one ba.
        # N of ba make N-1 new "AB" and a ba.
        #   ba + ba + ... + ba -> baba...ba = ba
        # The last remaining ba and bx/ax make a new "AB" and a new bx/ax.
        #   ba + bx -> bABx = bx,  xa + ba -> xABa = xa
        # Then, bx and xa make a new "AB".
        #   xa + bx -> xABx 
        ans += ba + min(xa, bx)

    return ans


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

Buggy submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    ba = 0  # Num. of str that the first letter is B and the last one is A.
    xb = 0  # Num. of str that the last letter is B and the first one is not A.
    ax = 0  # Num. of str that the first letter is A and the last one is not B.
    for _ in range(N):
        s = str(input().strip())

        # Count the number of AB contained in the initial strings.
        for i in range(len(s)):
            if s[i:i+2] == 'AB':
                ans += 1

        if s[0] == 'B' and s[-1] == 'A':
            ba += 1
        elif s[0] == 'B':
            xb += 1
        elif s[-1] == 'A':
            ax += 1

    if max(xb, ax) == 0:
        # N of ba make N-1 new "AB".
        # BxxA + BxxA + ... + BxxA -> BxxABxxAB...ABxxA
        ans += ba - 1

    else:  # There is at least one bx or ax.
        # N of ba make N-1 new "AB" and a ba.
        #   ba + ba + ... + ba -> baba...ba = ba
        # The last remaining ba and bx/ax make a new "AB" and a new bx/ax.
        #   ba + bx -> bABx = bx,  xa + ba -> xABa = xa
        # Then, bx and xa make a new "AB".
        #   xa + bx -> xABx 
        ans += ba + min(xa, bx)

    return ans


if __name__ == '__main__':
    print(main())
Problem p03076 (python)

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 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())
Problem p03078 (python)

Fixed submission:
import sys
from heapq import heappush, heappop

def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = sorted(list(map(int, input().split())), key=lambda x: -x)
    B = sorted(list(map(int, input().split())), key=lambda x: -x)
    C = sorted(list(map(int, input().split())), key=lambda x: -x)

    deli = []
    heappush(deli, (-A[0]-B[0]-C[0], 0, 0, 0))
    pushed = set((0,0,0))
    for _ in range(K):
        d = heappop(deli)
        i, j, k = d[1], d[2], d[3]

        if i+1 < X and (i+1, j, k) not in pushed:
            heappush(deli, (-A[i+1]-B[j]-C[k], i+1, j, k))
            pushed.add((i+1, j, k))

        if j+1 < Y and (i, j+1, k) not in pushed:
            heappush(deli, (-A[i]-B[j+1]-C[k], i, j+1, k))
            pushed.add((i, j+1, k))

        if k+1 < Z and (i, j, k+1) not in pushed:
            heappush(deli, (-A[i]-B[j]-C[k+1], i, j, k+1))
            pushed.add((i, j, k+1))

        print(-d[0])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from itertools import product

def main():
    input = sys.stdin.readline
    X, Y, Z, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A = sorted(A, key=lambda x: -x) + [-10**9]
    B = sorted(B, key=lambda x: -x) + [-10**9]
    C = sorted(C, key=lambda x: -x) + [-10**9]

    diffA = [A[i] - A[i+1] for i in range(X)]
    diffB = [B[i] - B[i+1] for i in range(Y)]
    diffC = [C[i] - C[i+1] for i in range(Z)]

    A_ = [A[0]]
    B_ = [B[0]]
    C_ = [C[0]]
    i, j, k = 0, 0, 0
    while (len(A_) * len(B_) * len(C_)) < 10**5:
        a, b, c = diffA[i], diffB[j], diffC[k]

        if min(a, b, c) >= 10**4:
            break

        if a == min(a, b, c):
            A_.append(A[i+1])
            i += 1
        if b == min(a, b, c):
            B_.append(B[j+1])
            j += 1
        if c == min(a, b, c):
            C_.append(C[k+1])
            k += 1

    deli= []
    for a in A_:
        for b in B_:
            for c in C_:
                deli.append(a + b + c)

    deli = sorted(deli, key=lambda x: -x)
    for i in range(K):
        print(deli[i])


if __name__ == '__main__':
    main()
Problem p03112 (python)

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 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()
Problem p03128 (python)

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 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()
Problem p03138 (python)

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 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()
Problem p03148 (python)

Fixed submission:
import sys

def point(sushi, n, k):
  sushi = sorted(sushi, key=lambda x:-x[1])
  
  ate_t = set()
  dpoint = 0
  dup = []
  for s in sushi[:k]:
    t = s[0]
    d = s[1]
    if t in ate_t:
      dup.append(d)
    ate_t.add(t)
    dpoint += d
  
  ans = len(ate_t)**2 + dpoint
  
  for s in sushi[k:]:
    t = s[0]
    d = s[1]
    if len(dup) <= 0:
      break
    if t in ate_t:
      continue
    ate_t.add(t)
    rm = dup.pop()
    dpoint = dpoint - rm + d
    res = len(ate_t)**2 + dpoint
    ans = max(ans, res)
  
  return ans

def main():
  input = sys.stdin.readline
  n, k = map(int, input().split())
  sushi = []
  for _ in range(n):
    t, d = map(int, input().split())
    sushi.append([t,d])
  print(point(sushi, n, k))


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def point(sushi):
  d = 0
  t = []
  for s in sushi:
    d += s[1]
    t.append(s[0])
  return d + len(set(t))**2


def rm_ate(sushi, rest):
  t = set([s[0] for s in sushi])
  return [r for r in rest if not r[0] in t]


def rm_dup(sushi):
  sushi = sorted(sushi, key=lambda x:-x[1])
  d = []
  r = []
  for s in sushi:
    if s[0] in d:
      r.append(s)
    else:
      d.append(s[0])
  sushi.remove(r[-1])
  return sushi


def main():
  input = sys.stdin.readline
  n, k = map(int, input().split())
  sushi = []
  for _ in range(n):
    t, d = map(int, input().split())
    sushi.append([t,d])
  sushi = sorted(sushi, key=lambda x:x[1])
  temp = sushi[-k:]
  rest = rm_ate(temp, sushi[:-k])
  ans = point(temp)
  while rest:
    temp = rm_dup(temp)
    temp += [rest.pop()]
    res = point(temp)
    ans = max(ans, res)
    rest = rm_ate(temp, rest)
  print(ans)


if __name__ == '__main__':
  main()
Problem p03238 (python)

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 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()
Problem p03240 (python)

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 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()
Problem p03260 (python)

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 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()
Problem p03318 (python)

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 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()
Problem p03352 (python)

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 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()
Problem p03418 (python)

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 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()
Problem p03434 (python)

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()

Buggy submission (verdict: Runtime Error):
4
20 18 2 18