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

Fixed submission:
n = int(input())
xy = [tuple(map(int, input().split())) for i in range(n)]
ans = n

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    xt = xy[i][0]-xy[j][0]
    yt = xy[i][1]-xy[j][1]
    tmp = n
    for k in range(n):
      if (xy[k][0]+xt, xy[k][1]+yt) in xy:
        tmp -= 1
    ans = min(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
xy.sort()
s = defaultdict(int)
for i in range(n-1):
  s[(xy[i+1][0]-xy[i][0], xy[i+1][1]-xy[i][1])] += 1
m = max(s.values())
ans = 1 + (n-m-1)
print(ans)
Problem p03026 (python)

Fixed submission:
n = int(input())
from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
graph = defaultdict(list)
edge = []
for i in range(n-1):
  a, b = list(map(int, input().split()))
  edge.append((a, b))
  graph[a].append(b)
  graph[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
visited = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
score = 0

def dfs(x):
  visited[x] = 1
  for next_ in graph[x]:
    if visited[next_]:
      continue
    dfs(next_)
  if all(visited[i] for i in graph[x]):
    ans[x] = c.pop()
    return
  visited[x] = 0

dfs(1)
for a, b in edge:
  score += min(ans[a], ans[b])
print(score)
print(*ans[1:])

Buggy submission (verdict: Runtime Error):
n = int(input())
from collections import defaultdict
graph = defaultdict(list)
edge = []
for i in range(n-1):
  a, b = list(map(int, input().split()))
  edge.append((a, b))
  graph[a].append(b)
  graph[b].append(a)
c = list(map(int, input().split()))
c.sort(reverse=True)
visited = [0 for i in range(n+1)]
ans = [0 for i in range(n+1)]
score = 0

def dfs(x):
  visited[x] = 1
  for next_ in graph[x]:
    if visited[next_]:
      continue
    dfs(next_)
  if all(visited[i] for i in graph[x]):
    ans[x] = c.pop()
    return
  visited[x] = 0

dfs(1)
for a, b in edge:
  score += min(ans[a], ans[b])
print(score)
print(*ans[1:])
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+1)
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**4)

n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if nexts is None:
    return
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))

Buggy submission (verdict: Runtime Error):
n = int(input())
if n==1:
  print(0)
  exit()
from collections import defaultdict
edge = defaultdict(list)
for i in range(n-1):
  u, v, w = list(map(int, input().split()))
  edge[u].append((v, w))
  edge[v].append((u, w))
graph = [-1 for i in range(n+1)]

def dfs(x, c):
  nexts = edge.get(x)
  if graph[x]!=-1:
    return
  else:
    graph[x] = c
  for y, w in nexts:
    if w%2:
      dfs(y, not c)
    else:
      dfs(y, c)

dfs(1, 0)
for i in range(1, n+1):
  print(int(graph[i]))
Problem p03050 (python)

Fixed submission:
n = int(input())
ans = 0
if n==1 or n==2:
  print(0)
  exit()
elif n<6:
  print(n-1)
  exit()
for i in range(1, int(n**(1/2))+2):
  k = (n-i)//i
  if n%k == n//k:
    ans += k
print(ans)

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

Fixed submission:
s = input()
from string import ascii_lowercase
a = ascii_lowercase
if s == a[::-1]:
  print(-1)
else:
  if len(set(s))<26:
    for ele in a:
      if ele not in s:
        print(s+ele)
        break
  else:
    suf=[s[-1]]
    for i in range(25, 0, -1):
      if s[i]<s[i-1]:
        suf.append(s[i-1])
      else:
        last = i-1
        break
    suf.sort()
    for i in range(len(suf)):
      if s[last]<suf[i]:
        print(s[:last]+suf[i])
        break

Buggy submission (verdict: Runtime Error):
s = input()
alphabet = ["abcdefghijklmnopqrstuvwxyz"]
if s == str(alphabet[::-1]):
  print(-1)
else:
  if len(set(s))<26:
    for ele in alphabet:
      if ele not in s:
        print(s+ele)
        break
  else:
    suf=[s[-1]]
    for i in range(len(s)-1, 0, -1):
      if s[i]<s[i-1]:
        suf.append(s[i-1])
      else:
        last = i-1
        break
    suf.sort()
    for i in range(len(suf)):
      if s[last]<suf[i]:
        print(s[:last]+suf[i])
        break
Problem p03503 (python)

Fixed submission:
n = int(input())
ans = float("-INF")
f = [[0 for i in range(10)] for i in range(n)]
p = [[0 for i in range(11)] for i in range(n)]
for i in range(n):
  ft = list(map(int, input().split()))
  for j in range(10):
    f[i][j] = ft[j]
for i in range(n):
  pt = list(map(int, input().split()))
  for j in range(11):
    p[i][j] = pt[j]

for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f[j][k]:
        c += 1
    t += p[j][c]
  ans = max(ans, t)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = float("-INF")
f = [[0 for i in range(10)] for i in range(n)]
p = [[0 for i in range(10)] for i in range(n)]
for i in range(n):
  ft = list(map(int, input().split()))
  for j in range(10):
    f[i][j] = ft[j]
for i in range(n):
  pt = list(map(int, input().split()))
  for j in range(10):
    p[i][j] = pt[j]

for i in range(1, 2**10):
  t = 0
  for j in range(n):
    c = 0
    for k in range(10):
      if i>>k&1 and f[j][k]:
        c += 1
    t += p[j][c]
  ans = max(ans, t)
print(ans)
Problem p03633 (python)

Fixed submission:
n = int(input())
t = [int(input()) for i in range(n)]

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

def lcm(a, b):
  g = gcd(a, b)
  return a*b//g

ans = 1
for i in range(n):
  ans = lcm(ans, t[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for i in range(n)]

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

def lcm(a, b):
  g = gcd(a, b)
  return a/g*b

ans = 1
for i in range(n):
  ans = lcm(ans, t[i])
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for i in range(n)]

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

def lcm(a, b):
  g = gcd(a, b)
  return a*b/g

ans = 1
for i in range(n):
  ans = lcm(ans, t[i])
print(int(ans))

Buggy submission (verdict: Runtime Error):
n = int(input())
t = [int(input()) for i in range(n)]

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

l = t[0]*t[1]/gcd(t[0], t[1])
for i in range(2, n):
  l = t[i]*l/gcd(t[i], l)
print(int(l))
Problem p03674 (python)

Fixed submission:
MOD = 10**9+7

def mod_pow(x, n):
  if x==0: return 1
  res = 1
  while n > 0:
    if n&1:
      res = (res*x)%MOD
    x = (x*x)%MOD
    n >>= 1
  return res

fact, invfact = [0]*(10**5+2), [0]*(10**5+2)
fact[0], invfact[0] = 1, 1
for i in range(1, 10**5+2):
  fact[i] = (fact[i-1]*i)%MOD
  invfact[i] = mod_pow(fact[i], MOD-2)%MOD

def comb(n, r):
  if n<r or n==0 or r==0: return 0
  return (((fact[n]*invfact[r])%MOD)*invfact[n-r])%MOD

from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i, ele in enumerate(a):
  if d[ele] == 0:
    d[ele]= i+1
  else:
    l = d[ele]
    r = i+1

print(n)
for k in range(2, n+2):
  print((comb(n+1, k)-comb(l-1+n-r+1, k-1))%MOD)

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7

def mod_pow(x, n):
  if x==0: return 1
  res = 1
  while n > 0:
    if n&1:
      res = (res*x)%MOD
    x = (x*x)%MOD
    n >>= 1
  return res

fact, invfact = [0]*(10**5+1), [0]*(10**5+1)
fact[0], invfact[0] = 1, 1
for i in range(1, 10**5+1):
  fact[i] = (fact[i-1]*i)%MOD
  invfact[i] = mod_pow(fact[i], MOD-2)%MOD

def comb(n, r):
  if n<r or n==0 or r==0: return 0
  return (((fact[n]*invfact[r])%MOD)*invfact[n-r])%MOD

from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i, ele in enumerate(a):
  if d[ele] == 0:
    d[ele]= i+1
  else:
    l = d[ele]
    r = i+1

print(n)
for k in range(2, n+2):
  print((comb(n+1, k)-comb(l-1+n-r+1, k-1))%MOD)
Problem p04015 (python)

Fixed submission:
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
y = [ele-a for ele in x]
m = n*max(a, max(x))
dp = [[0 for _ in range(2*m+1)]for _ in range(n+1)]
dp[0][m] = 1
for j in range(1, n+1):
  for t in range(2*m+1):
    if t-y[j-1]<0 or 2*m<t-y[j-1]:
      dp[j][t] = dp[j-1][t]
    elif 0<=t-y[j-1]<=2*m:
      dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j-1]]
print(dp[n][m]-1)

Buggy submission (verdict: Runtime Error):
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
dp = [[[0 for _ in range(n*max(x)+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for j in range(1, n+1):
  for k in range(n+1):
    for s in range(n*max(x)+1):
      if s<x[j-1]:
        dp[j][k][s] = dp[j-1][k][s]
      elif k>=1:
        dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
ans = 0
for i in range(1, n+1):
  ans += dp[n][i][i*a]
print(ans)

Buggy submission (verdict: Runtime Error):
n, a = list(map(int, input().split()))
x = list(map(int, input().split()))
dp = [[[0 for _ in range(n*max(x)+1)] for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1

for j in range(1, n+1):
  for k in range(n+1):
    for s in range(n*max(x)+1):
      if s<x[j-1]:
        dp[j][k][s] = dp[j-1][k][s]
      elif k>=1:
        dp[j][k][s] = dp[j-1][k][s]+dp[j-1][k-1][s-x[j-1]]
ans = 0
for i in range(1, n+1):
  ans += dp[n][i][i*a]
print(ans)
Problem p03288 (python)

Fixed submission:
rating = int(input())
if rating >= 0 and rating < 1200:
    print('ABC')
elif rating >= 1200 and rating < 2800:
    print('ARC')
else:
    print('AGC')

Buggy submission (verdict: Runtime Error):
rating = input()
if rating >= 0 and rating < 1200:
    print('ABC')
elif rating >= 1200 and rating < 2800:
    print('ARC')
else:
    print('AGC')
Problem p03293 (python)

Fixed submission:
S = input()
T = input()

for i in range(0,len(S)):
    if S == T:
        print('Yes')
        break
    else:
        T = T[len(T)-1]+T[0:len(T)-1]
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
flg = True
for i in range(0,len(S)):
    if S == T:
        print('Yes')
        break
    else:
        T = T[len(T)]+T[1:]
else:
    print('No')

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

for i in range(0,len(S)):
	if S[i] == T[-i]:
		continue
	else:
		print('No')
		return

print('Yes')
Problem p03309 (python)

Fixed submission:
import math
import statistics
import numpy as np
size = int(input())
A = np.array(list(map(int,input().split())))
i = np.array(list(range(1,size+1)))

remain_list = A-i
median = statistics.median(remain_list)
print(int(sum(abs(remain_list - median))))

Buggy submission (verdict: Runtime Error):
import math
import statistics
import numpy as np
size = int(input())
A = np.array(list(map(int,input().split())))
i = np.array(list(range(1,size+1)))

remain_list = A-i
median = statistics.median(remain_list)
print(sum(remain_list - median))A

Buggy submission (verdict: Runtime Error):
import math
import statistics
import numpy as np
size = int(input())
A = np.array(list(map(int,input().split())))
i = np.array(list(range(1,size+1)))

remain_list = A-i
median = statistics.median(remain_list)
print(sum(remain_list - median))A
Problem p03323 (python)

Fixed submission:
numA,numB = map(int,input().split())
if(numA <=8 and numB <= 8):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
numA numB = input()
if(numA <=8 and numB <= 8):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
numA numB = input()
if(numA <=8 and numB <= 8):
    print('Yay!')
else:
    print(':(')

Buggy submission (verdict: Runtime Error):
numA numB = input()
if(numA <=8 and numB <= 8):
    print('Yay!')
else:
    print(':(')
Problem p03324 (python)

Fixed submission:
D,N =map(int,input().split())
if D ==0 and N <100:
    print(N)
elif D ==0 and N ==100:
    print(N+1)
elif D == 1 and N <100:
    print(N*100)
elif D ==1 and N ==100:
    print((N+1)*100)

elif D == 2 and N <100:
    print(10000*N)
elif D == 2 and N==100:
    print((N+1)*10000)

Buggy submission (verdict: Runtime Error):
D,N =map(int,input().split())
if D ==0:
    print(N)
elif D == 1 and N <100:
    print(N*100)
elif D ==1 and N ==100:
    print(N+1)*100

elif D == 2 and N <100:
    print(10000*N)
elif D == 2 and N==100:
    print(N+1)*100

Buggy submission (verdict: Runtime Error):
D N =input()
if D ==0:
    print(N)
elif D == 1:
    print(N*100)
elif D == 2:
    print(N*10000)
Problem p02573 (python)

Fixed submission:
class UnionFind(): # 0インデックス
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split()) # N人、M個の関係
    union_find = UnionFind(N)
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        union_find.union(A, B)

    answer = 0
    for i in range(N):
        answer = max(answer, union_find.size(i))

    print(answer)

Buggy submission (verdict: Runtime Error):
N=list(map(int,input().split()))
n=N[0]
m=N[1]
A = []
for i in range(m):
  array = list(map(int,input().split()))
  array.sort()
  A.append(array)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

X=get_unique_list(A)

import collections

t = map(tuple,X)
counted = collections.Counter(t)
mode=counted.most_common()[0][0]

c=1
for j in range(len(X)):
  if mode[0] in X[j]:
    c+=1
 
    
print(c)
Problem p02830 (python)

Fixed submission:
N = int(input() )
S, T = map(str, input().split())

newword = []
for num in range(len(S)):
    newword.append(S[num])
    newword.append(T[num])
word = ""
for i in newword:
    word+=i
print(word)

Buggy submission (verdict: Runtime Error):
N = int(input() )
S, T = map(str, input().split())
print(S + T
Problem p03024 (python)

Fixed submission:
S = list(input())

#勝利数
win = S.count("o")
#これから勝つ必要のある試合
korekara = 8 - win
#戦った試合
match = len(S)
#残り試合
nokori = 15 - match

if korekara <= 0:
    print("YES")
elif nokori >= korekara:
    print("YES")
else:
    print("NO")

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


#勝利数
win = S.count("o")
#これから勝つ必要のある試合
korekara = 8 - win
#戦った試合
match = len(S)
#残り試合
nokori = 15 - match

if korekara <= 0:
    print("YES")
elif nokori => korekara:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S = list(input())
#勝利数
win = S.count("o")
#これから勝つ必要のある試合
korekara = 8 - win
#戦った試合
match = len(S)
#残り試合
nokori = 15 - match

if korekara <= 8:
    print("YES")
elif nokori => korekara:
    print("YES")
else:
    print("NO")
Problem p03035 (python)

Fixed submission:
a,b = map(int,input().split())
if b%2 ==0 :
    if a >= 13:
        print(b)
    elif 12 >= a >= 6:
        print(int(b/2))
    else:
        print(0)
else:
    pass

Buggy submission (verdict: Runtime Error):
if a >= 13:
    print(b)
elif 12 >= a >= 6:
    print(int(b/2))
else:
    print(0)
Problem p02717 (python)

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

Buggy submission (verdict: Runtime Error):
X=int(input())
Y=int(input())
Z=int(input())
X ^= Z
Z ^= X
X ^= Z

Y ^= Z
Z ^= Y
Y ^= Z
print(X,Y,Z)

Buggy submission (verdict: Runtime Error):
X=int(input())
Y=int(input())
Z=int(input())
X, Y, Z = Z, X, Y
print(X,Y,Z)

Buggy submission (verdict: Runtime Error):
X=int(input())
Y=int(input())
Z=int(input())
b=X
X=Z
Z=b
c=Z
Z=Y
Y=c
print(X,Y,Z)
Problem p02609 (python)

Fixed submission:
n = int(input())
s = input()[::-1]
cnt = s.count('1')

p1 = sum(pow(2, i, cnt+1) * (s[i] == '1') for i in range(n))
if cnt > 1:
    m1 = sum(pow(2, i, cnt-1) * (s[i] == '1') for i in range(n))

def op(n):
    popcnt = bin(n).count('1')
    return n%popcnt

pre = [0]*1000000
for i in range(1,1000000):
    pre[i] = pre[op(i)] + 1

def solve(i):
    if s[-i] == '0':
        r = (p1 + pow(2, n-i, cnt+1))%(cnt+1)
    else:
        if cnt == 1:
            return 0
        r = (m1 - pow(2, n-i, cnt-1))%(cnt-1)
    return 1 + pre[r]

for i in range(n):
    print(solve(i+1))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()[::-1]
cnt = s.count('1')

p1 = sum(pow(2, i, cnt+1) * (s[i] == '1') for i in range(n))
if cnt > 1:
    m1 = sum(pow(2, i, cnt-1) * (s[i] == '1') for i in range(n))

def op(n):
    popcnt = bin(n).count('1')
    return n%popcnt

pre = [0]*100000
for i in range(1,100000):
    pre[i] = pre[op(i)] + 1

def solve(i):
    if s[-i] == '0':
        r = (p1 + pow(2, n-i, cnt+1))%(cnt+1)
    else:
        if cnt == 1:
            return 0
        r = (m1 - pow(2, n-i, cnt-1))%(cnt-1)
    return 1 + pre[r]

for i in range(n):
    print(solve(i+1))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()[::-1]
cnt = s.count('1')

p1 = sum(pow(2, i, cnt+1) * (s[i] == '1') for i in range(n))
if cnt > 1:
    m1 = sum(pow(2, i, cnt-1) * (s[i] == '1') for i in range(n))

def op(n):
    popcnt = bin(n).count('1')
    return n%popcnt

pre = [0]*100000
for i in range(1,100000):
    pre[i] = pre[op(i)] + 1

def solve(i):
    if s[-i] == '0':
        r = (p1 + pow(2, n-i, cnt+1))%(cnt+1)
    else:
        if cnt == 1:
            return 1
        r = (m1 - pow(2, n-i, cnt-1))%(cnt-1)
    return 1 + pre[r]

for i in range(n):
    print(solve(i+1))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()[::-1]
cnt = s.count('1')

p1 = sum(pow(2, i, cnt+1) * (s[i] == '1') for i in range(n))
m1 = sum(pow(2, i, cnt-1) * (s[i] == '1') for i in range(n))

def op(n):
    popcnt = bin(n).count('1')
    return n%popcnt

pre = [0]*100000
for i in range(1,100000):
    pre[i] = pre[op(i)] + 1

def solve(i):
    if s[-i] == '0':
        r = (p1 + pow(2, n-i, cnt+1))%(cnt+1)
    else:
        if cnt == 1:
            return 1
        r = (m1 - pow(2, n-i, cnt-1))%(cnt-1)
    return 1 + pre[r]

for i in range(n):
    print(solve(i+1))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()[::-1]
cnt = s.count('1')

p1 = sum(pow(2, i, cnt+1) * (s[i] == '1') for i in range(n))
m1 = sum(pow(2, i, cnt-1) * (s[i] == '1') for i in range(n))

def op(n):
    popcnt = bin(n).count('1')
    return n%popcnt

pre = [0]*100000
for i in range(1,100000):
    pre[i] = pre[op(i)] + 1

def solve(i):
    t = list(s[::-1])
    t[i-1] = '1' if t[i-1]=='0' else '0'
    x = int(''.join(t), 2)

    if s[-i] == '0':
        r = (p1 + pow(2, n-i, cnt+1))%(cnt+1)
    else:
        if cnt == 1:
            return 1
        r = (m1 - pow(2, n-i, cnt-1))%(cnt-1)
    return 1 + pre[r]

for i in range(n):
    print(solve(i+1))
Problem p02696 (python)

Fixed submission:
a,b,n = map(int,input().split())
if b-1 <= n:
    cand = [b-1, n]
else:
    cand = [n]
print(max(a*x//b - a*(x//b) for x in cand))

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
print(max(a*x//b - a*(x//b) for x in list(range(b-1, n+1, b))[:1] + [n]))
Problem p02845 (python)

Fixed submission:
import sys

X = [0,0,0]

n = int(input())
A = [int(x) for x in input().split()]

res = 1
for a in A:
    res = res*X.count(a) % 1000000007
    if X.count(a):
        X[X.index(a)] += 1
    else:
        print(0)
        sys.exit(0)
print(res)

Buggy submission (verdict: Runtime Error):

X = [0,0,0]

n = int(input())
A = [int(x) for x in input().split()]

res = 1
for a in A:
    res = res*X.count(a) % 1000000007
    if X.count(a):
        X[X.index(a)] += 1
    else:
        assert False
print(res)
Problem p02957 (python)

Fixed submission:
a,b = map(int,input().split())
k = (a+b)//2

if abs(a-k) == abs(b-k):
    print(k)
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
# chessboard, manhattan distance even will noly be possible if parity is right

from math import sqrt
eps = 1e-5

# Utils
def solve2(A11,A12,A21,A22,b1,b2):
    """Solves a 2x2 matrix equation."""
    det = (A11*A22-A12*A21)
    if abs(det) < eps:
        return (None, None)

    return (1/det*(b1*A22-b2*A12), 1/det*(b2*A11-b1*A21))

def dot(a,b):
    """Returns the dot product"""
    return sum(a[i]*b[i] for i in range(len(a)))
    
def normalize(a):
    """Normalize vector to unit length"""
    norm = sqrt(dot(a,a))
    return tuple(x/norm for x in a)

def cross(a,b):
    """3D cross product"""
    return (a[1]*b[2] - a[2]*b[1],
            a[2]*b[0] - a[0]*b[2],
            a[0]*b[1] - a[1]*b[0])

# intpt,onsegment,t,s = ll_intersect(a,da,b,db)
def ll_intersect(a,da,b,db):
    """Given two segments, return line intersection, segments crossing and
       parameters at crossing"""
    dx, dy = a[0]-b[0], a[1]-b[1]
    s,t = solve2(db[0], -da[0], db[1], -da[1], dx, dy)

    if s == None:
        return (None, False, None, None)

    ipt = (a[0] + t*da[0], a[1] + t*da[1])
    
    # Epsilon treatment?
    if s < -eps or s > 1+eps or t < -eps or t > 1+eps:
        return (ipt, False, t, s)
    
    return (ipt, True, t, s)
    

def manhattan(x,y,s,t):
    return abs(x-s) + abs(y-t)

def main():
    k = int(input())
    xx,yy = map(int,input().split())
    if k % 2 == 0:
        if (xx+yy)%2:
            print('-1')
            return
    
    P = []

    while (xx,yy) != (0,0):
        P.append((xx,yy))
        if manhattan(0,0,xx,yy) <= 2*k:
            Sorig = [[(-k,0),(k,k)],
                    [(0,k),(k,-k)],
                    [(k,0),(-k,-k)],
                    [(0,-k),(-k,k)]]
            S = [[(pos[0]+xx,pos[1]+yy),diff] for pos,diff in Sorig]
            
            inter = []
            for pp,dd in S:
                for pp2,dd2 in Sorig:
                    pt,onseg,_,_ = ll_intersect(pp,dd,pp2,dd2)
                    if onseg:
                        ix,iy = pt
                        if (ix - round(ix)) < eps and (iy - round(iy)) < eps:
                            inter.append((int(round(ix)),int(round(iy))))

            for ix,iy in inter:
                ix,iy = inter[-1]
                if manhattan(0,0,ix,iy) == k and manhattan(ix,iy,xx,yy) == k:
                    P.append((ix,iy))
                    P.append((0,0))
                    break
            if P[-1] == (0,0):
                break

        if xx < 0:
            signx = -1
            xx *= -1
        else:
            signx = 1

        if yy < 0:
            signy = -1
            yy *= -1
        else:
            signy = 1

        togo = k
        mn = min(togo,xx)
        xx -= mn
        togo -= mn
        yy -= togo

        xx *= signx
        yy *= signy

    for i in range(len(P)-1):
        assert abs(P[i][0] - P[i+1][0]) + abs(P[i][1] - P[i+1][1]) == k

    print(len(P)-1)
    for x,y in P[:-1][::-1]:
        print(x,y)

main()