Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
K = int(input())

flagtail = 0
old_s = ""
cnt = 0
for s_ in S:
	if s_ == old_s:
		cnt +=1
		old_s = ""
	else:
		old_s = s_

ans = cnt * K

if S[-1] != S[-2] and S[0]==S[-1]:
	ans += (K-1)

print(ans)

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

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

S = input()
K = int(input())


if len(S) >= 1:
	flagtail = 0
	old_s = ""
	cnt = 0
	for s_ in S:
		if s_ == old_s:
			cnt +=1
			old_s = ""
		else:
			old_s = s_
	ans = cnt

	cnt1 = cnt
	old_s = ""

	if(K > 1 and K %2 == 0):
		S = S*2
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)

	if(K > 1 and K %2 != 0):
		S = S*3
		cnt1 = cnt
		cnt = 0
		old_s = ""
		for s_ in S:
			if s_ == old_s:
				cnt +=1
				old_s = ""
			else:
				old_s = s_

		ans = cnt1 + (cnt-cnt1)*(K-1)//2
	print(ans)
else:
	print(K//2)
Buggy python submission (verdict: Runtime Error):
n=int(input)-1
print((1+n)*n//2)

Fixed submission:
n=int(input())-1
print((1+n)*n//2)
Buggy python submission (verdict: Runtime Error):
n=input()
if(n&1):
    print(0)
else:
    ans=0
    n /= 2
    while(n>=5):
        ans += n//5
        n //= 5
    print(ans)

Fixed submission:
n=int(input())
if(n&1):
    print(0)
else:
    ans=0
    n /= 2
    while(n>=5):
        ans += n//5
        n //= 5
    print(ans)
Buggy python submission (verdict: Runtime Error):
a=int(input())
if a==1:
  print(0)
if a==0
  print(1)

Fixed submission:
a=int(input())
if a==1:
  print(0)
if a==0:
  print(1)
Buggy python submission (verdict: Runtime Error):
import sys

def solve(N: int, A: "List[int]"):
    result = 0.
    for i in range(N):
        result += 1./A[i]
    print(1./result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(a: int, s: str):
    if a >= 3200:
        print(s)
    else:
        print('red')
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    s = next(tokens)  # type: str
    solve(a, s)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
import sys
import queue

def solve(N: int, Q: int, a: "List[int]", b: "List[int]", p: "List[int]", x: "List[int]"):
    # initialize count
    count = [0] * N
    for j in range(Q):
        count[p[j]-1] += x[j]
    # initialize tree vertice adjacency list
    adj_list = [ [] for i in range(N) ]
    for i in range(N-1):
        u, v = a[i] - 1, b[i] - 1
        adj_list[u] += [v]
        adj_list[v] += [u]
    # BFS from root, which is 0-th node
    explored = [False] * N
    myqueue = queue.Queue()
    explored[0] = True
    myqueue.put(0)
    while(not myqueue.empty()):
        u = myqueue.get()
        for v in adj_list[u]:
            if explored[v] == False:
                myqueue.put(v)
                explored[v] = True
                count[v] += count[u]
    print(' '.join([str(i) for i in count]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]" 
    x = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        p[i] = int(next(tokens))
        x[i] = int(next(tokens))
    solve(N, Q, a, b, p, x)

if __name__ == '__main__':
    main()


Fixed submission:
#!/usr/bin/env python3
import sys
import queue

def solve(N: int, Q: int, a: "List[int]", b: "List[int]", p: "List[int]", x: "List[int]"):
    # initialize count
    count = [0] * N
    for j in range(Q):
        count[p[j]-1] += x[j]
    # initialize tree vertice adjacency list
    adj_list = [ [] for i in range(N) ]
    for i in range(N-1):
        u, v = a[i] - 1, b[i] - 1
        adj_list[u] += [v]
        adj_list[v] += [u]
    # BFS from root, which is 0-th node
    explored = [False] * N
    myqueue = queue.Queue()
    explored[0] = True
    myqueue.put(0)
    while(not myqueue.empty()):
        u = myqueue.get()
        for v in adj_list[u]:
            if explored[v] == False:
                myqueue.put(v)
                explored[v] = True
                count[v] += count[u]
    print(' '.join([str(i) for i in count]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (N-1)  # type: "List[int]" 
    b = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    p = [int()] * (Q)  # type: "List[int]" 
    x = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        p[i] = int(next(tokens))
        x[i] = int(next(tokens))
    solve(N, Q, a, b, p, x)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
from networkx.utils.union_find import UnionFind
n,m=map(int,input().split())
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
uf=UnionFind([i for i in range(n)])
for x in a:
     uf.union(x[0],x[1])
print(len(max(uf.to_sets(),key=len)))

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
n,m=map(int,input().split())
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
g.add_nodes_from([i for i in range(n)])
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Buggy python submission (verdict: Runtime Error):
import networkx as nx
n,m=map(int,input().split())
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Buggy python submission (verdict: Runtime Error):
import networkx as nx
n,m=map(int,input().split())
a=[[tuple(i) for i in input().split()] for _ in range(m)]
g=nx.Graph()
g.add_edges_from(a)
print(sorted([len(i) for i in nx.connected_components(g)])[-1])

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))

Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx

n,m=map(int,input().split())
a=[[tuple(i) for i in input().split()] for _ in range(m)]
g=nx.Graph()
g.add_edges_from(a)
o=1
for i in list(nx.connected_components(g)):
     o=max(o,len(i))
print(o)

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
if m==0:print(1);exit()
a=[[i for i in input().split()] for _ in range(m)]
g=nx.Graph()
for x in a:
     g.add_edge(x[0],x[1])
print(len(sorted(nx.connected_components(g),key=len,reverse=True)[0]))
Buggy python submission (verdict: Runtime Error):

x,k,d=map(int,input().split())

if x==0 and k%2==0:print(0)
if x==0 and k%2==1:print(d)

if x>0 and x>=k*d:print(x-k*d)
if x>0 and x<k*d:
    if ((x-x%d)//d)%2==k%2:print(x%d)
    else:print(abs(x%d-d))
if x<0 and -x>=k*d:print(-x-k*d)
if x<0 and -x<k*d:
    fewa

Fixed submission:
x,k,d=map(int,input().split())

if x==0 and k%2==0:print(0)
if x==0 and k%2==1:print(d)

if x>0 and x>=k*d:print(x-k*d)
if x>0 and x<k*d:
    if ((x-x%d)//d)%2==k%2:print(x%d)
    else:print(abs(x%d-d))
if x<0 and -x>=k*d:print(-x-k*d)
if x<0 and -x<k*d:
    if ((abs(x)-abs(x)%d)//d)%2==k%2:print(-x%d)
    else:print(abs(-x%d-d))
Buggy python submission (verdict: Time Limit Exceeded):
l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

for x in range(1,n+1):
    print(l.count(x))

Fixed submission:
import collections

l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(l)
for x in range(1,n+1):
    print(c[x])

Buggy python submission (verdict: Time Limit Exceeded):
l=[]
n=int(input())
for x in range(1,10**2+1):
    for y in range(1,10**2+1):
        for z in range(1,10**2+1):
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

for x in range(1,n+1):
    print(l.count(x))

Fixed submission:
import collections

l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(l)
for x in range(1,n+1):
    print(c[x])

Buggy python submission (verdict: Time Limit Exceeded):
l=[]
n=int(input())
for x in range(1,10**2+1):
    for y in range(1,10**2+1):
        for z in range(1,10**2+1):
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

for x in range(1,n+1):
    print(l.count(x))

Fixed submission:
import collections

l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(l)
for x in range(1,n+1):
    print(c[x])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
for i in range(1,n+1):
    cnt=0
    for x in range(1,10**2+1):
        for y in range(1,10**2+1):
            for z in range(1,10**2+1):
                if x**2+y**2+z**2+x*y+y*z+z*x==i:cnt+=1
                elif x**2+y**2+z**2+x*y+y*z+z*x>i:break
    print(cnt)

Fixed submission:
import collections

l=[]
n=int(input())
for x in range(1,10**2+1):
    if x**2>n:continue
    for y in range(1,10**2+1):
        if x**2+y**2>n:continue
        for z in range(1,10**2+1):
            if x**2+y**2+z**2>n:continue
            l.append(x**2+y**2+z**2+x*y+y*z+z*x)

c=collections.Counter(l)
for x in range(1,n+1):
    print(c[x])
Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ai=0
bi=0
if sum(a)+sum(b)<k:print(n+m);exit()
ma=0
for x in range(len(a)+1):
    sa=sum(a[:x])
    for y in range(len(b)+1):
        if sa+sum(b[:y])>k:break
        ma=max(ma,x+y)
print(ma)

Fixed submission:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ma=0
for x in range(len(a)+1):
    sa=sum(a[:x])
    for y in range(len(b)+1):
        if sa+sum(b[:y])>k:break
        ma=max(ma,x+y)
print(ma)

Fixed submission:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ma=0
for x in range(len(a)+1):
    sa=sum(a[:x])
    for y in range(len(b)+1):
        if sa+sum(b[:y])>k:break
        ma=max(ma,x+y)
        
print(ma)

Fixed submission:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ma=0
for x in range(len(a)+1):
    for y in range(len(b)+1):
        if sum(a[:x])+sum(b[:y])>k:break
        ma=max(ma,x+y)
        
print(ma)

Fixed submission:
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
import collections

n=int(input())
a=map(int,input().split())
q=int(input())
b=[[int(i) for i in input().split()] for l in range(q)]

c=collections.Counter(a)

for x in b:
    c[x[0]],c[x[1]]=0,c[x[0]]+c[x[1]]
    print(sum([j*k for j,k in c.items()]))

Fixed submission:
import collections

n=int(input())
a=map(int,input().split())
q=int(input())
b=[[int(i) for i in input().split()] for l in range(q)]

c=collections.Counter(a)
s=sum([j*k for j,k in c.items()])
for x in b:
    s=s-x[0]*c[x[0]]+x[1]*c[x[0]]
    c[x[0]],c[x[1]]=0,c[x[0]]+c[x[1]]
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.dijkstra_predecessor_and_distance(g,source=1)

if len(di[0])!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[0][x][0])

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])

Buggy python submission (verdict: Time Limit Exceeded):
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.single_target_shortest_path(g,target=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][1])

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])

Buggy python submission (verdict: Runtime Error):
import networkx as nx
import matplotlib.pyplot as plt
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.single_target_shortest_path(g,target=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][1])

Fixed submission:
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[p-1 for p in a]
l=[0]
i=a[0]
p=-1
q=-1
for x in range(n):
    if i in set(l):break
    l.append(i)
    i=a[i]
d=-1
for x in range(n):
    if a[x]==i:
        d=x
        break
f=l[:d]
b=l[d:]
print(l,f,b,d)
if len(f)==0 or len(b)==0:
    print(l[k%(n-1)]+1)
    exit()

if k<=d:
    print(l[k]+1)
    exit()

k-=len(f)
print(b[k%len(b)]+1)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
visited=[False]*(n+1)
visited[1]=True
l=[1]
i=a[0]

for x in range(n):
    if visited[i]:break
    visited[i]=True
    l.append(i)
    i=a[i-1]

d=-1
for x in range(n):
    if l[x]==i:
        d=x
        break

f=l[:d]
b=l[d:]

if len(f)==0:
    print(b[k%len(b)])
    exit()
 
if len(b)==0:
    print(f[k%len(f)])
    exit()

if k<=d:
    print(l[k])
    exit()
 
k-=len(f)
print(b[k%len(b)])

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=[p-1 for p in a]
l=[0]
i=a[0]
p=-1
q=-1
for x in range(n):
    if i in (l):break
    l.append(i)
    i=a[i]
d=-1
for x in range(n):
    if a[x]==i:
        d=x
        break
f=l[:d]
b=l[d:]
if d==0 or d==n-1 or d==-1:
    print(l[k%(n-1)]+1)
    exit()

if k<=d:
    print(l[k]+1)
    exit()

k-=len(f)
print(b[k%len(b)]+1)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
visited=[False]*(n+1)
visited[1]=True
l=[1]
i=a[0]

for x in range(n):
    if visited[i]:break
    visited[i]=True
    l.append(i)
    i=a[i-1]

d=-1
for x in range(n):
    if l[x]==i:
        d=x
        break

f=l[:d]
b=l[d:]

if len(f)==0:
    print(b[k%len(b)])
    exit()
 
if len(b)==0:
    print(f[k%len(f)])
    exit()

if k<=d:
    print(l[k])
    exit()
 
k-=len(f)
print(b[k%len(b)])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)[::-1]
s=sum(a)
print("Yes" if a[m]>=s/4/m else "No")


Fixed submission:
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)[::-1]
s=sum(a)
print("Yes" if a[m-1]>=s/4/m else "No")
Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import collections
import copy

@lru_cache(maxsize=2*10**5)
def f(p):
    c=copy.deepcopy(b)
    c[x]-=1
    d=collections.Counter(c.values())
    dk=d.keys()
    re=0
    for o in dk:
        if o>1:
            re+=o*(o-1)*d[o]
    return re//2


n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)

for x in a:
    print(f(x))

Fixed submission:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
e=0
for x in b.values():
    e+=x*(x-1)
for x in a:
    t=b[x]
    p=e-t*(t-1)+(t-1)*(t-2)
    print(p//2)

Buggy python submission (verdict: Time Limit Exceeded):
from functools import lru_cache
import collections
import copy

@lru_cache(maxsize=2*10**5)
def f(p):
    c=copy.deepcopy(b)
    c[x]-=1
    d=c.values()
    e=0
    for y in d:
        e+=y*(y-1)
    return e//2


n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)

for x in a:
    print(f(x))

Fixed submission:
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.Counter(a)
e=0
for x in b.values():
    e+=x*(x-1)
for x in a:
    t=b[x]
    p=e-t*(t-1)+(t-1)*(t-2)
    print(p//2)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
front=True
for _ in range(n):
    q=input()
    if q=="1":front=not front;continue
    l=q.split()
    if l[1]=="1":
        if front:s=l[2]+s
        else:s=s+l[2]
    if l[1]=="2":
        if front:s=s+l[2]
        else:s=l[2]+s

print(s if front else s[::-1])

Fixed submission:
s=input()
n=int(input())
a=[input() for _ in range(n)]

front=True
f=""
b=""

for q in a:
    if q=="1":front=not front;continue
    l=q.split()
    if l[1]=="1":
        if front:f=l[2]+f
        else:b=b+l[2]
    if l[1]=="2":
        if front:b=b+l[2]
        else:f=l[2]+f

print(f+s+b if front else (f+s+b)[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
a=[[i for i in input().split()] for l in range(n)]
c=0
for x in a:
    if x[0]=="1":c+=1
    if x[0]=="2":
        if c%2==1:s=s[::-1]
        c=0
        if x[1]=="1":s=x[2]+s
        else:s=s+x[2]
if c%2==1:s=s[::-1]
print(s)

Fixed submission:
s=input()
n=int(input())
a=[input() for _ in range(n)]

front=True
f=""
b=""

for q in a:
    if q=="1":front=not front;continue
    l=q.split()
    if l[1]=="1":
        if front:f=l[2]+f
        else:b=b+l[2]
    if l[1]=="2":
        if front:b=b+l[2]
        else:f=l[2]+f

print(f+s+b if front else (f+s+b)[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for i in range(n)]
l=list(sorted(set(s)))
li=[]
m=0
for x in l:
    m= max(m,s.count(x))
for x in l:
    if s.count(x)==m:
        li.append(x)
li=list(sorted(li))
for x in li:
    print(x)

Fixed submission:
n=int(input())
s=[input() for i in range(n)]
l=list(set(s))
o=[]
for x in range(len(s)):
    o.append(0)
dic=dict(zip(l,o))

for x in s:
   if x in dic:dic[x]+=1
d=sorted(dic.items(),key=lambda x:-x[1])
m=d[0][1]
p=[]
for r in d:
    if r[1]==m:p.append(r[0])
u=sorted(p)
for y in u:
    print(y)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[sum(a[x:x+k]) for x in range(n-k+1)]
print((max(l)+k)/2)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a[:k])
l=[s]
for x in range(n-k):
    s=s-a[x]+a[x+k]
    l.append(s)
print((max(l)+k)/2)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
c=0
for i in range(n):
    f=True
    for j in range(0,i+1):
        if s[i-j]<s[i]:
            f=False
            break
    if f:
        c=c+1
print(c)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
c=0
m=200001
for i in range(n):
    if m>s[i]:
        c=c+1
    m=min(m,s[i])
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
c=0
for i in range(n):
    f=True
    for j in range(0,i):
        if s[i]>s[j]:
            f=False
            break
    if f:
        c=c+1
print(c)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
c=0
m=200001
for i in range(n):
    if m>s[i]:
        c=c+1
    m=min(m,s[i])
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=list(map(int,input().split()))
c=0
for i in range(n):
    f=True
    for j in range(0,i):
        if s[i]>s[j]:
            f=False
    if f:
        c=c+1
print(c)

Fixed submission:
n=int(input())
s=list(map(int,input().split()))
c=0
m=200001
for i in range(n):
    if m>s[i]:
        c=c+1
    m=min(m,s[i])
print(c)