Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

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

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

if ans<=10**18:
    print("{}".format(ans))

else:
    print("{}".format(-1))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np

N = int(input())
A = list(map(int, input().split()))
#A = np.array(A)
ans = 1
c = 1
for i in range(N):
    ans = ans*A[i]
    if ans > 10**18:
        #print("{}".format(-1))
        c=0
        break

if c==1:
    print("{}".format(ans))
elif c==0:
    if 0 in A:
        print("{}".format(0))
    else:
        print("{}".format(-1))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import math

A, B = input().split()
A = int(A)
B_float = float(B)
B_int = int(B[0]+B[2:])
if B_float < 1:
    B_float = B_float*100
    C = A*B_float/100
    #C_str = str(C)
    print("{}".format(int(C)))
else:
    C = A*B_int
    C_str = str(C)
    #iti = C_str.find('.')
    print("{}".format(int(C_str[:-2])))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import math

A, B = input().split()
A = int(A)
B_float = float(B)
B_int = int(B[0]+B[2:])
if B_float < 1:
    B_float = B_float*100
    C = A*B_float/100
    #C_str = str(C)
    print("{}".format(int(C)))
elif not A==0:
    C = A*B_int
    C_str = str(C)
    #iti = C_str.find('.')
    print("{}".format(int(C_str[:-2])))
elif A==0:
    print("{}".format(0))

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import numpy as np
import math

A, B = input().split()
A = int(A)
B_float = float(B)
B_int = int(B[0]+B[2:])
if B_float < 1:
    B_float = B_float*100
    C = A*B_float/100
    #C_str = str(C)
    print("{}".format(int(C)))
else:
    C = A*B_int
    C_str = str(C)
    iti = C_str.find('.')
    print("{}".format(int(C_str[:-2])))


Fixed submission:
# -*- coding: utf-8 -*-
import numpy as np
import math

A, B = input().split()
A = int(A)
B_float = float(B)
B_int = int(B[0]+B[2:])
if B_float < 1:
    B_float = B_float*100
    C = A*B_float/100
    #C_str = str(C)
    print("{}".format(int(C)))
elif not A==0:
    C = A*B_int
    C_str = str(C)
    #iti = C_str.find('.')
    print("{}".format(int(C_str[:-2])))
elif A==0:
    print("{}".format(0))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N, K=map(int, input().split())
A = list(map(int,input().split()))
now=0
rireki=[0]*N
for i in range(K):
    if rireki[now]==0:
        rireki[now]=1
    else:
        loop=i+1
        break

#    print("{}".format(now))
    now=A[now]-1


amari=K%loop
for i in range(amari):
    now=A[now]-1

print("{}".format(A[now]))


Fixed submission:
# -*- coding: utf-8 -*-

N, K=map(int, input().split())
A = list(map(int,input().split()))
now=0
rireki=[0]*N
isou=1
hazimete=0
for i in range(4*N):
    if rireki[now]==0:
        rireki[now]=1
        startnum=i
        start=now
    else:
        if hazimete==1:
            startnum=i
            start=now
        hazimte=1
        if rireki[now]==1:
            rireki[now]=2
        else:
            if rireki[now]==2:
                rireki[now]=3
                isou=i-startnum-1
                break
    #print("{}".format(now))
    now=A[now]-1

#print("{}".format(isou))
amari=(K-startnum-1)%isou

for i in range(amari):
    now=A[now]-1
#print("{}".format(amari))
if K>startnum:
    print("{}".format(now+1))
else:
    now=0
    for i in range(K):
        now=A[now]-1
    print("{}".format(now+1))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
d = [0]*K

C = [0]*N
for i in range(K):
    d[i]=int(input())
    A=list(map(int, input().split()))
    for j in range(N):
        for k in range(d[i]):
            if A[k]==j+1:
                C[j]=1
                break

count=0
for i in range(N):
    if C[i]==0
    count+1


print("{}".format(count))


Fixed submission:
# -*- coding: utf-8 -*-

N, K = map(int, input().split())
d = [0]*K

C = [0]*N
for i in range(K):
    d[i]=int(input())
    A=list(map(int, input().split()))
    for j in range(N):
        for k in range(d[i]):
            if A[k]==j+1:
                C[j]=1
                break

count=0
for i in range(N):
    if C[i]==0:
        count=count+1

#print("{}".format(C))
print("{}".format(count))
Buggy python submission (verdict: Runtime Error):
 -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
sheet = [0]*(N)
for i in range(N-1):
    sheet[A[i]-1]=sheet[A[i]-1]+1


for i in range(N):
    print("{}".format(sheet[i]))


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
sheet = [0]*(N)
for i in range(N-1):
    sheet[A[i]-1]=sheet[A[i]-1]+1


for i in range(N):
    print("{}".format(sheet[i]))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


K = int(input())
x=0
for i in range(K):
    for j in range(K):
        g1=gcd(i+1,j+1)
        for k in range(K):
            g2=gcd(g1,k+1)
            x=x+g2
            #print("{}".format(g))
print("{}".format(x))


Fixed submission:
# -*- coding: utf-8 -*-

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


K = int(input())
G = [[0]*K for i in range(K)]
x=0
for i in range(K):
    for j in range(K):
        g1=gcd(i+1,j+1)
        G[i][j]=g1

for i in range(K):
    for j in range(K):
        for k in range(K):
            g1=G[i][j]
#            print("{}".format(g1))
            x=x+G[g1-1][k]
#        for k in range(K):
#            g2=gcd(g1,k+1)
#            x=x+g2
            

print("{}".format(x))
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

X = int(input())

a = int(X/500)
b = int((X-500*a)/5
print("{}".format(1000*a+5*b))


Fixed submission:
# -*- coding: utf-8 -*-

X = int(input())

a = int(X/500)
b = int((X-500*a)/5)
print("{}".format(1000*a+5*b))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
List = list(map(int,input().split()))
num = 1
for i in List:
  num *= i
if num <= 10**18:
  print(num)
else:
  print(-1)

Fixed submission:
N = int(input())
List = list(map(int,input().split()))
import math
def seki(L):
  num = 1
  for i in L:
    num *= i
  return num
def Seki(L):
  if len(L) <= int(math.sqrt(N)):
    return seki(L)
  else:
    return Seki(L[:len(L)//2]) * Seki(L[len(L)//2:])
if Seki(List) <= 10**18:
  print(Seki(List))
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M = map(float,input().split())
X = sqrt(A**2+B**2-2*A*B*math.cos(math.radians(5.5*M-30*H)))
print(X)

Fixed submission:
import math
A,B,H,M = map(float,input().split())
X = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(5.5*M-30*H)))
print(X)
Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k == K:
    MM = 1
    P = i
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM == 1:
  print(P+1)
else:
  print(Y[B]+1)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k == K:
    MM = 1
    P = i
    break
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM == 1:
  print(P+1)
else:
  print(Y[B]+1)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k == K:
    MM = 1
    P = i
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM = 1:
  print(P+1)
else:
  print(Y[B]+1)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k == K:
    MM = 1
    P = i
    break
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM == 1:
  print(P+1)
else:
  print(Y[B]+1)

Buggy python submission (verdict: Runtime Error):
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k = K:
    MM = 1
    P = i
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM = 1:
  print(P+1)
else:
  print(Y[B]+1)

Fixed submission:
N, K = map(int,input().split())
A = list(map(int,input().split()))
X = [-1 for j in range(N)]
X[0] = 0
Y = [0]
i = 0
Num = 0
MM = 0
for k in range(1,N):
  i = A[i]-1
  if k == K:
    MM = 1
    P = i
    break
  elif X[i] != -1:
    Num = X[i]
    break
  else:
    X[i] = k
    Y.append(i)
Y = Y[Num:]
B = (K-Num)%len(Y)
if MM == 1:
  print(P+1)
else:
  print(Y[B]+1)
Buggy python submission (verdict: Runtime Error):
N, K = int(input().split())
Sunuke = set(range(N))
for i in range(K):
  d = int(input())
  X = list(map(int, input().split()))
  for x in X:
    Sunuke.discard(x-1)
print(len(Sunuke))

Fixed submission:
N, K = input().split()
N = int(N)
K = int(K)
Sunuke = set(range(N))
for i in range(K):
  d = int(input())
  X = list(map(int, input().split()))
  for x in X:
    Sunuke.discard(x-1)
print(len(Sunuke))
Buggy python submission (verdict: Time Limit Exceeded):
X = int(input())
x = 1
while ((x-1)**2)*9 < X:
    x += 1
for i in range(x):
    for j in range(-x, i):
        if i**5-j**5 == X:
            a = [i,j]
            break 
print(*a)


Fixed submission:
X = int(input())
x = 1
while ((x-1)**4)*5 < X:
    x += 1
for i in range(x):
    for j in range(-x, i):
        if i**5-j**5 == X:
            a = [i,j]
            break 
print(*a)
Buggy python submission (verdict: Runtime Error):
import itertools
N, M, Q = input().split()
N = int(N)
M = int(M)
Q = int(Q)
num = [0]*Q
for i in range(Q):
  num[i] = [list(map(int,input().split()))]
num = list(range(1, M+1))
A = []
for v in itertools.combinations(num, N):
  A.append(list(v))
score = 0
for w in A:
  scoreX = 0
  for j in range(Q):
    b = num[j][1]
    a = num[j][0]
    if num[j][2] == w[b-1]-w[a-1]:
      scoreX += num[j][3]
  if scoreX > score:
    score = scoreX
print(str(score))

Fixed submission:
import itertools
N, M, Q = input().split()
N = int(N)
M = int(M)
Q = int(Q)
Num = [0 for i in range(Q)]
for i in range(Q):
  Num[i] = list(map(int,input().split()))
num = list(range(1, M+1))
A = []
for v in itertools.combinations_with_replacement(num, N):
  A.append(list(v))
score = 0
for w in A:
  scoreX = 0
  for j in range(Q):
    b = Num[j][1]
    a = Num[j][0]
    if Num[j][2] == w[b-1]-w[a-1]:
      scoreX += Num[j][3]
  if scoreX > score:
    score = scoreX
print(str(score))
Buggy python submission (verdict: Runtime Error):
A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
value = math.floor(A*(B-1)/B)
max = 0
for i in range(B):
  a = int(math.floor(A*x/B)-A*math.floor(x/B))
  if a > max:
    max = a
if N < B-1:
  print(a)
else:
  print(value)

Fixed submission:
A, B, N = input().split()
A = float(A)
B = float(B)
N = float(N)
import math
value = math.floor(A*(B-1)/B)
a = int(math.floor(A*N/B)-A*math.floor(N/B))
if N < B-1:
  print(a)
else:
  print(value)
Buggy python submission (verdict: Runtime Error):
import itertools
import math
N = input()
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
permutation = list(itertools(N))
for i in range(len(permutation)):
  if P == permutation[i]:
    a = i
  elif Q == permutation[i]:
    b = i
print(math.fabs(a-b))

Fixed submission:
def f(x):
    return x-1
import itertools
import math
N = int(input())
P = list(map(int, input().split()))
P = list(map(f, P))
Q = list(map(int, input().split()))
Q = list(map(f, Q))
S = list(range(N))
permutation = list(itertools.permutations(S))
a,b = 0,0
for i in range(len(permutation)):
    if P == list(permutation[i]):
        a = i
    if Q == list(permutation[i]):
        b = i
print(int(math.fabs(a-b)))
Buggy python submission (verdict: Runtime Error):
N, M = input().split()
K = []
P = []
adjacent = [[0] for i in range(M)]
for i in range(M):
  A = list(input())
  K[i] = A[0]
  adjacent[i] = A[1:]
P = list(input())
X = 0
a = [[0] for i in range(M)]
for i in range(2**N):
  b = []
  for j in range(N):
    if i%2 == 1:
      b.append(j)
    i = i//2
  for j in range(M):
    if len(set(b)&set(adjacent[j]))%2 == P[j]:
      a[j] = 1
  if sum(a) == M:
    X += 1
print(X)
    

Fixed submission:
N, M = map(int, input().split())
K = [[0] for i in range(M)]
adjacent = [[0]*N for i in range(M)]
for i in range(M):
    A = list(input().split())
    K[i] = A[0]
    for j in A[1:]:
        adjacent[i][int(j)-1] = 1
P = list(input().split())
X = 0
for i in range(2**N):
  a = 0
  b = [0]*N
  for j in range(N):
    if i%2 == 1:
      b[j] = 1
    i = i//2
  for j in range(M):
    if  sum([x*y for (x,y) in zip(b, adjacent[j])])%2 == int(P[j]):
      a += 1
  if a == M:
    X += 1
print(X)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=N//15
R=S-1
A=60+15*8*R
T=(60+A)*S//2
M=N-15*S
P=[1,2,4,7,8,11,13,14]
P1=[]
for u in P:
    P1.append(u+15*R)

B=0
for i in range(M):
    B=B+P1[i]

print(B+T)

Fixed submission:
N=int(input())
S=N//15
P=[1,2,4,7,8,11,13,14]
P2=[3,5,6,9,10,12]
Q=0
D=0
if S==0:
    for i in range(1,N+1):
        if i in P2:
            continue
        else:
            D=D+i
else:
    T=S-1
    D=(60+60+15*T*8)*S//2
    N1=N-15*S
    for i in range(1,N1+1):
        if i in P2:
            continue
        else:
            D=D+i+15*S

print(D)

Buggy python submission (verdict: Runtime Error):
N=int(input())
S=N//15
R=S-1
A=60+15*8*R
T=(60+A)*S//2
M=N-15*S
P=[1,2,4,7,8,11,13,14]
P1=[]
for u in P:
    P1.append(u+15*R)

B=0
for i in range(M):
    B=B+P1[i]

print(B+T)

Fixed submission:
N=int(input())
S=N//15
P=[1,2,4,7,8,11,13,14]
P2=[3,5,6,9,10,12]
Q=0
D=0
if S==0:
    for i in range(1,N+1):
        if i in P2:
            continue
        else:
            D=D+i
else:
    T=S-1
    D=(60+60+15*T*8)*S//2
    N1=N-15*S
    for i in range(1,N1+1):
        if i in P2:
            continue
        else:
            D=D+i+15*S

print(D)
Buggy python submission (verdict: Time Limit Exceeded):
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)

while N > 1000*K:
    N=N-1000*K
    if N <=1000*K:
        break

while N > 100*K:
    N=N-100*K
    if N <=100*K:
        break

if N > K:
    while N > K:
        N=N-K
        if N <= K:
            break

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)
    




Fixed submission:
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)



if N > K:

    


    if N >2*K:
        L=N//K
        N=N-L*K
    else:
        N=N-K
    

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)

while N > 100*K:
    N=N-100*K
    if N <=100*K:
        break

if N > K:
    while N > K:
        N=N-K
        if N <= K:
            break

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)
    




Fixed submission:
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)



if N > K:

    


    if N >2*K:
        L=N//K
        N=N-L*K
    else:
        N=N-K
    

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)

if N > K:
    while N > K:
        N=N-K
        if N <= K:
            break

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)
    




Fixed submission:
s=input().split()

N=int(s[0])
K=int(s[1])

if N > K/2 and N < K:
    print(abs(N-K))

if N <= K/2:
    print(N)

if N==K:
    print(0)



if N > K:

    


    if N >2*K:
        L=N//K
        N=N-L*K
    else:
        N=N-K
    

    if N > K/2 and N < K:
        print(abs(N-K))

    if N <= K/2:
        print(N)

    if N==K:
        print(0)
Buggy python submission (verdict: Runtime Error):
s=input()
if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    pirnt(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
else:
    print(1)
 


Fixed submission:
s=input()
if s=="SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":
    print(3)
elif s=="FRI":
    print(2)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
ansl=[]
for i in range(n):
  tmp=input().rstrip()
  if not(tmp in ansl):
    ansl.append(tmp)
print(len(ansl))

Fixed submission:
n=int(input())
ansl=[]
for i in range(n):
  ansl.append(input().rstrip())
print(len(set(ansl)))
Buggy python submission (verdict: Time Limit Exceeded):
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=0
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=tmp+int(i)*10**a
    a+=1
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=0
for i in reversed(s):
    ans[tmp%2019]+=1
    tmp=tmp+int(i)*10**a
    a+=1
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
for i in range(len(s)):
    ans[tmp%2019]+=1
    tmp=10**i*int(s[-i-1])+tmp
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
for i in range(len(s)):
    ans[tmp%2019]+=1
    tmp=pow(10,i)*int(s[-i-1])+tmp
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().rstrip()
ans=[0 for i in range(2019)]
ans[0]=1
for i in range(len(s)):
    tmp=int(s[i:])%2019
    ans[tmp]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=len(s)
#print(s,n)
count=0
for i in range(n-3):
  for j in range(4,n-i+1):
    if int(s[i:i+j])%2019==0:
      count+=1
      #print(i,i+j)
print(count)

Fixed submission:
s=input().rstrip()
ans=[0 for i in range(2019)]
tmp=0
a=1
rs=reversed(s)
for i in rs:
    ans[tmp%2019]+=1
    tmp=(tmp+int(i)*a)%2019
    a*=10
    a%=2019
ans[tmp%2019]+=1
count=0
for i in ans:
    count+=int(i*(i-1)/2)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split(" ")))
# print(n,a)
for j in range(1,n+1):
	a1=[i for i in a if i == j]
	print(len(a1))

Fixed submission:
n=int(input())
a=list(map(int,input().split(" ")))
countlist=[0 for i in range(n)]
for j in range(n-1):
  countlist[a[j]-1]+=1
for i in range(n):
	print(countlist[i])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
import math
ans=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      ans+=math.gcd(math.gcd(i,k),j)
print(ans)

Fixed submission:
n=int(input())
import math
ans=0
for i in range(1,n+1):
  for j in range(1,n+1):
    for k in range(1,n+1):
      ans+=math.gcd(math.gcd(i,k),j)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input().rstrip()
count=0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if (j-i)!=(k-j):
                if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                    count+=1
print(count)

Fixed submission:
n=int(input())
s=input().rstrip()
r=s.count("R")
g=s.count("G")
b=s.count("B")
count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        if j+j-i<n:
            if s[i]!=s[j] and s[i]!=s[j+j-i] and s[j]!=s[j+j-i]:
                count+=1
print(r*g*b-count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = list(map(int, input().split(" ")))
ans = []

sum = 0
for i in range(1, n + 1):
    tmp = numlist.count(i)
    sum += int(tmp * (tmp - 1) / 2)

for i in numlist:
    print(sum - numlist.count(i) + 1)


Fixed submission:
n = int(input())
numlist = list(map(int, input().split(" ")))

import collections

numcount=collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = list(map(int, input().split(" ")))
ans = []

for i in range(1, n + 1):
    ans.append(numlist.count(i))

sum = 0
for i in ans:
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - ans[i - 1] + 1)


Fixed submission:
n = int(input())
numlist = list(map(int, input().split(" ")))

import collections

numcount=collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
numlist = list(map(int, input().split(" ")))
ans = []

for i in range(1, n + 1):
    ans.append(numlist.count(i))

for i in numlist:
    ans[i - 1] -= 1
    sum = 0
    for j in ans:
        sum += int(j * (j - 1) / 2)
    print(sum)
    ans[i - 1] += 1


Fixed submission:
n = int(input())
numlist = list(map(int, input().split(" ")))

import collections

numcount=collections.Counter(numlist)


sum = 0
for i in numcount.values():
    sum += int(i * (i - 1) / 2)

for i in numlist:
    print(sum - numcount[i] + 1)