Problem:


Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]

for i in range(N):
  s[i] = list(set(s[i]))
  
print(len(set(s)))

Submission status: Runtime Error

Solution code:
from collections import Counter


def main():
    n = int(input())
    cnt = Counter()
    ans = 0
    for i in range(n):
        s = sorted(input())

        if cnt[s] == 0:
            cnt[s] = 1
        else:
            ans += cnt[s]
            cnt[s] += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
K,X = map(int,input().split())

l = max(X-K+1,-1000000)
r = min(X+K-1,1000000)

ans = []

for i in range(l,r+1):
    ans.append(str(i))

ans = " ".join(ans)

print(ans)

Submission status: Runtime Error

Solution code:
def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))



from itertools import permutations
from collections import Counter


def factorial(n):
    if n == 0:
        return 1
    return n * factorial(n-1)


def combinations_count(n, r=2):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    k = int(input())
    a = sorted(["".join(sorted(input())) for _ in range(k)])
    d = Counter(a)
    return sum(combinations_count(val) for val in d.values() if val > 1)


print(main())

Submission status: Runtime Error

Solution code:
from sys import stdin
import copy

n = int(input())
S = [stdin.readline()[:-1] for i in [0]*(n-1)]
S.append(stdin.readline())
s = []
for i in S:
    s.append("".join(sorted(i)))
s.sort()
arr = []
temp = 1
for i in range(n-1):
    if temp>1 and s[i]!=s[i+1]:
        arr.append(temp)
        temp = 1
    if s[i]==s[i+1]:
        temp += 1
if temp>1:
    arr.append(temp)
arr.sort()
factorial = [1]
for i in range(arr[-1]+1):
    factorial.append(factorial[i]*(i+1))
comb = [0,0]
for i in range(2,arr[-1]+1):
    comb.append(factorial[i]/(2*factorial[i-2]))
ans = 0
for i in arr:
    ans += comb[i]
print(int(ans))

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for _ in range(n):
    tmp = input()
    tmp.sort()
    s.append(tmp)
cnt = 0
for i in range(n-1):
    for j in range(1,n):
        if s[i]==s[j]:
            cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
from numba import njit
N = int(input())

@njit
def solve(N):
    S = []
    S.append(input())
    cnt = 0
    for _ in range(N-1):
        i = input()
        a = sorted(i)
        for j in S:
            b = sorted(j)
            if a == b:
                cnt += 1
        S.append(i)
    return cnt
    
print(solve(N))

Submission status: Runtime Error

Solution code:
import collections

n=int(input())
lst=[]
ans=0

for i in range(n):
  s=input()
  s.sort()
  lst+=[s]
  
  c=collections.Counter(s)
  
for i in c.values():
  ans+=i*(i-1)//2
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

clist = [None for _ in range(n)]
cnt   = 0

for i in range(n):
    clist[i] = Counter(input())

for i in range(n):
    if i < n:
        for j in range(i+1,n):
            if clist[i] == clist[j]:
                cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
S = [(sorted(input())) for _ in range(N)]
c = collections.Counter(S)
ans = 0
for i in set(S):
    n = c[i]
    ans += n*(n-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
S = [(sorted(input()))for _ in range(N)]
c = collections.Counter(S)
ans = 0
print(S)

for i in set(S):
    n = c[i]
    ans += n*(n-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
S = [{sorted(input())}for _ in range(N)]
c = collections.Counter(S)
ans = 0
print(S)

for i in set(S):
    n = c[i]
    ans += n*(n-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import collections

N = int(input())
S = [sorted(input())for _ in range(N)]
c = collections.Counter(S)
ans = 0

for i in set(S):
    n = c[i]
    ans += n*(n-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A={}
ans=0
for i in range(N):
    s=input()
    s=sorted(s)
    if A.get(s,"Not")=="Not":
        A[s]=1
    else:
        ans+=A[s]
        A[s]+=1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic["".join(sorted(i))] +=1
        print(dic)
    else:
        dic["".join(sorted(i))] = 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic[i] +=1
    else:
        dic["".join(sorted(i))] = 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic.keys():
        ans += dic[i].values()
        dic[i] +=1
    else:
        dic[i] = 1
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(input())
    
dic = dict()
ans = 0
for i in s:
    if "".join(sorted(i)) in dic:
        ans += dic[i]
        dic[i] +=1
    else:
        dic[i] = 1
print(ans)

Submission status: Runtime Error

Solution code:
S=[]
cho=[0]
p=0
n = int(input())
for i in range(n):
    s=sorted(input())
    if s in S:
        cho[p]+=1
        p+=1
    S.append(s)
import collections
from scipy.special import comb
a=0
Sd=list(set(S))
c = collections.Counter(S)
for p in  range(len(Sd)):
    if c[Sd[p]] >=2:
        a  += comb(c[Sd[p]], 2, exact=True)
print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
arr=[]
from collections import Counter
c=Counter([])
for _ in range n:
  s=input()
  z=[item for item in s]
  z.sort()
  z=tuple(z)
  c[z]+=1
ans=0
for item in c.values():
  ans+=(item*(item-1))//2
print (ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()
cnt=0
for i in range(n-1):
    if s[i]==s[i+1]:
    cnt +=1
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]
s.sort()
print(s)
cnt=0
for i in range(n-1):
    if s[i]==s[i+1]
    cnt +=1
print(cnt-n)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted(list(input()))) for _ in range(n)]

cnt=0
for i in range(n):
    if s.count(s[i])!=1
        cnt += s.count(s[i])/s.count(s[i])
print(cnt-n)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
s = ["".join(sorted(input())) for _ in range(N)]
print(A)
B = collections.Counter(s)
print(sum(i*(i-1)//2 for i in B.values()))

Submission status: Runtime Error

Solution code:
counter={}
ans=0
for i in range(n):
	ss = sorted(s[i])
	ss=("").join(ss)
	if ss not in counter:
		counter[ss]=0
	else:
		counter[ss]+=1
		ans+=counter[ss]

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [list(input()) for _ in range(n)]
ans = 0
sd = dict([])

for i in s:
    key = ''.join(sorted(i))
    sd.setdefault(key, 0)
    sd[key] += 1
    
for v in s_dict.values():
    ans += v * (v - 1) // 2
print(ans)

Submission status: Runtime Error

Solution code:
import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
a = [input() for _ in range(N)]

d = dict()
for x in a:
  s = ''.join(sorted(x))
  if s not in d.keys():
    d[s] = 1
  else:
    d[s] += 1

print(sum([comb(i, 2) for i in d.values()]))

Submission status: Runtime Error

Solution code:
n=int(input())
s={}
for i in range(n):
  tmp=list(input().strip()).sort()
  tmp="".join(tmp)
  s[tmp]=s.get(tmp,0)+1
  
ans=0
for key in s.keys():
  v=s[key]
  if v<2:
    continue
  cmb=v*(v-1)
  cmb=cmb//2
  ans+=cmb
print(ans)

Submission status: Runtime Error

Solution code:
import collections
def main4():
    dd = collections.defaultdict(int)
    n = int(input())
    res = 0
    for i in range(n):
        s = input()
        s.sort()
        dd[''.join(s)]+=1
    for i in dd.values():
        res += (i*(i-1))//2
    print(res)

if __name__ == '__main__':
    main4()

Submission status: Runtime Error

Solution code:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
dic_s = {}
for i in range(N):
    s = "".join(sorted(input()))
    if s in dic_s:
        dic_s[s] += 1
    else:
        dic_s[s] = 1
counter = 0
for key,value in dic_s.items():
    counter += combinations_count(value,2)
print(counter)

Submission status: Runtime Error

Solution code:
n = int(input())
d = {'0': 0}

for i in range(n):
    tp = ''.join(sorted(input()))
    if tp in d:
        d[tp] = sum(list(range(d[tp] + 2)))
    else:
        d.update({tp: 0})

print(sum(d.values()))

Submission status: Runtime Error

Solution code:
from collections import Counter

N=int(input())
dic＝{}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]+=1
    else:
        dic[sorted_s]=1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

N=int(input())
dic＝{}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]]+=1
    else:
        dic[sorted_s]=1

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
print(len(set([sorted(i) for i in [input() for i in range(n)]])))

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
n = int(input())
s = [''.join(sorted(list(input()))) for _ in range(n)]

def combination(i):
    return factorial(i) // (factorial(i-2) * factorial(2))

cnt = Counter(s)
print(cnt)
ans = 0
for i in cnt.values():
    print(i)
    ans += combination(i)

print(ans)

Submission status: Runtime Error

Solution code:
# https://atcoder.jp/contests/abc137/tasks/abc137_c

import math

N = int(input())

s_dic = {}
s_set = set()

for i in range(N):
    s = input()

    s = ''.join(sorted(s))

    if s in s_set:
        s_dic[s] += 1

    else:
        s_set.add(s)
        s_dic[s] = 1


result = 0

for val in s_dic.values():

    if val > 1:
        result += int(math.factorial(val) /2)

print(result)

Submission status: Runtime Error

Solution code:
import pandas as pd
import math

N = int(input())
print("No")

Submission status: Runtime Error

Solution code:
import pandas as pd
import math

N = int(input())
S = ["".join(sorted(input())) for i in range(N)]
df = pd.DataFrame(S, columns=["value"])


def combinations_count(n, r):
    if n == 1:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


grouped = df.groupby("value")
sizes = grouped.size().values
ans = sum([combinations_count(size, 2) for size in sizes])
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=[]
cnt=0
for i in range(n):
  s=input()
  s=sorted(s)
  a.append(s)
b=set(a)
for i in b:
  x=a.count(i)
  if x>0:
    cnt+=x*(x-1)//2
print(cnt)

Submission status: Runtime Error

Solution code:
def kaijyou(x):
  a=1
  for i in range(x):
    a*=i
    return a

cnt=0
n=int(input())
x=[input() for i in range(n)]
y=set(x)
for i in y:
  cnt+=kaijyou(x.count(i)-1)
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
s = []
for i in range(N):
  q = sorted(input())
  s.append(q)
s.sort()


ans = 0

for m in range(N):
  i = 0
  while(1):
    if collections.Counter(s[m]) == collections.Counter(s[m+1+i]):
      ans += 1
      i += 1
    else:
      break
    
print(ans)

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
s = []
for i in range(N):
  q = sorted(input())
  s.append(q)
s.sort()


ans = 0

for m in range(N):
  i = 0
  print(m)
  while(1):
    if collections.Counter(s[m]) == collections.Counter(s[m+1+i]):
      ans += 1
      i += 1
    else:
      break
    
print(ans)

Submission status: Runtime Error

Solution code:
def nC2(n):
    x = 1
    for i in range(2, n+1):
        x *= i
    return x//2

def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]
    counter = {}
    for s in S:
        if s in counter:
            counter[s] += 1
        else:
            counter[s] = 1
    ans = sum([nC2(v) for v in counter.values()])
    print(ans)

main()

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N = int(input())
s = sorted([sorted(input()) for _ in range(N)])
total = 0
count = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        total += comb(count, 2)
        count = 1
total += comb(count, 2)
print(int(total))

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
a, b = [], []
for i in range(N):
    b = sorted([x for x in input()])
    a += [int(''.join([str(ord(x)) for x in b]))]
count = Counter(a)
total = 0
for i in count.items():
    if i[1] >= 2:
        total += comb(i[1], 2)
print(int(total))

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial
def combinations(n,r):
    return factorial(n)//(factorial(n-r)*factorial(r))
N=int(input())
S=["".join(sorted(input())) for i in range(N)]
s=Counter(S)
ans=0
for key,value in s.items():
    ans+=combinations(value,2)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

l = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = ''.join(tmp)
    l.append(tmp)

from collections import Counter
c = Counter(l)
num = c.values()

from math import factorial
def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

ans = 0
for i in num:
    ans += combinations_count(i, 2)
    if i == 1:
        break

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    s = [input() for _ in range(n)]
    d = []
    ans = 0
    for ss in s:
        c = collections.Counter(ss)
        d.append(c)
    for i in range(n):
        for j in range(i + 1, n):
            if d[i] == d[j]:
                ans += 1              
    print(ans)  
        
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}
for i in range(n):
  s = sorted(list(input()))
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
dic = {}
for i in range(n):
  s = list(input()).sorted()
  if s not in dic:
    dic[s] = 0
  dic[s] += 1
ans = 0
for i in dic.values():
  ans += i * (i - 1)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy
n = int(input())

s = []
count = 0
for i in range(n):
    tmp = numpy.arry(sorted(list(input())))
    s.append(tmp)
    for j in s:
        if all(j == tmp):
            count += 1

print(count)

Submission status: Runtime Error

Solution code:
n ,res, cc = int(raw_input()),0,collections.Counter()
while(n):
	u =  tuple(sorted(raw_input()))
	res += cc[u]
	n-=1
	cc[u]+=1
print res

Submission status: Runtime Error

Solution code:
n=int(inpput())
list=[input() for i in range(n)]
lists=[]
for i in list:
  lists.append(''.join(sorted(i)))
  
print(len(lists)-len(set(lists)))

Submission status: Runtime Error

Solution code:
import collections
n=int(input())
ans=0
s=["".join(sorted(input())) for _ in range(n)]
c=collections.Counter(s)
for i in set(s):
  a=c[s]
  ans+=a*(a-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
inport collections
n=int(input())
ans=0
s=["".join(sorted(input())) for _ in range(n)]
c=collections.Counter(s)
for i in set(s):
  a=c[s]
  ans+=a*(a-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(intput())
di={}
count=0
for i in range(n):
  s=str(sorted(input()))
  if s in di:
    di[s]+=1
    count+=di[s]
  else:
    di[s]=0
print(count)

Submission status: Runtime Error

Solution code:
n=int(intput())
di={}
count=0
for i in range():
  s=str(sorted(input()))
  if s in di:
    di[s]+=1
    count+=di[s]
  else:
    di[s]=0
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append("".join(sorted(input())))

S=set(s)

import math

def cmb(n,r):
    return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))


ans=0
for x in S:
    a=s.count(x)
    ans+=cmb(a,2)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

dic = {}
for i in range(n):
  s = ''.join(sorted(list(input())))
  if not s in dic:
    dic[s] = 1
  else:
    dic[s] += 1

res = 0
for v in dic.values():
	if v >= 2:
      res += v*(v-1)
print(res//2)

Submission status: Runtime Error

Solution code:
n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1
        
import collections
c = collections.deque(note.values())
ans = 0
for i in range(c):
    q = c.popleft()
    ans += q*(q-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
import math

n=int(input())

dic={}
for i in range(n):
    s=''.join(sorted(input()))
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans=0
for n in dic.values():
    ans += math.factorial(n) // (math.factorial(n-2) * math.factorial(2))

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
for i in range(n):
   b[i]=sorted(s[i])
   a[i]=''.join(b[i])
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==a[j]:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
a=["" for i in range(n)]
for i in range(n):
   b[i]=sorted(s[i])
   a[i]=''.join(b[i])
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==a[j]:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
a=["" for i in range(n)]
for i in range(n):
   b[i]=sorted(s[i])
   a[i]=''.join(b[i])
   print(a)
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]==a[j]:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
a=["" for i in range(n)]
for i in range(n):
   b[i]=sorted(s[i])
   a[i]=''.join(b[i])

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

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
print(s)
for i in range(n):
   r[i]=(sorted([s[i][j] for j in range(10)]))
   r[i]=''.join(r[i])
for i in range(n-1):
    for j in range(i+1,n):
        if r[i]==r[j]:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
s = [input() for i in range(n)]
c=0
for i in range(n):
   r[i]=(((sorted([s[i][j] for j in range(10)]))))
   r[i]=''.join(r[i])
for i in range(n-1):
    for j in range(i+1,n):
        if r[i]==r[j]:
            c+=1
print(c)

Submission status: Runtime Error

Solution code:
n = (int)(input())
s = [sorted(list(input())) for i in range(n)]

#print(*count)

ans = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if count[i] == count[j]:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

duplicate_list = duplicates(s)

for i in range (len(duplicate_list)):
  for j in range (s.count(duplicate_list[i])):
    count += j

print(count)

Submission status: Runtime Error

Solution code:
def sigma(n):
    if n <= 1:
        return n
    else:
        return n + sigma(n-1)


N = int(input())
s = [input() for i in range(N)]

s_sorted = list(map(''.join, list(map(sorted, s))))

s_dict = dict()
for k in s_sorted:
    if k in s_dict:
        s_dict[k] += 1
    else:
        s_dict[k] = 1

cnt = 0
for k in s_dict:
    cnt += sigma(s_dict[k] - 1)

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
slst = [input() for _ in range(n)]
cnt = 0
for j in range(1,n):
    for i in range(j-1):
        lst_1 = list(slst[i])
        lst_2 = list(slst[j])
        count_1 = Counter(lst_1)
        count_2 = Counter(lst_2)
        so1 = sorted(count_1.items())
        so2 = sorted(count_2.items())
        for i ,j in zip(so1,so2):
            if i != j:
                break
        cnt += 1    
            
print(cnt)

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

n = int(input())
a = [list(input()) for i in range(n)]
for i in range(n):
  a[i].sort()
  a[i]="".join(a[i])
b=set(a)
ans = 0
for i in b:
  temp = a.count(i)
  if temp >= 2:
    ans += convination(temp, 2)

print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial

def convination(n, r):
    a = factorial(n) / factorial(r) / factorial(n - r)
    return int(a)

n = int(input())
a = [list(input()) for i in range(n)]
c = []
for i in range(n):
  a[i].sort()
  c.append(str(a[i]))
#print(c)
b=set(c)
#print(b)
ans = 0
for i in b:
  temp = c.count(i)
  if temp >= 2:
    ans += convination(temp, 2)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
li = []
li.append(0)
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[0] == li[1]:
        f += 1
        del li[0]
    else:
        count += (f*(f-1))//2
        f = 1
        del li[0]
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial

# input
N = int(input())
S = {}
for n in range(N):
    s = input()
    counter = Counter(s)
    S[n] = counter

matched = []
count = {}
cnt = 0
m_append = matched.append
for k in S.keys():
    if S[k] in matched:
        continue
    add = list(S.values()).count(S[k])
    if add > 0:
        m_append(S[k])
        cnt += factorial(add) // factorial(2) // factorial(add - 2) 

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial

# input
N = int(input())
S = {}
for n in range(N):
    s = input()
    counter = Counter(s)
    S[n] = counter

matched = []
count = {}
cnt = 0
m_append = matched.append
for k in S.keys():
    if S[k] in matched:
        continue
    add = list(S.values()).count(S[k])
    if add > 0:
        m_append(S[k])
    if add == 2:
        cnt += 1
    else:
        cnt += factorial(add) // factorial(2) // factorial(add - 2)

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter
from math import factorial

# input
N = int(input())
S = {}
for n in range(N):
    s = input()
    counter = Counter(s)
    S[n] = counter

matched = []
count = {}
cnt = 0
m_append = matched.append
for k in S.keys():
    if S[k] in matched:
        continue
    add = list(S.values()).count(S[k])
    if add > 0:
        m_append(S[k])
    cnt += factorial(add) // factorial(2) // factorial(add - 2)

print(cnt)

Submission status: Runtime Error

Solution code:
from collections import Counter

# input
N = int(input())
S = {}
for n in range(N):
    s = input()
    counter = Counter(s)
    S[n] = counter 

matched = []
cnt = 0
m_append = matched.append
for k in S.keys():
    if S[k] in matched:
        continue
    add = len(
        [
            1
            for i, c in S.keys()
            if k != i
            and S[k] == S[i]
        ]
    )
    if add > 0:
        m_append(S[k])
    cnt += add

print(cnt)

Submission status: Runtime Error

Solution code:
#Guide Book https://atcoder.jp/contests/abc128/tasks/abc128_b
N = int(input())
Shop_List=[]
for i in range(N):
    Temp_List=list(input().split())
    Temp_List[1]=int(Temp_List[1])
    Temp_List.append(i+1)
    Shop_List.append(Temp_List)


Shop_List_Sorted = sorted(Shop_List, key=lambda x:(x[0], -x[1]))
for k in range(N):
    print(Shop_List_Sorted[k][2])

Submission status: Runtime Error

Solution code:
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
data = []
for _ in range(n):
    s = input()
    data.append(count(s))
ans = 0
for i in range(n):
    for ii in range(i+1, n):
        if data[i] == data[ii]|:
            ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter,defaultdict
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N = int(input())
A = defaultdict(int)
for _ in range(N):
    c = Counter(list(input()))
    d = sorted(c.items(),key= lambda x:x[0])
    A[tuple(d)] += 1

SUM = 0
for v in A.values():
    SUM += combinations_count(v,2)

print(SUM)

Submission status: Runtime Error

Solution code:
from collections import Counter
n=int(inout())
l=[''.join(sorted(input())) for _ in range(n)]
ans=0
for i in Counter(l).value():
  ans+=i*(i-1)//2
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import collections
n=int(input())
l=[input() for i in range(n)]
ans=0
for k in itertools.combinations:
  c1=collections.Counter(k[0])
  c2=collections.Counter(k[1])
  if c1.most_common()==c2.most_common():
    ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
n = int(input())
S = [str(sorted(input())) for _ in range(N)]

print(sum(map(lambda x: x * (x - 1) // 2, Counter(S).values())))

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=int(comb(v,2))
print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
N=int(input())
dic={}
ans=0
for i in range(N):
    s=list(input())
    s.sort()
    S=''.join(s)
    if S not in dic:
        dic[S]=1
    else:
        dic[S]+=1
for v in dic.values():
    if v>=2:
        ans+=int(comb(v,2))
print(dic)

Submission status: Runtime Error

Solution code:
n = int(input())
cnt = 0
A = []
for _ in range(n):
    A.append(sorted(input())) 
for i in range(n-1):
    for j in range(i+1, n):
        if s == t:
            cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

n = int(input())
d_list = []
cnt_list = collections.defaultdict(lambda:1)
for i in range(n):
    s = str(input())
    
    d = collections.Counter(s)

    if i >= 1:
        if d in list(d_list):
            idx = d_list.index(d)
            cnt_list[idx] += 1
        else:
            d_list.append(d)
    else:
        d_list.append(d)

ans = 0
cnt_list = list(cnt_list.values())
for i in range(len(cnt_list)):
    ans += comb(cnt_list[i], 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())

dic={}
for i in range(n):
    s=''.join(sorted(list(input())))
    dic[s]=dic.get(s,0)+1

ans=0
for key,value in dic.items():
    if value<2:
        continue
    ans+=int(factorial(value) / factorial(2) / factorial(value - 2))
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

dic={}
for i in range(n):
    s=''.join(sorted(list(input())))
    dic[s]=dic.get(s,0)+1

ans=0
for key,value in dic.items():
    if value<2:
        continue
    ans+=int(factorial(value) / factorial(2) / factorial(value - 2))
print(ans)

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())

dic={}
for i in range(n):
    s = ''.join(sorted(set(input())))
    dic[s]=dic.get(s,0)+1

ans=0
for key,value in dic.items():
    if value<2:
        continue
    ans+=int(factorial(value) / factorial(2) / factorial(value - 2))
print(ans)

Submission status: Runtime Error

Solution code:
import collections, math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0

N = int(input())
string_counters = []

cnt = dict()
for i in range(N):
    string = collections.Counter(input())
    if string not in string_counters:
        string_counters.append(string)
        cnt.setdefault(i, 1)
    else :
        cnt[string_counters.index(string)] += 1

output = 0
for k, v in cnt.items():
    if v == 1:
        pass
    else :
        output += combinations_count(v, 2)

print(output)

Submission status: Runtime Error

Solution code:
import collections, math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0

N = int(input())
string_counters = []

cnt = dict()
for i in range(N):
    string = collections.Counter(input())
    if string not in string_counters:
        string_counters.append(string)
        cnt.setdefault(i, 1)
    else :
        cnt[string_counters.index(string)] += 1

output = 0
for k, v in cnt.items():
    output += combinations_count(v, 2)

print(output)