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

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

Buggy submission (verdict: Runtime Error):
#UnionFind木
class UnionFind():
  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 same(self, x, y):
        return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

A = [0]*M
B = [0]*M
for i in range(M):
  A[i],B[i] = map(int, input().split())
  A[i] -= 1
  B[i] -= 1

ans = []

A = A[::-1]
B = B[::-1]
uf = UnionFind(N)
total = N*(N-1)//2
ans.append(total)
for i in range(M):
  if uf.same(A[i],B[i]):
    ans.append(total)
    continue
  m = abs(uf.parents[uf.find(A[i])])
  n = abs(uf.parents[uf.find(B[i])])
  #print(uf)
  #print(A[i]+1,m,B[i]+1,n)
  uf.union(A[i],B[i])
  total -= m*n
  ans.append(total)
  
#print(ans)   

print(*ans[:-1][::-1], sep='\n')

Buggy submission (verdict: Runtime Error):
#UnionFind木
class UnionFind():
  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 same(self, x, y):
        return self.find(x) == self.find(y)

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x < 0]

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

  def __str__(self):
    return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

A = [0]*M
B = [0]*M
for i in range(M):
  A[i],B[i] = map(int, input().split())
  A[i] -= 1
  B[i] -= 1

ans = []

A = A[::-1]
B = B[::-1]
uf = UnionFind(N)
total = N*(N-1)//2
ans.append(total)
for i in range(M):
  if uf.same(A[i],B[i]):
    ans.append(total)
    continue
  m = len(uf.members(A[i]))
  n = len(uf.members(B[i]))
  uf.union(A[i],B[i])
  total -= m*n
  ans.append(total)
  
#print(ans)   

print(*ans[:-1][::-1], sep='\n')
Problem p03170 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

dp = ['First']*(K+1)
dp[0] = 'Second'
def solve(dp):
    for i in range(1,K+1):
        for j in range(N):
            dp[i] = 'Second'
            if dp[i-A[j]]=='Second':
                dp[i] = 'First'
                break
    ans = dp[K]
    return ans
print(solve(dp))

Buggy submission (verdict: Runtime Error):
def solve():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  dp = ['Second']*(K*2)
  for i in range(K):
    if dp[i]!='Second':
      continue
    for j in range(N):
      dp[i+A[j]]='First'
  ans = dp[K]
  return ans
print(solve())def solve():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  dp = ['Second']*(K*2)
  for i in range(K):
    if dp[i]!='Second':
      continue
    for j in range(N):
      dp[i+A[j]]='First'
  ans = dp[K]
  return ans
print(solve())
Problem p03171 (python)

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


def solve(N,A):
    s,e = 0, N-1
    dp = [[0]*N for i in range(N)]
    for k in range(N):
        for i in range(N):
            j = i+k
            if j>=N:
                continue
            sign = (-1)**(N-1-k)
            if k==0:
                dp[i][j] = sign*A[i]
                continue
            dp[i][j] = sign*max(sign*dp[i+1][j]+A[i],sign*dp[i][j-1]+A[j])
    ans = dp[0][N-1]
    return ans
print(solve(N,A))

Buggy submission (verdict: Runtime Error):
def calc(N,i,j):
  if dp[i][j]<float('inf'):
    return dp[i][j]
  if (N-(j-i+1))%2==0:
    if i==j:
      dp[i][j] = A[i]
    else:
      dp[i][j] = max(calc(N,i,j-1)+A[j],calc(N,i+1,j)+A[i])
  else:
    if i==j:
      dp[i][j] = -A[i]
    else:
      dp[i][j] = min(calc(N,i,j-1)-A[j],calc(N,i+1,j)-A[i])
  return dp[i][j]

N = int(input())
A = list(map(int, input().split()))
dp = [[float('inf')]*N for _ in range(N)]
ans = calc(N,0,N-1)
print(ans)
Problem p03180 (python)

Fixed submission:
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  A = [list(map(int, input().split())) for _ in range(N)]
  dp = [0]*(1<<N)
  dp[0] = 0
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      last = com[-1]
      dp[S] = dp[S-(1<<last)]
      for c in com:
        dp[S] += A[last][c]
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      T = (S-1)&S
      while T>0:
        dp[S] = max(dp[S],dp[T]+dp[S-T])
        T = (T-1)&S
  ans = dp[-1]
  return ans
print(solve())

Buggy submission (verdict: Runtime Error):
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  B = [0]*N
  for i in range(N):
    a,b = input().split()
    a1,a2 = map(int,a.split(':'))
    b1,b2 = map(int,b.split(':'))
    a = a1*60+a2
    b = b1*60+b2
    B[i] = [a,b]
  A = [[0]*N for _ in range(N)]
  for i in range(N):
    for j in range(N):
      if B[i][0]>=B[j][1] and B[i][1]<=B[j][0]+1440:
        A[i][j] = 1
        A[j][i] = 1
  dp = [float('inf')]*(1<<N)
  dp[0] = 0
  for i in range(N):
    dp[1<<i] = 1
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = 0
      for c in com:
        S += 1<<c
      last = com[-1]
      dp[S] = dp[S-(1<<last)]
      for c in com[:-1]:
        if A[last][c]==0:
          dp[S] = float('inf')
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      T = (S-1)&S
      while T>0:
        dp[S] = min(dp[S],dp[T]+dp[S-T])
        T = (T-1)&S
  ans = dp[-1]
  return ans
print(solve())
Problem p03210 (python)

Fixed submission:
N = int(input())

def check():
    if N==3 or N==5 or N==7:
        return True
    return False
if check():
    print('YES')
else:
    print('NO')

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

def check():
    if N=3 or N=5 or N=7:
        return True
    return False
if check():
    print('YES')
else:
    print('NO')
Problem p03231 (python)

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

from fractions import gcd

def solve(N,M,S,T):
    g = gcd(N,M)
    for i in range(g):
        if S[N//g*i]!=T[M//g*i]:
            return -1
    ans = N*M//g
    return ans
print(solve(N,M,S,T))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

from collections import gcd

def solve(N,M,S,T):
    g = gcd(N,M)
    for i in range(g):
        if S[N//g*i]!=T[M//g*i]:
            return -1
    ans = N*M//g
    return ans
print(solve(N,M,S,T))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

from math import gcd

def solve(N,M,S,T):
    g = gcd(N,M)
    for i in range(g):
        if S[N//g*i]!=T[M//g*i]:
            return -1
    ans = N*M//g
    return ans
print(solve(N,M,S,T))
Problem p03241 (python)

Fixed submission:
N, M = map(int, input().split())
i = 1
lis = []
while M//i>=N and i<=M**0.5:
  if M % i == 0:
    lis.append(i)
  i += 1
for l in lis[::-1]:
  ans = M//l
  if M//ans>=N:
    lis.append(ans)
print(lis[-1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
i = 1
lis = []
while M//i>=N and i<M**0.5:
  if M % i == 0:
    lis.append(i)
  i += 1
print(lis[-1])
Problem p03274 (python)

Fixed submission:
def solve():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    if 0 in X:
        N -= 1
        K -= 1
        if K == 0:
            return 0
        X.remove(0)
    ans = 10**9
    for i in range(N-K+1):
        if X[i+K-1]<=0:
            p = -X[i]
        elif X[i]>=0:
            p = X[i+K-1]
        else:
            p = X[i+K-1]-X[i]+min(X[i+K-1],abs(X[i]))
        ans = min(ans,p)
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    if 0 in X:
        N -= 1
        K -= 1
        X.remove(0)
    ans = 10**9
    for i in range(N-K+1):
        if X[i+K-1]<=0:
            p = -X[i]
        elif X[i]>=0:
            p = X[i+K-1]
        else:
            p = X[i+K-1]-X[i]+min(X[i+K-1],abs(X[i]))
        ans = min(ans,p)
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    if 0 in X:
        N -= 1
        K -= 1
        X.remove(0)
    ans = X[-1]-X[0]+min(X[-1],abs(X[0]))
    for i in range(N-K+1):
        if X[i+K-1]<=0:
            p = -X[i]
        elif X[i]>=0:
            p = X[i+K-1]
        else:
            p = X[i+K-1]-X[i]+min(X[i+K-1],abs(X[i]))
        ans = min(ans,p)
    return ans
print(solve())
Problem p03281 (python)

Fixed submission:
N = int(input())
ans = 0
for i in range(1,N+1,2):
  cnt = 0
  for j in range(1,i+1):
    if i%j==0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
for i in range(1,N+1,2):
  cnt = 0
  for j in range(i):
    if i%j==0:
      cnt += 1
  if cnt == 8:
    ans += 1
print(ans)
Problem p03347 (python)

Fixed submission:
def solve():
  N = int(input())
  A = [int(input()) for _ in range(N)]
  if N==1:
    if A[0]==0:
      return 0
    return -1
  if A[0]>0 or A[1]>1:
    return -1
  ans = N - A.count(0)
  for i in range(1,N-1):
    if A[i]+1<A[i+1]:
      return -1
    if A[i]>=A[i+1] and A[i+1]>0:
      ans += A[i+1]-1
  return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
  N = int(input())
  A = [int(input()) for _ in range(N)]
  if A[0]>0 or A[1]>1:
    return -1
  ans = N - A.count(0)
  for i in range(1,N-1):
    if A[i]+1<A[i+1]:
      return -1
    if A[i]>=A[i+1] and A[i+1]>1:
      ans += 1
  return ans
print(solve())
Problem p03353 (python)

Fixed submission:
s = input()
K = int(input())
l = min(len(s),K)
lis = []
for i in range(1,l+1):
  for j in range(len(s)-i+1):
    lis.append(s[j:j+i])
lis = list(set(lis))
lis.sort()
print(lis[K-1])

Buggy submission (verdict: Runtime Error):
prime = [2,3,5,7,11,13,17,19,23,29,31]
pow = [1]
for p in prime:
  i=1
  while p**i<=1000:
    pow.append(p**i)
    i += 1
X = int(input())
x = X
while x>0:
  if x in pow:
    ans = x
    break
  x -= 1
print(ans)
Problem p03355 (python)

Fixed submission:
def solve():
    S = input()
    K = int(input())
    strlist = sorted(list(S))
    lis = set()
    p = 0
    while len(list(lis))<K:
        a = strlist[p]
        if len(S)>=5:
            for i,s in enumerate(S):
                if s==a:
                    for j in range(i+1,min(len(S)+1,i+K+1)):
                        lis.add(S[i:j])
        else:
            for i in range(len(S)):
                for j in range(i+1,len(S)+1):
                    lis.add(S[i:j])
        p += 1
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(i+1,min(len(S)+1,i+K+1)):
                    lis.add(S[i:j])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(i+1,min(len(S),i+K+1)):
                    lis.add(S[i:j])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
    S = input()
    K = int(input())
    a = min(list(S))
    lis = set()
    if len(S)>=5:
        for i,s in enumerate(S):
            if s==a:
                for j in range(1,K+1):
                    lis.add(S[i:min(len(S),i+j)])
    else:
        for i in range(len(S)):
            for j in range(i+1,len(S)+1):
                lis.add(S[i:j])
    ans = sorted(list(lis))[K-1]
    return ans
print(solve())
Problem p03364 (python)

Fixed submission:
def solve():
    N = int(input())
    S2 = [0]*N
    for i in range(N):
        S2[i] = input()
    ans = 0
    for k in range(N):
        cum = [[0]*(N+1) for _ in range(N+1)]
        for i in range(1,N+1):
            for j in range(1,N+1):
                cum[i][j] = cum[i-1][j]+cum[i][j-1]-cum[i-1][j-1]+(S2[i-1][j-1]==S2[(j-1+k)%N][(i-1-k)%N])
                if i==N and j==N:
                    ans += (cum[i][j]==N*N)*N
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve():
    N = int(input())
    S2 = [0]*(2*N)
    for i in range(N):
        S2[i] = input()*2
        S2[i+N] = S2[i]
    check = [[[0]*(2*N) for _ in range(2*N)] for _ in range(2*N-1)]
    cum = [[[0]*(2*N) for _ in range(2*N)] for _ in range(2*N-1)]
    for i in range(2*N-1):
        for j in range(2*N-1):
            for k in range(-N+1,N):
                if j+k>=0 and j+k<=2*N-1 and i-k>=0 and i-k<=2*N-1:
                    check[k][i+1][j+1] = S2[i][j]==S2[j+k][i-k]
    for i in range(1,2*N):
        for j in range(1,2*N):
            for k in range(-N+1,N):
                cum[k][i][j] = cum[k][i-1][j]+cum[k][i][j-1]-cum[k][i-1][j-1]+check[k][i][j]
                if i>=N+1:
                    cum[k][i][j] -= check[k][i-N][j]
                if j>=N+1:
                    cum[k][i][j] -= check[k][i][j-N]
                if i>=N+1 and j>= N+1:
                    cum[k][i][j] += check[k][i-N][j-N]
    ans = 0
    for k in range(-N+1,0):
        A,B = -k+N,N
        while A<2*N:
            if cum[A-B][A][B]==N*N:
                ans += 1
            A += 1
            B += 1
    for k in range(N):
        A,B = N,k+N
        while B<2*N:
            if cum[A-B][A][B]==N*N:
                ans += 1
            A += 1
            B += 1
    return ans
print(solve())

Buggy submission (verdict: Runtime Error):
import numpy as np
def solve():
    N = int(input())
    S2 = [0]*(2*N)
    for i in range(N):
        S2[i] = input()*2
        S2[i+N] = S2[i]
    check = np.zeros((2*N-1,2*N-1,2*N-1))
    cum = np.zeros((2*N-1,2*N,2*N))
    for i in range(2*N-1):
        for j in range(2*N-1):
            for k in range(-N+1,N):
                if j+k>=0 and j+k<=2*N-1 and i-k>=0 and i-k<=2*N-1:
                    check[k,i,j] = S2[i][j]==S2[j+k][i-k]
    for i in range(1,2*N):
        for j in range(1,2*N):
            for k in range(-N+1,N):
                cum[k,i,j] = cum[k,i-1,j]+cum[k,i,j-1]-cum[k,i-1,j-1]+check[k,i-1,j-1]
                if i>=N+1:
                    cum[k,i,j] -= check[k,i-N-1,j-1]
                if j>=N+1:
                    cum[k,i,j] -= check[k,i-1,j-N-1]
                if i>=N+1 and j>= N+1:
                    cum[k,i,j] += check[k,i-N-1,j-N-1]
    ans = 0
    for k in range(-N+1,0):
        A,B = -k+N,N
        while A<2*N:
            if cum[A-B,A,B]==N*N:
                ans += 1
            A += 1
            B += 1
    for k in range(N):
        A,B = N,k+N
        while B<2*N:
            if cum[A-B,A,B]==N*N:
                ans += 1
            A += 1
            B += 1
    return ans
print(solve())
Problem p03450 (python)

Fixed submission:
from collections import deque
def check():
  N, M = map(int, input().split())
  edge = [[] for _ in range(N)]
  for i in range(M):
    a,b,d = map(int, input().split())
    edge[a-1].append([b-1,d])
    edge[b-1].append([a-1,-d])
  
  visited = [float('inf')]*N
  D = deque()
  for i in range(N):
    if visited[i]==float('inf'):
      visited[i]=0
      D.append(i)
      while len(D)>0:
        v = D.popleft()
        for w,d in edge[v]:
          if visited[w]==float('inf'):
            visited[w] = visited[v]+d
            D.append(w)
          elif visited[w]!=visited[v]+d:
            return 'No'
  return 'Yes'
print(check())

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def check():
  D = defaultdict(lambda: '')
  N, M = map(int, input().split())
  if M==0:
    return 'Yes'
  for i in range(M):
    l,r,d = map(int, input().split())
    if i==0:
      D[l] = 0
    if D[r]!='' and D[l]!='' and D[r] != D[l]+d:
      return 'No'
    D[r] = D[l]+d
  if max(D.values())-min(D.values())>10**9:
    return 'No'
  return 'Yes'
print(check())

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
def check():
  D = defaultdict(lambda: '')
  N, M = map(int, input().split())
  if M==0:
    return 'Yes'
  for i in range(M):
    l,r,d = map(int, input().split())
    if i==0:
      D[l] = 0
    if D[r]!='' and D[r] != D[l]+d:
      return 'No'
    D[r] = D[l]+d
  if max(D.values())-min(D.values())>10**9:
    return 'No'
  return 'Yes'
print(check())
Problem p03651 (python)

Fixed submission:
from fractions import gcd
def check():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K > max(A):
        return False
    g = A[0]
    for i in range(1,N):
        g = gcd(g,A[i])
    if K%g != 0:
        return False
    return True
if check():
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
from math import gcd
def check():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    if K > max(A):
        return False
    g = A[0]
    for i in range(1,N):
        g = gcd(g,A[i])
    if K%g != 0:
        return False
    return True
if check():
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
Problem p03679 (python)

Fixed submission:
def check():
  X, A, B = map(int, input().split())
  if A>=B:
    return 'delicious'
  if B-A>X:
    return 'dangerous'
  return 'safe'
print(check())

Buggy submission (verdict: Runtime Error):
#最小全域木問題、プリム法
from heapq import *
def solve():
    N = int(input())
    A = [list(map(int, input().split()))+[i] for i in range(N)]
    edge = [[] for _ in range(N)]
    A.sort()
    for i in range(N-1):
        w = A[i+1][0]-A[i][0]
        edge[A[i][2]].append((w,A[i+1][2]))
        edge[A[i+1][2]].append((w,A[i][2]))
    A.sort(key=lambda x:x[1])
    for i in range(N-1):
        w = A[i+1][1]-A[i][1]
        edge[A[i][2]].append((w,A[i+1][2]))
        edge[A[i+1][2]].append((w,A[i][2]))
    bridges = []
    heapify(bridges)
    used = [False]*N
    used[0] = True
    ans = 0
    for w,v in edge[0]:
        heappush(bridges,(w,v))
    while len(bridges)>0:
        w,v = heappop(bridges)
        if used[v]==False:
            ans += w
            used[v] = True
            for w,u in edge[v]:
                if used[u]==False:
                    heappush(bridges,(w,u))
    return ans
print(solve())
Problem p03695 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x:x//400,A))
#print(A)
C = [0]*9
for a in A:
  if a>=8:
    C[8] +=1
  elif C[a]==0:
    C[a] = 1
#print(C[:-1])
mi = sum(C[:-1])
mini = mi
if mi == 0:
  mini = 1
ma = mi+C[-1]
print(mini,ma)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
A = list(map(lambda x:x//400,A))
#print(A)
C = [0]*9
for a in A:
  if a>=8:
    C[8] +=1
  elif C[a]==0:
    C[a] = 1
#print(C[:-1])
mi = sum(C[:-1])
if mi == 0:
  mini = min(1,C[-1])
ma = min(8,mi+C[-1])
print(mini,ma)
Problem p03697 (python)

Fixed submission:
A, B = map(int, input().split())
if A+B>=10:
  print('error')
else:
  print(A+B)

Buggy submission (verdict: Runtime Error):
from math import ceil
def solve():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    top = max(H)+1
    total = sum(H)
    bottom = 1
    mid = (top+bottom)//2
    while bottom+1<top:
        cnt = 0
        for i in range(N):
            cnt += max(ceil((H[i]-B*mid)/(A-B)),0)
        if cnt>mid:
            bottom = mid+1
        else:
            top = mid+1
        mid = (top+bottom)//2
    ans = mid
    return ans
print(solve())
Problem p03730 (python)

Fixed submission:
A, B, C = map(int, input().split())
for i in range(1,B+1):
  if i*A%B==C:
    print('YES')
    exit()
print('NO')

Buggy submission (verdict: Runtime Error):
from math import gcd
def check():
    A, B, C = map(int, input().split())
    if C%gcd(A,B)==0:
        return 'YES'
    return 'NO'
print(check())
Problem p04015 (python)

Fixed submission:
def solve():
  ans = 0
  N, A = map(int, input().split())
  X = list(map(int, input().split()))
  x = sum(X)
  dp = [[[0]*2550 for _ in range(N+1)] for _ in range(N+1)]
  dp[0][0][0] = 1
  for i in range(N):
    for j in range(i+1):
      for k in range(x):
        dp[i+1][j][k] += dp[i][j][k]
        dp[i+1][j+1][k+X[i]] += dp[i][j][k]
  for j in range(1,N+1):
    ans += dp[-1][j][j*A]
  return ans
print(solve())

Buggy submission (verdict: Runtime Error):
def solve():
  ans = 0
  N, A = map(int, input().split())
  X = list(map(int, input().split()))
  x = sum(X)
  dp = [[[0]*(sum(X)+50) for _ in range(N+1)] for _ in range(N+1)]
  dp[0][0][0] = 1
  for i in range(N):
    for j in range(i+1):
      for k in range(x):
        dp[i+1][j][k] += dp[i][j][k]
        dp[i+1][j+1][k+X[i]] += dp[i][j][k]
  for j in range(1,N+1):
    ans += dp[-1][j][j*A]
  return ans
print(solve())
Problem p03138 (python)

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

bits_k = len(bin(k)) - 2
forma = '0%db' % bits_k
data = [0 for i in range(bits_k)]

for an in a:
    anb = format(an, forma)
    #print(anb)
    for i in range(bits_k):
        if anb[-i-1] == '0':
            data[i] += 1
        else:
            data[i] -= 1

#print(data)
ans = 0
for i in range(bits_k - 1, -1, -1):
    if data[i] > 0:
        ans |= (1 << i)
        if ans > k:
            ans &= ~(1 << i)

#print(ans)
b = sum([ans ^ an for an in a])
print(b)

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

bits_k = len(bin(k)) - 2
forma = f'0{bits_k}b'
data = [0 for i in range(bits_k)]

for an in a:
    anb = format(an, forma)
    #print(anb)
    for i in range(bits_k):
        if anb[-i-1] == '0':
            data[i] += 1
        else:
            data[i] -= 1

#print(data)
ans = 0
for i in range(bits_k - 1, -1, -1):
    if data[i] > 0:
        ans |= (1 << i)
        if ans > k:
            ans &= ~(1 << i)

#print(ans)
b = sum([ans ^ an for an in a])
print(b)