Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
import numpy as np
def getNearestValue(list, num):
	idx = np.abs(np.asarray(list) - num).argmin()
	return list[idx]

N=int(input())
A=list(map(int,input().split()))
A.sort()
n=A.pop()
r=getNearestValue(A,n/2)



print(n,r)


Fixed submission:
import sys
input = sys.stdin.readline
import numpy as np
def getNearestValue(list, num):
	idx = np.abs(np.asarray(list) - num).argmin()
	return list[idx]

N=int(input())
A=list(map(int,input().split()))
A.sort()
n=A.pop()
r=getNearestValue(A,n/2)



print(n,r)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=input().strip()
a=[]
for i in range(3):
    a.append(s[i])
a.sort()
if a[0]=="a" and a[1]=="b" and a[2]="c":
    print("Yes")
else:
    print("No")


Fixed submission:
import sys
input = sys.stdin.readline
s=input().strip()
a=[]
for i in range(3):
    a.append(s[i])
a.sort()
if a[0]=="a" and a[1]=="b" and a[2]=="c":
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a=int(input()
b=int(input()
c=int(input()
d=int(input()
print(min(a,b)+min(c,d))


Fixed submission:
import sys
input = sys.stdin.readline
a=int(input())
b=int(input())
c=int(input())
d=int(input())
print(min(a,b)+min(c,d))
Buggy python submission (verdict: Runtime Error):
n=input()
cnt=0
for i in range(3):
    if n[i]=n[i+1]:
        cnt+=1
if cnt>=3:
    print("Yes")
else:
    print("No")


Fixed submission:
n=input()
if n[0]==n[1]==n[2] or n[1]==n[2]==n[3]:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
s=input()
lis=["q","w","e","r","t","y","u","i","o","p","l","k","j","h","g","f","d","s","a","z","x","c","v","b","n","m"]
a=set()
for i in range(len(s)):
    a.add(s[i])
#print(a)
ans=[]
for i in range(len(lis)):
    if lis[i] in a:
        continue
    ans.append(lis[i])
ans.sort()
print(ans[0])


Fixed submission:
s=input()
lis=["q","w","e","r","t","y","u","i","o","p","l","k","j","h","g","f","d","s","a","z","x","c","v","b","n","m"]
a=set()
for i in range(len(s)):
    a.add(s[i])
#print(a)
ans=[]
for i in range(len(lis)):
    if lis[i] in a:
        continue
    ans.append(lis[i])
ans.sort()
if ans:
    print(ans[0])
else:
    print("None")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline().strip
a,b,c,d=map(int,input().split())
if b<c or d<a:
    print(0)
elif print(max(b,d)-min(a,c))


Fixed submission:
import sys
input = sys.stdin.readline().strip
a,b,c,d=map(int,input().split())
if b<c or d<a:
    print(0)
else: print(min(b,d)-max(a,c))
Buggy python submission (verdict: Runtime Error):
"""import sys
input = sys.stdin.readline().strip"""
n=int(input())
T=[int(input()) for _ in range(n)]
if n==1:
    print(T[0])
from fractions import gcd
ans=T[0]*T[1]//gcd(T[0],T[1])
for t in T:
    ans=ans*t//gcd(ans,t)
print(ans)


Fixed submission:
"""import sys
input = sys.stdin.readline().strip"""
n=int(input())
T=[int(input()) for _ in range(n)]
if n==1:
    print(T[0])
    exit()
from fractions import gcd
ans=T[0]*T[1]//gcd(T[0],T[1])
for t in T:
    ans=ans*t//gcd(ans,t)
print(ans)

Buggy python submission (verdict: Runtime Error):
"""import sys
input = sys.stdin.readline().strip"""
n=int(input())
T=[int(input()) for _ in range(n)]
from fractions import gcd
ans=T[0]*T[1]//gcd(T[0],T[1])
for t in T:
    ans=ans*t//gcd(ans,t)
print(ans)


Fixed submission:
"""import sys
input = sys.stdin.readline().strip"""
n=int(input())
T=[int(input()) for _ in range(n)]
if n==1:
    print(T[0])
    exit()
from fractions import gcd
ans=T[0]*T[1]//gcd(T[0],T[1])
for t in T:
    ans=ans*t//gcd(ans,t)
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in range(n):
    if a[i]%4==0:
        cnt4+=1
    elif a[i]%2==0:
        cnt2+=1
if cnt2>1:
    ans=len(a)-cnt4*3-cnt2
if cnt2==1:
    ans=len(a)-cnt4*3
print("Yes" if ans<=0 else "No")


Fixed submission:
"""import sys
input = sys.stdin.readline"""
n=int(input())
a=list(map(int,input().split()))
cnt2=0
cnt4=0
for i in a:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
if cnt2>1:
    ans=n-cnt4*2-cnt2
if cnt2<=1:
    ans=n-cnt4*2-1
print("Yes" if ans<=0 else "No")
Buggy python submission (verdict: Runtime Error):
"""import sys
input = sys.stdin.readline"""
n=int(input())
if n==32:
    print(32)
    exit()
cntm=0
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)


Fixed submission:

n=int(input())
cntm=0
ans=1
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)

Buggy python submission (verdict: Runtime Error):
"""import sys
input = sys.stdin.readline"""
n=int(input())
cntm=0
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)


Fixed submission:

n=int(input())
cntm=0
ans=1
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
cntm=0
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)


Fixed submission:

n=int(input())
cntm=0
ans=1
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
cntm=0
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)


Fixed submission:

n=int(input())
cntm=0
ans=1
for i in range(1,n+1):
    a=i
    cnt=0
    while a%2==0:
        a//=2
        cnt+=1
    if cntm<cnt:
        ans=i
        cntm=cnt
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a,b,c=map(int,input().split()))
for i in range(b):
    if a*i%b==c:
        print("YES")
        exit()
print("NO")


Fixed submission:
import sys
input = sys.stdin.readline
a,b,c=map(int,input().split())
for i in range(b+1):
    if a*i%b==c:
        print("YES")
        exit()
print("NO")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))

v=[]
for s in (1,-1):
    x=a[::]
    hugou=[s*(-1)**i sor i in range(n)]
    total=0
    for i in range(n):
        if (total+x[i])*hugou[i]<=0:
            x[i]=hugou[i]-total
        total+=xs[i]
    v.append(sum(absa[i]-x[i])for i in range(n))
print(min(v))


Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))

v=[]
for s in (1,-1):
    x=a[::]
    hugou=[s*(-1)**i for i in range(n)]
    total=0
    for i in range(n):
        if (total+x[i])*hugou[i]<=0:
            x[i]=hugou[i]-total
        total+=x[i]
    v.append(sum(abs(a[i]-x[i]) for i in range(n)))
print(min(v))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a,b=map(int,input().split())
if a=="H":
    print(b)
else:
    if b=="H":
        print("D")
    else:
        print("H")


Fixed submission:
import sys
input = sys.stdin.readline
a,b=input().split()
if a=="H":
    print(b)
else:
    if b=="H":
        print("D")
    else:
        print("H")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if a[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)


Fixed submission:
import sys
input = sys.stdin.readline
n=int(input())
s=input()
def solve():
    for i in range(1,n):
        if (ans[i]=="S" and s[i]=="o") or (ans[i]=="W" and s[i]=="x"):
            ans[i+1]=ans[i-1]
        else:
            if ans[i-1]=="S":
                ans[i+1]="W"
            else:
                ans[i+1]="S"

        if (ans[0]=="S" and s[0]=="o") or (ans[0]=="W" and s[0]=="x"):
            sl=ans[1]
        else:
            if ans[1]=="S":
                sl="W"
            else:
                sl="S"
    if ans[0]==ans[-1] and sl==ans[n-1]:
        return True
    else:
        return False

ans=[0]*(n+1)

for i in ["S","W"]:
    for j in ["S","W"]:
        ans[0]=i
        ans[1]=j
        if solve():
            print("".join(ans[:-1]))
            exit()
print(-1)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,ma,mb=map(int,input().split())
dp=[[[float("inf")]*500 for _ in range(500)] for i in range(n+1)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(450):
        dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
        for k in range(450):
            dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)
ans=float("inf")
i=1
#print(dp[-1])
while i*ma<450 and i*mb<450:
    ans=min(ans,dp[-1][ma*i][mb*i])
    i+=1
print(ans if ans!=float("inf") else -1)


Fixed submission:
import sys
input = sys.stdin.readline
n,ma,mb=map(int,input().split())
dp=[[[float("inf")]*500 for _ in range(500)] for i in range(n+1)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=map(int,input().split())
    for j in range(450):
        for k in range(450):
            dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k])
            dp[i+1][j+a][k+b]=min(dp[i+1][j+a][k+b],dp[i][j][k]+c)
ans=float("inf")
i=1
#print(dp[-1])
while i*ma<450 and i*mb<450:
    ans=min(ans,dp[-1][ma*i][mb*i])
    i+=1
print(ans if ans!=float("inf") else -1)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
s=input().strip()
for i in range(len(s)):
    if s[i]=="A":
        sa=i
for i in range(len(s)):
    if s[i]=="Z":
        sz=i
print(len(s[si:sz+1]))


Fixed submission:
import sys
input = sys.stdin.readline
s=input().strip()
for i in range(len(s)):
    if s[i]=="A":
        sa=i
        break
for i in range(len(s)):
    if s[i]=="Z":
        sz=i
print(len(s[sa:sz+1]))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a,o,b=map(input().split())
a=int(a)
b=int(b)
print(a+b if o=="+" else a-b)


Fixed submission:
import sys
input = sys.stdin.readline
a,o,b=input().split()
a=int(a)
b=int(b)
print(a+b if o=="+" else a-b)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a,o,b=map(int,input().split())
print(a+b if o=="+" else a-b)


Fixed submission:
import sys
input = sys.stdin.readline
a,o,b=input().split()
a=int(a)
b=int(b)
print(a+b if o=="+" else a-b)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x



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

n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
    p,q=map(int,input().split())
    uf1.union(p-1,q-1)
uf2=UnionFind(n)
for _ in range(l):
    p,q=map(int,input().split())
    uf2.union(p-1,q-1)
ans=[]
for i in range(n):
    a=set(uf1.members(i))
    b=set(uf2.members(i))
    c=a&b
    print(len(c))


Fixed submission:
import sys
input = sys.stdin.readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

n,k,l=map(int,input().split())
uf1=UnionFind(n)
for _ in range(k):
    p,q=map(int,input().split())
    uf1.union(p-1,q-1)
uf2=UnionFind(n)
for _ in range(l):
    p,q=map(int,input().split())
    uf2.union(p-1,q-1)
from collections import defaultdict
p=defaultdict(int)
for i in range(n):
    a=uf1.find(i)
    b=uf2.find(i)
    p[(a,b)]+=1
ans=[]
for i in range(n):
    ans.append(p[uf1.find(i),uf2.find(i)])
print(*ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
w=input().strip()
from collections import Counter
s~Counter(w)
for a in s.values():
    if a%2==1:
        print("No")
        exit()
print("Yes")


Fixed submission:
import sys
input = sys.stdin.readline
w=input().strip()
from collections import Counter
s=Counter(w)
for a in s.values():
    if a%2==1:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

gift_list = []
for _ in range(N):
  S = input()
  if not S in gift_list:
    gift_list.append(S)

print(len(gift_list))


Fixed submission:
N = int(input())

S = set([input() for _ in range(N)])

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

while True:
  if K == 1:
    answer = 0
    break
  if N <= abs(N - K):
    answer = N
    break
  else:
    N = abs(N - K)

print(answer)
    

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

if N % K == 0:
  answer = 0
else:
  if abs(N % K - K) >= N % K:
    answer = N % K
  else:
    answer = abs(N % K - K)

  
print(answer)
Buggy python submission (verdict: Runtime Error):
d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)

Fixed submission:
from collections import Counter

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)

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

N = int(input())

s = [input() for _ in range(N)]
s_dict = Counter(s)

max_keys = [k for k, v in s_dict.items() if v == max(s_dict.values())]
max_keys.sort()
for k in max_keys:
  print(k)

Fixed submission:
from collections import Counter

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)

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

N = int(input())

s_dict = {}
for _ in range(N):
  s = input()
  if s in s_dict:
    s_dict[s] += 1
  else:
    s_dict[s] = 1

max_keys = [k for k, v in s_dict.items() if v == max(s_dict.values())]
max_keys.sort()
for k in max_keys:
  print(k)

Fixed submission:
from collections import Counter

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)

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

N = int(input())

s_list = []
for _ in range(N):
  s = input()
  s_list.append(s)

s_dict = Counter(s_list)

max_keys = [k for k, v in s_dict.items() if v == max(s_dict.values())]
max_keys.sort()
for k in max_keys:
  print(k)

Fixed submission:
from collections import Counter

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sum=0
for i in range(1,n+1,1):
    sum+=int(i*int(n/i)*int(n/i+1)/2)

print(sum)



Fixed submission:
n = int(input())
sum=0
for i in range(1,n+1,1):
    t=int(n/i)
    sum+=i*t*(t+1)/2

print(int(sum))

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

n = int(input())

a=[]
prime=[]

for i in range(n+1):
    a.append(1)
    prime.append(0)

m=0
for i in range(2,n+1,1):
    if a[i]==1:
        m=m+1
        prime[m]=i
        for j in range(i,n+1,i):
            a[j]=0


yaku=[]
for i in range(n+1):
    yaku.append(0)

yaku[1]=1

for i in range(m,0,-1):
    p=prime[i]
    for j in range(int(n/p),0,-1):
        if yaku[j]>0:
            for k in range(1,1+int(math.log(n/j,p)),1):
                yaku[j*int(math.pow(p,k))]=yaku[j]*(k+1)


#print(yaku)

sum=0;
for i in range(1,n+1,1):
    sum+=i*yaku[i]

print(sum)



Fixed submission:
n = int(input())
sum=0
for i in range(1,n+1,1):
    t=int(n/i)
    sum+=i*t*(t+1)/2

print(int(sum))
Buggy python submission (verdict: Time Limit Exceeded):

if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    l = sorted(l, reverse=True)

    answer = 0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if l[i] < l[j] + l[k]:
                    answer += 1
                else :
                    break

    print(answer)


Fixed submission:
import bisect

if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    l = sorted(l)

    answer = 0
    for i in range(0,n):
        for j in range(i+1,n):
            k = bisect.bisect_left(l, l[i]+l[j])
            answer += max(0,k-(j+1))

    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    answer = 0
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                if abs(l[j]-l[k]) < l[i] and l[i] < l[j] + l[k]:
                    answer += 1

    print(answer)


Fixed submission:
import bisect

if __name__ == '__main__':
    n = int(input())
    l = list(map(int,input().split()))

    l = sorted(l)

    answer = 0
    for i in range(0,n):
        for j in range(i+1,n):
            k = bisect.bisect_left(l, l[i]+l[j])
            answer += max(0,k-(j+1))

    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n,m = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list = sorted(a_list, reverse=True)

    search_range = 1
    while m > 0:
        max_index = a_list[0:search_range].index(max(a_list[0:search_range]))
        a_list[max_index] = a_list[max_index] // 2
        m -= 1
        search_range += 1

    answer = sum(a_list)
    print(answer)


Fixed submission:
import heapq


if __name__ == '__main__':
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    q = []
    for x in a:
        heapq.heappush(q, -x)

    for i in range(m):
        x = heapq.heappop(q)
        x /= 2
        heapq.heappush(q,x)

    answer = 0
    for x in q:
        answer += int(-x//1)
    print(answer)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n,m = map(int, input().split())
    a_list = list(map(int, input().split()))
    a_list = sorted(a_list, reverse=True)

    while m > 0:
        max_index = a_list.index(max(a_list))
        a_list[max_index] = a_list[max_index] // 2
        m-=1

    answer = sum(a_list)
    print(answer)



Fixed submission:
import heapq


if __name__ == '__main__':
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    q = []
    for x in a:
        heapq.heappush(q, -x)

    for i in range(m):
        x = heapq.heappop(q)
        x /= 2
        heapq.heappush(q,x)

    answer = 0
    for x in q:
        answer += int(-x//1)
    print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    s = ["".join(sorted(list(input()))) for i in range(n)]

    answer = 0
    for i in range(n):
        for j in range(i+1,n):
            if s[i] == s[j]:
                answer += 1
    print(answer)


Fixed submission:
import collections


if __name__ == '__main__':
    n = int(input())
    s = ["".join(sorted(list(input()))) for i in range(n)]

    c = collections.Counter(s)

    answer = 0
    for cnt in c.values():
        answer += cnt*(cnt-1)//2
    print(answer)

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


if __name__ == '__main__':
    n = int(input())
    s = [str(input()) for i in range(n)]

    c = []


    for i in range(n):
        c.append(collections.Counter(s[i]))

    answer = 0
    for i in range(n):
        for j in range(i+1,n):
            if c[i] == c[j]:
                answer += 1
    print(answer)



Fixed submission:
import collections


if __name__ == '__main__':
    n = int(input())
    s = ["".join(sorted(list(input()))) for i in range(n)]

    c = collections.Counter(s)

    answer = 0
    for cnt in c.values():
        answer += cnt*(cnt-1)//2
    print(answer)