Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
l=list(map(int,input().split()))
i=0
cnt=0
lcnt=0
sl=[0]*n
for p in range(k):
  if sl[i]==0:
    sl[i]=1
    i=l[i]-1
    cnt+=1
  elif sl[i]==1:
    sl[i]=2
    lcnt+=1
    i=l[i]-1
  else:
    c=(k-cnt)%lcnt
    if c!=0:
      for tmp in range(c):
        i=l[i]-1
        break
print(i+1)

Fixed submission:
n,k=map(int,input().split())
l=list(map(int,input().split()))
i=0
cnt=0
lcnt=0
sl=[0]*n
for p in range(k):
  if sl[i]==0:
    sl[i]=1
    i=l[i]-1
    cnt+=1
  elif sl[i]==1:
    sl[i]=2
    lcnt+=1
    i=l[i]-1
  else:
    c=(k-cnt)%lcnt
    if c!=0:
      for tmp in range(c):
        i=l[i]-1
    break
print(i+1)
Buggy python submission (verdict: Runtime Error):
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
for k in l:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)


Fixed submission:
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
ans=0
for k in an:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
for i in As:
  l=ls.values()
  ans=0
  if i not in subd.keys():
    ls[i]=ls[i]-1
    for k in l:
      ans+=k*(k-1)//2
    subd[i]=ans
    ls[i]=ls[i]+1
  else:
    ans=subd[i]
  print(ans)

Fixed submission:
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
ans=0
for k in an:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
for i in As:
  ls[i]=ls[i]-1
  l=ls.values()
  ans=0
  for k in l:
    ans+=k*(k-1)//2
  ls[i]=ls[i]+1
  print(ans)
  

Fixed submission:
import collections

n=int(input())
As=list(map(int,input().split()))
ls=collections.Counter(As)
subd={}
an=ls.values()
ans=0
for k in an:
  ans+=k*(k-1)//2
sans=ans

for i in As:
  ans=sans+1-ls[i]
  print(ans)
Buggy python submission (verdict: Runtime Error):
l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0,0,0]]*3
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l.index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    print("Yes")
    a=1
  elif ll[1][1]==1 and ll[2][2]==1:
    print("Yes")
    a=1
  elif ll[1][0]==1 and ll[2][0]==1:
    print("Yes")
    a=1
elif ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  print("Yes")
  a=1
elif ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    print("Yes")
    a=1
  elif ll[1][2]==1 and ll[2][2]==1:
    print("Yes")
    a=1
elif ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    print("Yes")
    a=1
elif ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    print("Yes")
    a=1
if a==0:
  print("No")

Fixed submission:
l=[[]]*3
for k in range(3):
  l[k]=list(map(int,input().split()))
n=int(input())
ll=[[0]*3 for i in range(3)]
for k in range(n):
  i=int(input())
  for j in range(3):
    if i in l[j]:
      ll[j][l[j].index(i)]=1
a=0
if ll[0][0]==1:
  if ll[0][1]==1 and ll[0][2]==1:
    a=1
  if ll[1][1]==1 and ll[2][2]==1:
    a=1
  if ll[1][0]==1 and ll[2][0]==1:
    a=1
if ll[0][1]==1 and ll[1][1]==1 and ll[2][1]==1:
  a=1
if ll[0][2]==1:
  if ll[1][1]==1 and ll[2][0]==1:
    a=1
  if ll[1][2]==1 and ll[2][2]==1:
    a=1
if ll[1][0]==1:
  if ll[1][1]==1 and ll[1][2]==1:
    a=1
if ll[2][0]==1:
  if ll[2][1]==1 and ll[2][2]==1:
    a=1
if a==0:
  print("No")
else:
  print("Yes")
Buggy python submission (verdict: Runtime Error):
i=int(input())
l=[""]*i
for k in range(i):
  l[k]=input()
l.sort()
maxi=0
kosu=0
for k in l:
  kosu+=1
  if kosu=maxi:
    li.append(k)
  elif kosu>maxi:
    li.clear()
    li.append(k)
print(*li)

Fixed submission:
i=int(input())
l=[""]*i
for k in range(i):
  l[k]=input()
l.sort()
maxi=0
kosu=0
li=[]
subk=""
for k in l:
  if subk!=k:
    kosu=0
    subk=k
  kosu+=1
  if kosu==maxi:
    li.append(k)
  elif kosu>maxi:
    li.clear()
    li.append(k)
    maxi=kosu
for k in li:
  print(k)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split()))
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0
for j in range(k):
  a+=(i[j+place]+1)//2
print(a)


Fixed submission:
n,k=map(int,input().split())
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0.0
for j in range(k):
  a+=float(i[j+place]+1)/2
print(a)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split()))
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l(j)
  if plus>0:
    place=j+1
    plus=0
a=0
for j in range(k):
  a+=(i[j+place]+1)//2
print(a)

Fixed submission:
n,k=map(int,input().split())
i=list(map(int,input().split()))
l=[0]*(n-k)
for j in range(n-k):
  l[j]=i[j+k]-i[j]
place=0
plus=0
for j in range(n-k):
  plus=plus+l[j]
  if plus>0:
    place=j+1
    plus=0
a=0.0
for j in range(k):
  a+=float(i[j+place]+1)/2
print(a)
Buggy python submission (verdict: Runtime Error):
i=list(map(int,input().split()))
j=list(map(int,input().split()))
c=0
j.sort(reverse=True)
for x in range(i[1]):
  del j[0]
for y in j:
  c+=y
print(str(c))

Fixed submission:
i=list(map(int,input().split()))
j=list(map(int,input().split()))
c=0
cnt=1
n=i[1]
j.sort(reverse=True)
for x in j:
  if cnt>n:
    c+=x
  else:
    cnt+=1
print(str(c))
Buggy python submission (verdict: Time Limit Exceeded):
i=int(input())
nest=1
a=0
p=i
while True:
  nest+=1
  p=p//2
  if p==1:
    break
a=(2**nest)-1
print(a)


Fixed submission:
i=int(input())
nest=1
a=0
p=i
if p==1:
  print(1)
else:
  for k in range(50):
    nest+=1
    p=p//2
    if p==1:
      break
  a=(2**nest)-1
  print(a)

Buggy python submission (verdict: Time Limit Exceeded):
i=int(input())
nest=1
a=0
p=i
while True:
  nest+=1
  p=p//2
  if p==1:
    break
for k in range(nest):
  a+=2**k
print(a)


Fixed submission:
i=int(input())
nest=1
a=0
p=i
if p==1:
  print(1)
else:
  for k in range(50):
    nest+=1
    p=p//2
    if p==1:
      break
  a=(2**nest)-1
  print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
t=[]*n
sec=[]*n
for k in range(n):
  s=input().split()
  t[k]=s[0]
  sec[k]=int(s[1])
x=input()
p=t.index(x)
a=0
if p!=n:
  for l in range(p+1,n):
    a+=sec[l]
print(str(a))

Fixed submission:
n=int(input())
t=[""]*n
sec=[0]*n
for k in range(n):
  s=input().split()
  t[k]=s[0]
  sec[k]=int(s[1])
x=input()
p=t.index(x)
a=0
if p!=n:
  for l in range(p+1,n):
    a+=sec[l]
print(str(a))
Buggy python submission (verdict: Runtime Error):
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

l=list(range(1,n+1))
ll=itertools.permutations(l,n)
pp=ll.index(p)
qq=ll.index(q)
a=pp-qq
if a<0:
  a=a*(-1)
print(str(a))

Fixed submission:
import itertools
n=int(input())
p=tuple(map(int,input().split()))
q=tuple(map(int,input().split()))

l=list(range(1,n+1))
ll=list(itertools.permutations(l,n))
pp=ll.index(p)
qq=ll.index(q)
a=pp-qq
if a<0:
  a=a*(-1)
print(str(a))
Buggy python submission (verdict: Runtime Error):
s=input().split()
i=int(s[0])
j=int(s[1])
k=int(s[2])
if k>=i:
  i=0
  j=j-k+i
else:
  i=i-k
print(str(i)+" "str(j))

Fixed submission:
s=input().split()
i=int(s[0])
j=int(s[1])
k=int(s[2])
if k>=i:
  j=j-(k-i)
  i=0
  if j<0:
    j=0
else:
  i=i-k
print(str(i)+" "+str(j))
Buggy python submission (verdict: Runtime Error):
s=input().split()
i=int(s[0])
j=int(s[1])
amari=[]
a=""
if i<j:
  p_1=j
  p_2=i
elif i==j:
  a=str(i)
elif i>j:
  p_1=i
  p_2=j
while a=="":
  am=p_1%p_2
  if am==0:
    break
  amari.append(am)
  p_1=p_2
  p_2=am
a=str(amari[-1])
print(a)

Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=int(input())
j=int(input())
print(str(6-(i+j))

Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=int(input())
j=int(input())
l=list(range(1,3,1))
l.remove(i)
l.remove(j)
a=l.pop(0)
print(a)

Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=int(input())
j=int(input())
ls=list(range(1,3))
ls.remove(i)
ls.remove(j)
a=ls.pop(0)
print(a)


Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=input()
i.splitlines()
ls=list(range(1,3))
ls.remove(i[0])
ls.remove(i[1])
a=ls.pop()
print(a)


Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=input()
i.splitlines()
ls=list(range(1,3))
ls.remove(int(i[0]))
ls.remove(int(i[1]))
print(ls.pop())


Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=input()
i.splitlines()
ls=list(range(1,3))
ls.remove(i[0])
ls.remove(i[1])
print(ls.pop())

Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))

Buggy python submission (verdict: Runtime Error):
i=int(input())
j=int(input())
ls=range(1,3)
ls.remove(i)
ls.remove(j)
print(ls.pop())

Fixed submission:
i=int(input())
j=int(input())
a=6-(i+j)
print(str(a))
Buggy python submission (verdict: Runtime Error):
s=input()
a=""
if(s.equal("Sunny")):a="Cloudy"
if(s.equal("Cloudy")):a="Rainy"
if(s.equal("Rainy")):a="Sunny"
print(a)


Fixed submission:
s=input()
a=""
if(s=="Sunny"):a="Cloudy"
if(s=="Cloudy"):a="Rainy"
if(s=="Rainy"):a="Sunny"
print(a)

Buggy python submission (verdict: Runtime Error):
s=input()
a=""
if(s.equal("Sunny")):a="Cloudy"
if(s.equal("Cloudy")):a="Rainy";
if(s.equal("Rainy")):a="Sunny";
print(a)

Fixed submission:
s=input()
a=""
if(s=="Sunny"):a="Cloudy"
if(s=="Cloudy"):a="Rainy"
if(s=="Rainy"):a="Sunny"
print(a)

Buggy python submission (verdict: Runtime Error):
s=input();
a="";
if(s.equal("Sunny"))
  a="Cloudy";
if(s.equal("Cloudy"))
  a="Rainy";
if(s.equal("Rainy"))
  a="Sunny";
print(a)

Fixed submission:
s=input()
a=""
if(s=="Sunny"):a="Cloudy"
if(s=="Cloudy"):a="Rainy"
if(s=="Rainy"):a="Sunny"
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
s=input().split("01")
a=len(s)-1
t="".join(s)
while True:
  s=t.split("01")
  if len(s)==1:
    while True:
      s=t.split("10")
      if len(s)==1:
        break
      a+=len(s)-1
      t="".join(s)
    break
  a+=len(s)-1
  t="".join(s)
print(2*a)


Fixed submission:
s=input()
a=s.count("0")
b=len(s)-a
if a>=b:
  print(2*b)
else:
  print(2*a)

Buggy python submission (verdict: Time Limit Exceeded):
s=input().split("01")
a=len(s)-1
t="".join(s)
while True:
  s=t.split("01")
  if len(s)==1:
    while True:
      s=t.split("10")
      if len(s)==1:
        break
      a+=len(s)-1
    break
  a+=len(s)-1
  t="".join(s)
print(2*a)

Fixed submission:
s=input()
a=s.count("0")
b=len(s)-a
if a>=b:
  print(2*b)
else:
  print(2*a)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
l=[[0]*w]*h
m=[""]*h
for k in range(h):
  m[k]=input()
l[0][0]=1
for k in range(h):
  for j in range(w):
    if m[k][j]=="#":
      l[k][j]=0
    else:
      if k==0:
        if j!=0:
          l[k][j]=l[0][j-1]
      elif j==0:
        if k!=0:
          l[k][j]=l[k-1][j]
      else:
        l[k][j]=l[k-1][j]+l[k][j-1]
print(l[h][w]%1000000007)

Fixed submission:
h,w=map(int,input().split())
l=[[0]*w]*h
m=[""]*h
for k in range(h):
  m[k]=input()
l[0][0]=1
for k in range(h):
  for j in range(w):
    if m[k][j]=="#":
      l[k][j]=0
    else:
      if k==0:
        if j!=0:
          l[k][j]=l[0][j-1]
      elif j==0:
        if k!=0:
          l[k][j]=l[k-1][j]
      else:
        l[k][j]=l[k-1][j]+l[k][j-1]
print(l[h-1][w-1]%1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
l=[[0,0]]*m
t=[0]*m
tc=0
a=False
f=0
for k in range(m):
  l[k]=list(map(int,input().split()))
l.sort()
for k in l:
  if (k[0]!=1 and f==0):
    del t[tc:]
    f=1
  if k[0]==1:
    t[tc]=k[1]
    tc+=1
  elif k[1]==n:
    if k[0] in t:
      a=True
      break
if a:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Fixed submission:
n,m=map(int,input().split())
l=[[0,0]]*m
at=[0]*m
bt=[0]*m
atc=0
btc=0
a=False

f=0
for k in range(m):
  ln=list(map(int,input().split()))
  if ln[0]==1:
    at[atc]=ln[1]
    atc+=1
  elif ln[1]==n:
    bt[btc]=ln[0]
    btc+=1
del at[atc:]
del bt[btc:]
at.sort()
bt.sort()
c=list(set(at)^set(bt))
if len(c)!=(atc+btc):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
l=[[0,0]]*m
t=[0]*m
tc=0
a=False
f=0
for k in range(m):
  l[k]=list(map(int,input().split()))
l.sort()
for k in l:
  if k[0]!=1 & f==0:
    del t[tc:]
  if k[0]==1:
    t[tc]=k[1]
    tc+=1
  elif k[1]==n:
    if k[0] in t:
      a=True
      break
if a:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")


Fixed submission:
n,m=map(int,input().split())
l=[[0,0]]*m
at=[0]*m
bt=[0]*m
atc=0
btc=0
a=False

f=0
for k in range(m):
  ln=list(map(int,input().split()))
  if ln[0]==1:
    at[atc]=ln[1]
    atc+=1
  elif ln[1]==n:
    bt[btc]=ln[0]
    btc+=1
del at[atc:]
del bt[btc:]
at.sort()
bt.sort()
c=list(set(at)^set(bt))
if len(c)!=(atc+btc):
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,K = mips()
ans = 10**9
P = [p for p in mips()]
L = list(map(list,itertools.permutations(P,K)))
for el in L:
    ans = min(ans,sum(el))
print(ans)
    


Fixed submission:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,K = mips()
ans = 0
P = [p for p in mips()]
P.sort()
for i in range(K):
    ans += P[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
S = int(input())
ans = S[0:3]
print(ans)

Fixed submission:
S = input()
ans = S[0:3]
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [el for el in map(int,input().split())]
if 0 in A : 
    print(0)
    sys.exit(0)
res = 1
for el in A:
  res *= el
  if res - 10**18 > 0:
    print(-1)
    sys.exit(0)
print(res)

Fixed submission:
import sys
N = int(input())
A = [el for el in map(int,input().split())]
if 0 in A : 
    print(0)
    sys.exit(0)
res = 1
for el in A:
  res *= el
  if res - 10**18 > 0:
    print(-1)
    sys.exit(0)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [el for el in map(int,input().split())]
res = 1
for el in A:
  res *= el
if res <= 10**18:
  print(res)
else:
  print(-1)
  

Fixed submission:
import sys
N = int(input())
A = [el for el in map(int,input().split())]
if 0 in A : 
    print(0)
    sys.exit(0)
res = 1
for el in A:
  res *= el
  if res - 10**18 > 0:
    print(-1)
    sys.exit(0)
print(res)
Buggy python submission (verdict: Runtime Error):
><

Fixed submission:
from decimal import Decimal
A, B = map(Decimal, input().split())
print(int(A * B))

Buggy python submission (verdict: Runtime Error):
import math
A,B = map(float,input().split())
A = int(A)
if A == 0 or B == 0 :
    print(0)
else:
    ans = A*B
    i = math.floor(ans)-1
    while True : 
        if i <= ans and i+1 > ans:
            print(i)
            sys.exit(0)
        i += 1

Fixed submission:
from decimal import Decimal
A, B = map(Decimal, input().split())
print(int(A * B))
Buggy python submission (verdict: Runtime Error):
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())

import sys
import itertools
N,M,X = mips()
know = dict()
price = [[] for _ in range(N)]
A = [[] for _ in range(M)]
L = []
C = []
for i in range(M):
    know[i] = 0
for i in range(N):
    L.append([i for i in mips()])
    C.append(L[i][0])
    L[i].remove(L[i][0])
for i in range(N):
    for k in range(M):
        A[k].append(L[i][k])
Money = []
paid = 0 
K = []
No = 0
P = []
Q = [i for i in range(N)]
for i in range(N):
    P.append(list(itertools.combinations(Q,i)))
for k in range(N):
    for el in P[k]:
        for book in el:
            K = L[book]
            paid += C[book]
            for i in range(M):
                know[i] += K[i]
        for i in range(M):
            if know[i] < X:
                No = 1
                break
        if No == 0:
            Money.append(paid)
        paid = 0
        No = 0
        for i in range(M):
            know[i] = 0
print(min(Money))

Fixed submission:
def mips():
    return map(int,input().split())
def msps():
    return map(str,input().split())

import sys
import itertools
N,M,X = mips()
know = dict()
price = [[] for _ in range(N)]
L = []
C = []
for i in range(M):
    know[i] = 0
for i in range(N):
    L.append([i for i in mips()])
    C.append(L[i][0])
    L[i].remove(L[i][0])
Money = []
paid = 0 
K = []
No = 0
P = []
Q = [i for i in range(N)]
for i in range(N+1):
    P.append(list(itertools.combinations(Q,i)))
for k in range(N+1):
    for el in P[k]:
        for book in el:
            K = L[book] 
            paid += C[book]
            for i in range(M):
                know[i] += K[i]
        for i in range(M):
            if know[i] < X:
                No = 1
                break
        if No == 0:
            Money.append(paid)
        paid = 0
        No = 0
        for i in range(M):
            know[i] = 0
if Money == []:
    print("-1")
else:
    print(min(Money))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [i for i in map(int,input().split())]
S = set(L)
for i in range(1,N+1):
    if i in S:
        print(L.count(i))
    else:
        print(0)

Fixed submission:
N = int(input())
L = [i for i in map(int,input().split())]
ans = dict()
for i in range(1,N+1):
    ans[i] = 0
for el in L:
    if el in ans:
        ans[el] += 1
for i in range(1,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = [i for i in map(int,input().split())]
c = max(L)
for i in range(1,N+1):
    print(L.count(i))

Fixed submission:
N = int(input())
L = [i for i in map(int,input().split())]
ans = dict()
for i in range(1,N+1):
    ans[i] = 0
for el in L:
    if el in ans:
        ans[el] += 1
for i in range(1,N+1):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
res = 0
N = int(input())
for a in range(1,N+1):
  for b in range(1,N+1):
    for c in range(1,N+1):
      res += math.gcd(math.gcd(a,b),c)
print(res)

Fixed submission:
N = int(input())
L = [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(L[N-1])
Buggy python submission (verdict: Runtime Error):
import fractions
import sys
N,K = map(int,input().split())
L = []
L.append(N)
i = 0
if N == K:
    print(N)
    sys.exit(0)
if N == 0:
    print(0)
    sys.exit(0)
if K == 1:
    print(0)
    sys.exit(0)
Q = 0
while True:
  L.append(abs(N-K))
  N = abs(N-K)
  i += 1
  if i > 10**5:
    Q = min(L)
    break
if (N%2 == 0 and K%2 == 0):
  if N > K:
    print(0)
    sys.exit(0)
  else:
    print(N)
    sys.exit(0)
if (N%2 != 0 and K%2 != 0):
  if N<K:
    print(N)
    sys.exit(0)
  else:
    print(min(N,abs(N-K),Q))
    sys.exit(0)
else:
  if N > K:
   	if N%K == 0:
      print(0)
      sys.exit(0)
    else:
      print(min(N,Q,fractions.gcd(N,K)))
      sys.exit(0)
  else:
    print(min(N,Q))
  

Fixed submission:
import fractions
import sys
N,K = map(int,input().split())
L = []
L.append(N)
i = 0
if N == K:
    print(0)
    sys.exit(0)
if N == 0:
    print(0)
    sys.exit(0)
if K == 1:
    print(0)
    sys.exit(0)
Q = 0
N-=((N//K)*K)
while True:
  L.append(abs(N-K))
  N = abs(N-K)
  i += 1
  if i > 10**5:
    Q = min(L)
    break
if N%K == 0 and N>=K:
    print(0)
else:
    if N < K:
        print(min(N,Q))
    else:
        print(min(N%K,Q,fractions.gcd(N,K)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
import copy
import math
def nP2(N):
    return (math.factorial(N)/((math.factorial(2))*math.factorial(N-2)))
L = list(map(int,input().split()))
Count = [0 for _ in range(N+1)]
for el in L:
    Count[el]+=1
for balls in L:
    res = 0
    Count[balls]-=1
    for i in Count:
        if i >= 2:
            res += nP2(i)
    Count[balls] += 1
    print(int(res))

Fixed submission:
N = int(input())
import copy
import math
def nP2(N):
    return (math.factorial(N)/((math.factorial(2))*math.factorial(N-2)))
L = list(map(int,input().split()))
Count = [0 for _ in range(N+1)]
for el in L:
    Count[el]+=1
res = 1
for i in Count:
    if i>=2:
        res += nP2(i)
for balls in L:
    print(int(res-Count[balls]))