Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M,K=map(int,input().split())
P=998244353
class FactInv:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
FI=FactInv(N+10,P)
ans=0
for i in range(0,K+1):
    ans+=(M*FI.comb(N-1,i)*pow(M0,N-1-i,P))%P
    ans%=P
print(ans)

Fixed submission:
N,M,K=map(int,input().split())
P=998244353
class FactInv:
    def __init__(self,N,P):
        fact=[];ifact=[];fact=[1]*(N+1);ifact=[0]*(N+1)
        for i in range(1,N):
            fact[i+1]=(fact[i]*(i+1))%P
        ifact[-1]=pow(fact[-1],P-2,P)
        for i in range(N,0,-1):
            ifact[i-1]=(ifact[i]*i)%P
        self.fact=fact;self.ifact=ifact;self.P=P
    def comb(self,n,k):
        return (self.fact[n]*self.ifact[k]*self.ifact[n-k])%self.P
FI=FactInv(N+10,P)
ans=0
for k in range(0,K+1):
    ans+=(M*FI.comb(N-1,k)*pow(M-1,N-1-k,P))%P
    ans%=P
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=len(S)
A=[0]
for i in range(N):
    s=int(S[N-1-i:N])
    A.append(s%2019)
d={}
for i in range(len(A)):
    if not A[i] in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1
ans=0
for k in d.keys():
    ans+=d[k]*(d[k]-1)//2
print(ans)

Fixed submission:
S=input()
N=len(S)
A=[0]
for i in range(N):
    s=int(S[-1-i])
    A.append((A[-1]+(s*pow(10,i,2019)))%2019)
d={}
for i in range(len(A)):
    if not A[i] in d:
        d[A[i]]=1
    else:
        d[A[i]]+=1
ans=0
for k in d.keys():
    ans+=d[k]*(d[k]-1)//2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
Rev=False
for _ in range(Q):
    q=list(input().split())
    if len(q)==1:
        Rev=not Rev
    else:
        if q[1]=='1':
            if not Rev:
                S=q[2]+S
            else:
                S=S+q[2]
        else:
            if Rev:
                S=q[2]+S
            else:
                S=S+q[2]
if Rev:
    S=S[::-1]
print(S)

Fixed submission:
S=input()
Q=int(input())
Rev=False
a=[]
b=[]
for _ in range(Q):
    q=list(input().split())
    if len(q)==1:
        Rev=not Rev
    else:
        if q[1]=='1':
            if not Rev:
                a.append(q[2])
            else:
                b.append(q[2])
        else:
            if Rev:
                a.append(q[2])
            else:
                b.append(q[2])
S=''.join(a)[::-1]+S+''.join(b)
if Rev:
    S=S[::-1]
print(S)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
for i in range(0, N):
    print(A.index(i+1)+1,end=" ")

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(0, N):
    B[A[i]-1]=i+1
for i in range(0, N):
    print(B[i],end=" ")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
B=[i+1 for i in range(0, N)]
for i in range(0, N):
    print(A.index(B[i])+1,end=" ")

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0]*N
for i in range(0, N):
    B[A[i]-1]=i+1
for i in range(0, N):
    print(B[i],end=" ")
Buggy python submission (verdict: Runtime Error):
A,B,C,D=map(int,input().split())
E=B-A
import math
CD=C*D//math.gcd(C, D)
b=B-B//C-B//D+B//CD
A-=1
a=A-A//C-A//D+A//CD
print(b-a)

Fixed submission:
A,B,C,D=map(int,input().split())
E=B-A
import fractions
CD=C*D//fractions.gcd(C, D)
b=B-B//C-B//D+B//CD
A-=1
a=A-A//C-A//D+A//CD
print(b-a)
Buggy python submission (verdict: Runtime Error):
X, A = (int, input().split())
print(10 if X>=A else 0)

Fixed submission:
X, A = map(int, input().split())
print(10 if X>=A else 0)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[]
for _ in range(0,M):
    b,c=map(int,input().split())
    B.append([c,b])
A.sort();B.sort(reverse=True)
cnt=0
fin=False
for b in B:
    for i in range(0,b[1]):
        if A[cnt]<b[0]:
            A[cnt]=b[0]
            cnt+=1
        else:
            fin=True
            break
    if fin:
        break
print(sum(A))



Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
B=[]
for _ in range(0,M):
    b,c=map(int,input().split())
    B.append([c,b])
A.sort();B.sort(reverse=True)
cnt=0
fin=False
for b in B:
    for i in range(0,b[1]):
        if cnt>N-1:
            fin=True
            break
        if A[cnt]<b[0]:
            A[cnt]=b[0]
            cnt+=1
        else:
            fin=True
            break
    if fin:
        break
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N=int(input())
G=[[] for i in range(N)]
for _ in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w%2])
    G[v-1].append([u-1,w%2])
color=[0 for i in range(N)]
seen=[False for i in range(N)]
color[0]=1
def dps(i):
    seen[i]=True
    for g in G[i]:
        if seen[g[0]]:
            continue
        else:
            if g[1]==0:
                color[g[0]]=color[i]
            else:
                color[g[0]]=color[i]*-1
            dps(g[0])
dps(0)
for i in range(N):
    print(1 if color[i]==1 else 0)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
N=int(input())
G=[[] for i in range(N)]
for _ in range(N-1):
    u,v,w=map(int,input().split())
    G[u-1].append([v-1,w%2])
    G[v-1].append([u-1,w%2])
color=[0 for i in range(N)]
seen=[False for i in range(N)]
color[0]=1
def dps(i):
    seen[i]=True
    for g in G[i]:
        if seen[g[0]]:
            continue
        else:
            if g[1]==0:
                color[g[0]]=color[i]
            else:
                color[g[0]]=color[i]*-1
            dps(g[0])
dps(0)
for i in range(N):
    print(1 if color[i]==1 else 0)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**10 for i in range(N)]
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i<N-j:
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])

Fixed submission:
N,K=map(int,input().split())
h=list(map(int,input().split()))
dp=[10**10 for i in range(N)]
dp[0]=0
for i in range(N-1):
    for j in range(1,K+1):
        if i<N-j:
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
aList = list(map(int, input().split()))
col = aList[:n-1]
row = aList[1:]
ansSum = 0
for i in range(n-1):
    for j in range(i,n-1):
        ansSum += col[i]*row[j]
print(ansSum % (7+10**9))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
array_sum_square = sum(A)**2
individual_square_sum = 0
for i in range(0, n, 1):
    individual_square_sum += A[i]**2
print((array_sum_square - individual_square_sum) // 2 % (7 + 10 ** 9))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
n = int(input())
aList = list(map(int, input().split()))
comb = combinations(aList, 2)
ansSum = 0
for i in list(comb):
    ansSum += i[0]*i[1]
print(ansSum%(7+10**9))

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
array_sum_square = sum(A)**2
individual_square_sum = 0
for i in range(0, n, 1):
    individual_square_sum += A[i]**2
print((array_sum_square - individual_square_sum) // 2 % (7 + 10 ** 9))
Buggy python submission (verdict: Runtime Error):
inpt = input()
cap = {Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M}
if inpt in cap:
    print('A')
else:
    print('a')

Fixed submission:
inpt = input()
cap = {'Q','W','E','R','T','Y','U','I','O','P','A','S','D','F','G','H','J','K','L','Z','X','C','V','B','N','M'}
if inpt in cap:
    print('A')
else:
    print('a')
Buggy python submission (verdict: Runtime Error):
import copy
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
dict = {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0,13:0,14:0,15:0,16:0,17:0,18:0,19:0,20:0,21:0,22:0,23:0,24:0,25:0,26:0,27:0,28:0,29:0,30:0,31:0,32:0,33:0,34:0,35:0,36:0,37:0,38:0,39:0,40:0,41:0,42:0,43:0,44:0,45:0,46:0,47:0,48:0,49:0,50:0,51:0,52:0,53:0,54:0,55:0,56:0,57:0,58:0,59:0,60:0,61:0,62:0,63:0,64:0,65:0,66:0,67:0,68:0,69:0,70:0,71:0,72:0,73:0,74:0,75:0,76:0,77:0,78:0,79:0,80:0,81:0,82:0,83:0,84:0,85:0,86:0,87:0,88:0,89:0,90:0,91:0,92:0,93:0,94:0,95:0,96:0,97:0,98:0,99:0,100:0}
for i in pList:
    dict[i] = 1
goUp = True
goDown = True
run = True
upTar = copy.copy(x)
lowTar = copy.copy(x)
theAns = copy.copy(x)
while run:
    if dict[lowTar] == 0:
        theAns = lowTar
        break
    if dict[upTar] == 0:
        theAns = upTar
        break
    if goUp:
        upTar += 1
    if goDown:
        lowTar -= 1
    if upTar == 100:
        goUp = False
    if lowTar:
        goDown = False
print(theAns)

Fixed submission:
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
pSet = set(pList)
step = 0
small = False
big = False
while True:
    if x - step not in pSet:
        small = True
        break
    if x + step not in pSet:
        big = True
        break
    step += 1
if small:
    print(x-step)
else:
    print(x+step)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
numList = list(map(int, input().split()))
product = 1
for i in numList:
    product *= i
if product > 10**18:
    print(-1)
else:
    print(product)

Fixed submission:
N = int(input())
numList = list(map(int, input().split()))
product = 1
toPrint = True
isZero = False
for j in numList:
    if j == 0:
        isZero = True
if not isZero:
    for i in numList:
        product = product * i
        if product > 10**18:
            toPrint = False
            break
if isZero:
    print(0)
else:
    if toPrint:
        print(product)
    else:
        print(-1)
Buggy python submission (verdict: Runtime Error):
import numpy
[a, b] = list(input().split())
newa = int(a)
product = newa * b
print(int(numpy.floor(product)))

Fixed submission:
[a, b] = list(input().split())
a = int(a)
newb = ''
for i in b:
    if i == '.':
        continue
    newb += i
newb = int(newb)
print((a*newb)//100)
Buggy python submission (verdict: Runtime Error):
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
Alist = []
for i in range(M):
    Alist.append(int(input()))
daysNeeded = sum(Alist)
if daysNeeded>N:
    print(-1)
else:
    print(M - daysNeeded)

Fixed submission:
NM = list(map(int, input().split()))
N = NM[0]
M = NM[1]
Alist = list(map(int, input().split()))
daysNeeded = sum(Alist)
if daysNeeded>N:
    print(-1)
else:
    print(N - daysNeeded)
Buggy python submission (verdict: Time Limit Exceeded):
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
for howManyWeChoose in range(K, N+2):
    lastMembers = []
    firstmembers = []
    for i in range(howManyWeChoose):
        lastMembers.append(N-i)
        firstmembers.append(i)
    until = sum(lastMembers)
    start = sum(firstmembers)
#     sumOfAll += howManyWeChoose * (until - start + 1) * (10 ** 100) + sum(range(start, until + 1))
# print(sumOfAll%(7+10**9))
    sumOfAll += len(range(start, until + 1))
print(sumOfAll%(7+10**9))

Fixed submission:
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
for howManyWeChoose in range(K, N+2):
    until = int(N*(N+1)/2 - (N-howManyWeChoose)*(N-howManyWeChoose+1)/2)
    start = int(howManyWeChoose*(howManyWeChoose-1)/2)
    sumOfAll += until-start+1
print(sumOfAll%(7+10**9))

Buggy python submission (verdict: Runtime Error):
import operator as op
from functools import reduce
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return int(numer / denom)
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
oneToNSum = int((N)*(N+1)/2 - 1)
for k in range(K,N+1):
    NCKm1 = ncr(N, K - 1)
    sumOfAll += N * NCKm1 * 10 ^ 100 + NCKm1 * oneToNSum
print(sumOfAll%(7+10^9))

Fixed submission:
NK = list(map(int, input().split()))
N = NK[0]
K = NK[1]
sumOfAll = 0
for howManyWeChoose in range(K, N+2):
    until = int(N*(N+1)/2 - (N-howManyWeChoose)*(N-howManyWeChoose+1)/2)
    start = int(howManyWeChoose*(howManyWeChoose-1)/2)
    sumOfAll += until-start+1
print(sumOfAll%(7+10**9))
Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
outSum = 0
for i in range(1,K+1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            outSum += math.gcd(math.gcd(i,j),k)
print(outSum)

Fixed submission:
K=int(input())
L1=[1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 
8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(L1[K-1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
outCount = 0
for i in range(N):
    for j in range(N):
        for k in range(N):
            if S[i]==S[j] or S[j]==S[k] or S[i]==S[k]:
                continue
            elif j-i == k-j:
                continue
            elif i<j<k:
                outCount += 1
print(outCount)

Fixed submission:
N = int(input())
S = input()
noCount = {'R': 0, 'G': 0, 'B': 0}
minusCount = 0
for i in S:
    if i == 'R':
        noCount['R'] += 1
    elif i == 'G':
        noCount['G'] += 1
    elif i == 'B':
        noCount['B'] += 1
RGB = noCount['R']*noCount['G']*noCount['B']

for step in range(1, (N+1)//2):
    for cenPos in range(step, N-step):
        if S[cenPos - step] != S[cenPos] and S[cenPos] != S[cenPos + step] and S[cenPos - step] != S[cenPos + step]:
            minusCount += 1
print(RGB - minusCount)
Buggy python submission (verdict: Runtime Error):
N = input()
print((N+1)/2)

Fixed submission:
N = int(input())
if N%2 != 0:
    print(((N+1)/2)/N)
if N%2 == 0:
    print(1/2)

Buggy python submission (verdict: Runtime Error):
print((input()+1)/2)

Fixed submission:
N = int(input())
if N%2 != 0:
    print(((N+1)/2)/N)
if N%2 == 0:
    print(1/2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = list(map(int, input().split()))
ordList = []
for i in range(1,N+1):
    ordList.append(str(As.index(i)+1))
print(' '.join(ordList))

Fixed submission:
N = int(input())
As = list(map(int, input().split()))
ordList = [None] * N
noCount = 1
for i in As:
    ordList[i-1] = str(noCount)
    noCount += 1
print(' '.join(ordList))
Buggy python submission (verdict: Runtime Error):
import numpy as np
S = input()
l = len(S)
oddArr = np.arange(0,l+1,2)
evenArr = np.arange(1,l,2)
playable = True
for i in oddArr:
    if S[i]=='R' or S[i]=='U' or S[i]=='D':
        continue
    else:
        playable = False
        break
if playable:
    for i in evenArr:
        if S[i] == 'L' or S[i] == 'U' or S[i] == 'D':
            continue
        else:
            playable = False
            break
if playable:
    print('Yes')
else:
    print('No')

Fixed submission:
import numpy as np
S = input()
l = len(S)
oddArr = np.arange(1,l+1,2)
evenArr = np.arange(2,l+1,2)
playable = True
for i in oddArr:
    if S[i-1]=='R' or S[i-1]=='U' or S[i-1]=='D':
        continue
    else:
        playable = False
        break
if playable:
    for i in evenArr:
        if S[i-1] == 'L' or S[i-1] == 'U' or S[i-1] == 'D':
            continue
        else:
            playable = False
            break
if playable:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

if K%10==0 or K%10==2 or K%10==4 or K%10==5 or K%10==6 or K%10==8:
    print(-1)
else:
    num = 0
    i = 0
    while True:
        num += 7 * 10**i
        if num%K == 0:
            break
        i += 1
    print(i+1)


Fixed submission:
K = int(input())

if K % 7 == 0:
    L = 9 * K / 7
else:
    L = 9 * K

if L % 2 == 0 or L % 5 == 0:
    print(-1)
else:
    rest = 1
    ans = 0
    while True:
        rest *= 10
        ans += 1
        rest = rest % L
        if rest == 1:
            break
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())

for i in range(1, N+1):
    ans = 0
    n = int(math.sqrt(i))+1
    for x in range(1, n+1):
        for y in range(1, x+1):
            for z in range(1, y+1):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    if x == y == z:
                        ans += 1
                    elif x == y or y == z:
                        ans += 3
                    else:
                        ans += 6
    print(ans)

Fixed submission:
import math
N = int(input())

ans = [0] * N
n = int(math.sqrt(N)) 

for x in range(1, n+1):
    for y in range(1, x+1):
        for z in range(1, y+1):
            i = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if i <= N:
                if x == y == z:
                    ans[i-1] += 1
                elif x == y or y == z:
                    ans[i-1] += 3
                else:
                    ans[i-1] += 6

for j in range(N):
    print(ans[j])

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())

for i in range(1, N+1):
    ans = 0
    n = int(math.sqrt(i))+1
    for x in range(1, n+1):
        for y in range(1, n+1):
            for z in range(1, n+1):
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    ans += 1
    print(ans)

Fixed submission:
import math
N = int(input())

ans = [0] * N
n = int(math.sqrt(N)) 

for x in range(1, n+1):
    for y in range(1, x+1):
        for z in range(1, y+1):
            i = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if i <= N:
                if x == y == z:
                    ans[i-1] += 1
                elif x == y or y == z:
                    ans[i-1] += 3
                else:
                    ans[i-1] += 6

for j in range(N):
    print(ans[j])
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
A = list(map(int, input().split()))
N = int(N)

S = 1
for i in range(N):
    S = S*A[i]

if S > 10 ** 18:
    print(-1)
else:
    print(S)

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

    if 0 in A:
        print(0)
        return

    S = 1
    for i in range(N):
        S *= A[i]
        if S > 10 ** 18:
            print(-1)
            return

    print(S)

main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for _ in range(N)]

ans = []
for i in range(N):
    flg = 0
    for j in range(len(ans)):
        if S[i] == ans[j]:
            flg = 1
            break
    if flg == 0:
        ans.append(S[i])

print(len(ans))

Fixed submission:
N = int(input())

ans = set()

for i in range(N):
    S = input()
    if S in ans:
        continue
    else:
        ans.add(S)

print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for _ in range(N)]

ans = 0
for i in range(N):
    flg = 0
    j = 0
    while j < i:
        if S[j] == S[i]:
            flg = 1
            break
        j += 1
    if flg == 0:
        ans += 1

print(ans)

Fixed submission:
N = int(input())

ans = set()

for i in range(N):
    S = input()
    if S in ans:
        continue
    else:
        ans.add(S)

print(len(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(input()) for _ in range(N)]

ans = 0
for i in range(N):
    flg = 0
    j = 0
    while j < i:
        if S[j] == S[i]:
            flg = 1
            break
        j += 1
    if flg == 0:
        ans += 1

print(ans)

Fixed submission:
N = int(input())

ans = set()

for i in range(N):
    S = input()
    if S in ans:
        continue
    else:
        ans.add(S)

print(len(ans))
Buggy python submission (verdict: Time Limit Exceeded):
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            if i == j == k:
                ans += i+1
            else:
                ans += calc(calc(i+1, j+1), k+1)

print(ans)

Fixed submission:
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += calc(calc(i+1, j+1), k+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += calc(calc(i+1, j+1), k+1)

print(ans)

Fixed submission:
def calc(a, b):
    m = min(a, b)
    l = max(a, b)
    while m != 0:
        s = m
        m = l % m
        l = s
    return l

K = int(input())
ans = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            ans += calc(calc(i+1, j+1), k+1)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

i = 0

while True:
    if (N+i) % K == 0 or (N-i) % K == 0:
        break
    i += 1

print(i)

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

n = N%K
m = K - n

print(min(abs(n), abs(m)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for _ in range(N)]

newS = sorted(list(set(S)))
frq = [0] * len(newS)

for i in range(N):
    for j in range(len(newS)):
        if S[i] == newS[j]:
            frq[j] += 1
            break
ma = max(frq)
for i in range(len(newS)):
    if frq[i] == ma:
        print(newS[i])

Fixed submission:
N = int(input())
S = [input() for _ in range(N)]

S = sorted(S)
newS = sorted(list(set(S)))
frq = [0] * len(newS)

si = index = 0
for i in range(N):
    if i == N-1:
        frq[index] = N - si
    elif S[i] != S[i+1]:
        frq[index] = i + 1 - si
        si = i + 1
        index += 1
    
ma = max(frq)
for i in range(len(newS)):
    if frq[i] == ma:
        print(newS[i])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
H = list(map(int, input().split()))

for i in range(K):
    if len(H) == 0:
        break
    ma = max(H)
    H.remove(ma)

ans = 0
for i in range(len(H)):
    ans += H[i]

print(ans)

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

if N <= K:
    print(0)
else:
    H = sorted(H)
    ans = 0
    for i in range(N-K):
        ans += H[i]
    print(ans)