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

Fixed submission:
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
m = max(A)
if N == 1:
    if A[0] == K:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    if K > m:
        print('IMPOSSIBLE')
    else:
        gcd = xgcd(A[0],A[1])
        for i in range(2,N):
            gcd = xgcd(gcd,A[i])
            if gcd == 1:
                print('POSSIBLE')
                break
        else:
            if K % gcd == 0:
                print('POSSIBLE')
            else:
                print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a

N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
m = max(A)
if K > m:
    print('IMPOSSIBLE')
else:
    gcd = xgcd(A[0],A[1])
    for i in range(2,N):
        gcd = xgcd(gcd,A[i])
        if gcd == 1:
            print('POSSIBLE')
            break
    else:
        if K % gcd == 0:
            print('POSSIBLE')
        else:
            print('IMPOSSIBLE')
Problem p02573 (python)

Fixed submission:
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 size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

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

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

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

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

n,m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1,b-1)
maxn = 0
for i in range(n):
    maxn = max(maxn, uf.size(i))
print(maxn)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
friend = [[0]*n for i in range(n)]
s = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    if friend[a-1][b-1] != 1 and friend[b-1][a-1] != 1:
        friend[a-1][b-1] = 1
        friend[b-1][a-1] = 1
        s[a-1] += 1
        s[b-1] += 1
print(max(s) + 1)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
friend = [[0]*n for i in range(n)]
s = 0
for i in range(m):
    a, b = map(int, input().split())
    friend[a-1][b-1] = 1
    friend[b-1][a-1] = 1
for i in range(n):
    s = max(s, sum(friend[i]))
print(s)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
friend = [[0] * n for i in range(n)]
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    friend[x][y] = 1
    friend[y][x] = 1
maxfriend = 0
for li in friend:
    maxfriend = max(maxfriend, sum(li))
print(maxfriend+1)
Problem p02684 (python)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
 
visited = []
tf_visited = [0] * n
pos = 0
count = 0
 
while tf_visited[pos] == 0:
	visited.append(pos)
	tf_visited[pos] = 1
	pos = a[pos]-1
	count += 1
	if count >= k:
		print(pos+1)
		exit()
 
loop_start = visited.index(pos)
loop_length = len(visited)-loop_start
pos_t = (k-loop_start) % loop_length + loop_start
print(visited[pos_t]+1)

Buggy submission (verdict: Runtime Error):
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
li = [1,]
ans = [0] * n 
tmp = 1
ind = []
count = 0
for i in range(10**5):
    li.append(a[tmp-1])
    ans[tmp-1] += 1
    tmp = a[tmp-1]
    for j in range(len(ans)):
        if ans[j] == 2:
            count = sum(ans) -1
            ind.append(a[tmp-1])
            ans[j] = 3
    if any(item > 3 for item in ans):
        break
q = deque(ind)
q.rotate(-1)
s = count-2*len(ind)-1
if s >= k:
    print(li[k])
else:
    print(q[k%len(q)-s])

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
li = [1,]
ans = [0] * n 
tmp = 1
ind = []
count = 0
for i in range(10**5):
    li.append(a[tmp-1])
    ans[tmp-1] += 1
    tmp = a[tmp-1]
    for j in range(len(ans)):
        if ans[j] == 2:
            count = sum(ans) -1
            ind.append(j)
            ans[j] = 3
    if any(item > 3 for item in ans):
        break
s = count-2*len(ind)-1

if k <= s:
    print(a[k])
else:
    print(a[ind[(k-s+1) % (s+1) -2]])
Problem p02730 (python)

Fixed submission:
s = input()
r1 = s[::-1]
n = len(s)
r2 = s[0:(n-1)//2]
r2r = r2[::-1]
r3 = s[(n+3)//2-1:]
r3r = r3[::-1]
if s == r1 and r2 == r2r and r3 == r3r:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
flg = False
for i in range(len(S)//2):
    if S[i] == S[len(S)-i]:
        flg = True
    else:
        flg = False
for i in range((len(S)-1) //2//2):
    if S[i] == S[(len(S)-1)//2-i]:
        pass
    else:
        flg = False
for i in range((len(S)-(len(S)+3)//2)//2):
    if S[i] == S[(len(S)+3)//2 -i]:
        pass
    else:
        flg = False

if flg:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
S = input()
flg = False
for i in range(len(S)):
    if S[i] == S[len(S)-i]:
        flg = True
    else:
        flg = False
for i in range((len(S)-1) /2):
    if S[i] == S[(len(s)-1)/2-i]:
        pass
    else:
        flg = False
for i in range((len(S)+3)/2, N):
    if S[i] == S[(len(S)+3)/2) -i]:
        pass
    else:
        flg = False

if flg:
    print('Yes')
else:
    print('No')
Problem p02760 (python)

Fixed submission:
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
listb = [int(input()) for i in range(N)]

for item in listb:
    for i in range(3):
        if A1[i] == item:
            A1[i] = 0
    for j in range(3):
        if A2[j] == item:
            A2[j] = 0
    for k in range(3):
        if A3[k] == item:
            A3[k] = 0
if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print('Yes')
    exit()
for i in range(3):
    if A1[i] == A2[i] and A2[i] == A3[i]:
        print('Yes')
        exit()
if A1[0] == A2[1] == A3[2] or A1[2] == A2[1] == A3[0]:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
listb = [input() for i in range(N)]

for item in listb:
    for i in range(3):
        if A1[i] == item:
            A1[i] = 0
    for j in range(3):
        if A2[j] == item:
            A2[j] = 0
    for k in range(3):
        if A3[k] == item:
            A3[k] = 0
if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print('Yes')
    exit()
for i in range(3):
    if A1[i] == A2[i] and A2[i] == A3[i]:
        print('Yes')
        exit()
if A1[1] == A2[2] == A3[3] or A1[3] == A2[2] == A3[1]:
    print('Yes')
    exit()
print('No')

Buggy submission (verdict: Runtime Error):
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
N = int(input())
listb = [input() for i in range(N)]

for item in listb:
    for i in range(3):
        if A1[i] == item:
            A1[i] = 0
    for j in range(3):
        if A2[j] == item:
            A2[j] = 0
    for k in range(3):
        if A3[k] == item:
            A3[k] = 0
flg = false
if sum(A1) == 0 or sum(A2) == 0 or sum(A3) == 0:
    print('Yes')
    exit()
for i in range(3):
    if A1[i] == A2[i] and A2[i] == A3[i]:
        print('Yes')
        exit()
if A1[1] == A2[2] == A3[3] or A1[3] == A2[2] == A3[1]:
    print 'Yes'
    exit()
print('No')
Problem p02761 (python)

Fixed submission:
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and flg[0] == 1 and ans[0] == 0 :
    print(-1)
elif n > 1 and flg[0] == 0:
    ans[0] = 1
    print(''.join(map(str,ans)))
    exit()
else:
    print(''.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
s = [0] * m
c = [0] * m
ans = [0] * n
flg = [0] * n
for i in range(m):
    s[i],c[i] = map(int,input().split())
for j in range(m):
    if: flg[s[j]-1] == 1 and ans[s[j]-1] != c[j]:
        print(-1)
        exit()
    else:
        ans[s[j]-1] = c[j]
        flg[s[j]-1] = 1
    
if n > 1 and ans[0] == 0 :
    print(-1)
else:
    print(''.join(map(str,ans)))
Problem p02802 (python)

Fixed submission:
n,m = map(int,input().split())
ps = [0] * m
for i in range(m):
    ps[i] = list(map(str,input().split()))
if m == 0:
    print(0,0)
    exit()
countA = [0] * n
countW = [0] * n
cn = 0
for item in ps:
    if item[1] == 'AC' and countA[int(item[0])-1] == 0:
        countA[int(item[0])-1] = 1
        cn += countW[int(item[0])-1]
    else:
        countW[int(item[0])-1] += 1
print(sum(countA),cn)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ps = [0] * m
p = [0] * m
s = [0] * m
for i in range(m):
    ps[i] = list(map(str,input().split()))
if m = 0:
    print(0,0)
    exit()
cp=int(ps[0][0])
countA = [0] * n
countW = 0
cn = 0
for item in ps:
    if item[1] == 'AC':
        countA[int(item[0])-1] = 1
        countW += cn
        cp += 1
        cn = 0
    else:
        cn+=1
print(sum(countA),countW)
Problem p02837 (python)

Fixed submission:
n = int(input())
shougen=[[-1]*(n+1) for _ in range(n+2)]
for i in range(1,n+1):
  a = int(input())
  for j in range(a):
    x,y = map(int, input().split())
    shougen[i][x]=y
 
ans=0
for i in range(2**n):
  f=True
  for j in range(n):
    if i>>j & 1:
      for k,s in enumerate(shougen[j+1][1:],start=0):
        if s == 1 and not i>>k & 1:
          f=False
        if s == 0 and i>>k & 1:
          f=False
  else:
    if f:
      ans=max(ans, str(bin(i)).count("1"))
 
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
a = [0] * n
xy = []
for i in range(n):
    a[i] = int(input())
    x_y = []
    for j in range(a[i]):
        x_y.append(list(map(int,input().split())))
    xy.append(x_y)

ans = 0
for it in itertools.product([0,1],repeat=n):
    li = [0] * n
    for i in range(len(a)):
        for k in range(n):
            for j in range(a[i]):
                if it[k] == 1:
                    if xy[k][j][1]==0:
                        li[xy[k][j][0]-1] = -1
                    else:
                        li[xy[k][j][0]-1] = 1
    flg = True                        
    for l in range(n):
        if li[l] == -1 and it[l] == 1 or li[l] == 1 and it[l] == -1 or li[l] == 1 and it[l] == 0:
            flg = False
    if flg:

        if ans < sum(it):
            ans = sum(it)
print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())
print(n*(n-1)//2)

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
li = list(range(1,n+1))
q = deque(li)
q.rotate(-1)
count = 1
ans = 0
for q_i in q:
    ans += count % q_i
    count += 1
print(ans)
Problem p02971 (python)

Fixed submission:
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
sorted_a = sorted(a, reverse=True)
max_a = sorted_a[0]
for i in range(n):
    if max_a != a[i]:
        print(max_a)
    else:
        print(sorted_a[1])

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [0] * n
for i in range(n):
    a[i] = int(input())
for i in range(n):
    li_s = max(a[:i])
    li_g = max(a[i+1:])
    print(max(li_s,li_g))
Problem p02994 (python)

Fixed submission:
n,l= map(int,input().split())
li = []
for i in range(n):
    li.append(l)
    l += 1
ans = 0
li_min = float('inf')
for i in range(len(li)):
    li_min = min(abs(li[i]),li_min)
for i in range(len(li)):
    if li_min == abs(li[i]):
        li[i] = 0
print(sum(li))

Buggy submission (verdict: Runtime Error):
n,l= map(int,input().split())
if l == -1:
    count = 0
    for i in range(n):
        count += l
        l += 1
    print(count)
elif l < 0:
    count = 0
  for i in range(n-1):
        count += l
        l += 1
    print(count)
else:
    print(((2*l+n)*(n-1))//2)
Problem p02582 (python)

Fixed submission:
S = input()
cnt = 0
cmax = 0
for c in S:
  if c == "R":
    cnt += 1
    if cmax < cnt:
      cmax = cnt
  else:
    cnt = 0
print(cmax)

Buggy submission (verdict: Runtime Error):
S = input()
c = 0
cmax = 0
for c in S:
  if c == "R":
    c += 1
    if cmax < c:
      cmax = c
  else:
    c = 0
print(cmax)
Problem p02660 (python)

Fixed submission:

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def q4():
    N = int(input())
    arr = prime_factorize(N)
    if not arr:
        print(0)
        return

    ans_count = 0
    count = 1

    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()

Buggy submission (verdict: Runtime Error):

def q4():
    N = int(input())
    arr = prime_factorize(N)
    if not arr:
        print(0)
        return

    ans_count = 0
    count = 1

    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()

Buggy submission (verdict: Runtime Error):

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def q4():
    N = int(input())
    arr = prime_factorize(N)

    ans_count = 0
    count = 1
    min_val = min(arr)
    while arr:
        if arr.count(min_val) < count:
            arr = list(filter(lambda a: a != min_val, arr))
            count = 1
            if not arr:
                break
            min_val = min(arr)
            continue
        arr = arr[count:]
        ans_count += 1
        count += 1
    print(ans_count)


q4()
Problem p02713 (python)

Fixed submission:

from math import gcd

K = int(input())

a = 0
for ai in range(1, K + 1):
  for bi in range(1, K + 1):
    gcd_ab = gcd(ai, bi)
    for ci in range(1, K + 1):
      a += gcd(gcd_ab, ci)

print(a)

Buggy submission (verdict: Runtime Error):

def q3():
import math
    k = int(input())
    sum_n = 0
    gcd_2_dict = {}
    def gcd(n1, n2):
        if n1 < n2:
            sorted_nums = tuple([n1, n2])
        else:
            sorted_nums = tuple([n2, n1])
        if sorted_nums in gcd_2_dict:
            return gcd_2_dict[sorted_nums]
        gcd_num = math.gcd(n1, n2)
        gcd_2_dict[sorted_nums] = gcd_num
        return gcd_num

    for a in range(1, k + 1):
        for b in range(1, k + 1):
            for c in range(1, k + 1):
                sorted_nums = sorted([a, b, c])
                sum_n += gcd(gcd(sorted_nums[0], sorted_nums[1]), sorted_nums[2])

    print(sum_n)

q3()
Problem p02730 (python)

Fixed submission:
S = input()
N = len(S)
 
def isp(s):
  n = len(s)
  for i in range(n // 2):
    if s[i] != s[n - 1 - i]:
      return False
  return True
 
if isp(S) and isp(S[0:(N - 1) // 2]):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
N = len(S)

def isp(s):
  n = len(s)
  for i in range(n // 2 - 1):
    if s[i] != s[n - 1 - i]:
      return False
  return True

if isp(S) and isp(S[0:(N - 1) / 3]):
  print("Yes")
else:
  print("No")
Problem p02767 (python)

Fixed submission:
_ = int(input())
X = list(map(int, input().split()))

t = []
for i in range(min(X), max(X) + 1):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))

Buggy submission (verdict: Runtime Error):
_ = int(input())
X = list(map(int, input().split()))

t = []
for i in range(min(X), max(X)):
  s = 0
  for x in X:
    s += (x - i) * (x - i)
  t.append(s)

print(min(t))
Problem p02885 (python)

Fixed submission:
a, b = [int(i) for i in input().split()]
print(max(0, a - 2 * b))

Buggy submission (verdict: Runtime Error):
a, b = [int(i) for i in input().split()]
print(max(0, a - 2 * b)
Problem p02922 (python)

Fixed submission:
import math
A,B=map(int,input().split())
print(math.ceil((B-1)/(A-1)))

Buggy submission (verdict: Runtime Error):
A,B=map(int,input().split())
print(math.ceil((B-1)/(A-1)))
Problem p03005 (python)

Fixed submission:
N, K = [int(x) for x in input().split(' ')]
if K == 1:
    print(0)
else:
    min = 1
    max = N - (K - 1)
    print(max - min)

Buggy submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split(' ')]
if K == 1:
    print(0)
    return
min = 1
max = N - (K - 1)
print(max - min)
Problem p03101 (python)

Fixed submission:
h, w = [int(i) for i in input().split()]
h1, w1 = [int(i) for i in input().split()]
 
print(h * w - (h * w1 + w * h1 - h1 * w1))

Buggy submission (verdict: Runtime Error):
h, w = [int(i) for i in input().split()]
_, _ = input()

print(h * w - (h + w - 1))
Problem p03227 (python)

Fixed submission:
s = input()
if len(s) == 2:
  print(s)
else:
  print(s[2]+s[1]+s[0])

Buggy submission (verdict: Runtime Error):
s = input()
if len(S) == 2:
  print(s)
else:
  print(s[2]+s[1]+s[0])
Problem p02609 (python)

Fixed submission:
n = int(input())
x = input()
ans = [0]*(n+1)

for i in range(1,n+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)

for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx%temp + pow(2,n-1-i,temp)
    else:
        if temp>1:
            temp -= 1
            num = numx%temp - pow(2,n-1-i,temp)
        else:
            print(0)
            continue
    print(ans[num%temp]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ans = [0]*(-(-n//2)+1)

def f(x):
    c = 0
    while x:
        c += 1
        x = x % bin(x).count('1')
    return c

one_cnt = x.count('1')
numx = int(x,2)
for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx + 2**(n-1-i)
    else:
        temp -= 1 if temp>0 else 0
        num = numx - 2**(n-1-i)
    print(f(num%temp)+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ans = [0]*(-(-n//2)+1)

for i in range(1,-(-n//2)+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)
for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx + 2**(n-1-i)
    else:
        temp -= 1
        num = numx - 2**(n-1-i)
    print(ans[num%temp]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ans = [0]*(n+1)

for i in range(1,n+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)
for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx + 2**(n-1-i)
    else:
        temp -= 1
        num = numx - 2**(n-1-i)
    print(ans[num%temp]+1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = input()
ans = [0]*(10**5+1)

for i in range(1,10**5+1):
    s = format(i, 'b')
    c = s.count('1')
    a = i%c
    ans[i] += 1
    ans[i] += ans[a] 

one_cnt = x.count('1')
numx = int(x,2)
for i in range(n):
    temp = one_cnt
    if x[i]=='0':
        temp += 1
        num = numx + 2**(n-1-i)
    else:
        temp -= 1
        num = numx - 2**(n-1-i)
    print(ans[num%temp]+1)
Problem p02619 (python)

Fixed submission:
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(d)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    print(a)

Buggy submission (verdict: Runtime Error):
n = 26
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(n)]
for i in range(d):
    s[i] = list(map(int,input().split()))
a = 0
last = [0]*n
ans = []
for i in range(d):
    t = int(input())-1
    a += s[i][t]
    last[t] = i+1
    for j in range(n):
        a -= c[j]*(i-last[j]+1)
    ans.append(a)
for i in ans:
    print(i)

Buggy submission (verdict: Runtime Error):
d = int(input())
c = list(map(int,input().split()))
s = [[] for i in range(26)]
for i in range(d):
    s[i] = list(map(int,input().split()))
ans = 0
last = [0]*26
for i in range(d):
    t = int(input())-1
    ans += s[i][t]
    last[t] = i+1
    for j in range(26):
        ans -= c[j]*(i-last[j]+1)
    print(ans)
Problem p02642 (python)

Fixed submission:
n = int(input())
a = sorted(list(map(int,input().split())))
m = max(a)+1
c = [0]*m
for x in a:
    for i in range(x,m,x):
        if c[i]<2:c[i]+=1
ans = 0
for i in a:
    if c[i]==1:
        ans += 1
print(ans)

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

if n==1:
    print(1)
    exit()

if a[0] in a[1:]:
    ans = 0
else:
    ans = 1

import sympy
div = set([a[0]])
for i in a[1:]:
    x = set(sympy.divisors(i))
    if not x&div:
        ans += 1
    div.add(i)
print(ans)
Problem p02696 (python)

Fixed submission:
a,b,n = map(int,input().split())
if n%b==0:n-=1
x = max((n//b)*b-1,n%b)
print(((a*x)//b)-(a*(x//b)))

Buggy submission (verdict: Runtime Error):
a,b,n = map(int,input().split())
n%b==0:n-=1
print((a*n)//b-a*(n//b))
Problem p02775 (python)

Fixed submission:
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l-1):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        n[i+1] += 1
        ans += 10-n[i]
    else:
        ans += n[i]
ans += 11-n[-1] if n[-1]>5 else n[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
n = list(input())
n = [int(i) for i in n]
n.reverse()
l = len(n)
ans = 0
for i in range(l):
    if (n[i]==5 and n[i+1]>=5) or n[i]>5:
        if i!=l-1:
            n[i+1] += 1
        else:
            ans += 1
        ans += 10-n[i]
    else:
        ans += n[i]
print(ans)