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: Wrong Answer

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

for v in s.values():
    if 1 < v:
        ans += math.factorial(v) // math.factorial(2)
print(ans)

Submission status: Wrong Answer

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

for v in s.values():
    ans += math.factorial(v) // math.factorial(2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import defaultdict
n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
d = defaultdict(int)
for a in s:
  d[a]+=1
c=0
for a in d.values():
  if a>1:
    c+=math.factorial(a)//2
print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
for i in range(N):
    C.append("".join(sorted(input(i))))
B = set(C)
ans = 0
for j in B:
    t = C.count(j)
    if t > 1:
        ans += int(t*(t-1)/2 )
# 1->0, 2->1, 3->3, 4->6, 5->10 :: nC2
    
print(ans)

Submission status: Wrong Answer

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))
print(cnt)

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
C = []
for i in range(N):
    s = set(input())
    c = collections.Counter(s)
    C.append(c)

ans = 0
D = []
for j in range(N):
    a = C.pop(0)
    ans += C.count(a)
print(ans)

Submission status: Wrong Answer

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


ans = 0

for m in range(N):
  for n in range(m+1,N):
    if collections.Counter(s[m]) == collections.Counter(s[n]):
      ans += 1
    else:
      break

print(ans)

Submission status: Wrong Answer

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


ans = 0

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

print(ans)

Submission status: Wrong Answer

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 = [''.join(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: Wrong Answer

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 = [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: Wrong Answer

Solution code:
N=int(input())
arr=[]
arr2=[]
arr3=[]
counter=0
for n in range(N):
    s=input()
    S=sorted(s)
    if arr.count(S)>=1:
        if arr2.count(S)>1:
            counter+=1+arr2.count(S) #組み合わせだからあとで考慮
            targetforarr3index=arr2.index(S)
            arr3[targetforarr3index]+=1
        else:
            counter+=1
            arr2.append(S)
            arr3.append(1)
    else:
        arr.append(S)
print(counter)

Submission status: Wrong Answer

Solution code:
N=int(input())
arr=[]
arr2=[]
arr3=[]
counter=0
for n in range(N):
    s=input()
    S=sorted(s)
    if arr.count(S)>=1:
        if arr2.count(S)>=1:
            counter+=arr2.count(S) #組み合わせだからあとで考慮
            targetforarr3index=arr2.index(S)
            arr3[targetforarr3index]+=1
        else:
            counter+=1
            arr2.append(S)
            arr3.append(1)
    else:
        arr.append(S)
print(counter)

Submission status: Wrong Answer

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:
    if i > 1:
        ans += combinations_count(i, 2)
    else:
        break

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())

#S = [[0 for j in range(3)] for i in range(2)]　2行3列の場合
S = [[0 for j in range(10)] for i in range(N)]

for i in range(N):
    R=input()
    for j in range(10):
        S[i][j]=R[j]
    S[i].sort()
    
    L=[str(a) for a in S[i]]
    L="".join(L)
    S[i]=L

Submission status: Wrong Answer

Solution code:
n = int(input())
dic = {}
for i in range(n):
  s = ''.join(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: Wrong Answer

Solution code:
N = int(input())

S = [""]*N

for i in range(N):
    S[i] = input()
    
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
  
S_set = ["".join(sorted(s)) for s in S]


import collections
import itertools

same_list = collections.Counter(S_set)

ans = [0]*len(same_list)

for i,v in enumerate(same_list.values()):
    if i==0:
        ans[i] = cmb(v, 2)
    else:
        ans[i] = ans[i-1] + cmb(v, 2)

print(ans[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
s=sorted(input())

a=[s]
cnt=0
for _ in range(n-1):
    t=sorted(input())
    for i in range(len(a)):
        if a[i]==t:
            cnt+=1
        else:
            a.append(t)
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[[""]]*n
r=0
for ii in range(n):
  s[ii][:]=list(input())
  s[ii].sort
import numpy as np
for ii in range(n-1):
  for jj in np.arange(ii+1,n):
    if s[ii]==s[jj]:
      #print(s[ii],s[jj])
      r+=1
print(r//2)

Submission status: Wrong Answer

Solution code:
n=int(input())
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: Wrong Answer

Solution code:
n = int(input())
save = [-1]*(n+1)

def aC2(a):
    if(save[a]!=-1):
        return save[a]
    ans = 1
    for i in range(3,a+1):
        ans *= i
    save[a] = ans
    return ans

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

ans = 0
for x in dic.values():
    if(x==0 or x==1):
        continue
    ans += aC2(x)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def aC2(a):
    ans = 1
    for i in range(3,a+1):
        ans *= i
    return ans
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if(dic.get(s) is None):
        dic[s] = 1
    else:
        dic[s] += 1

ans = 0
for x in dic.values():
    if(x==0 or x==1):
        continue
    ans += aC2(x)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

def aC2(a):
    ans = 1
    for i in range(2,a+1):
        ans *= i
    return ans//2
dic = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    if(dic.get(s) is None):
        dic[s] = 1
    else:
        dic[s] += 1
ans = 0
for x in dic.values():
    ans += aC2(x)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
for i in range(N):
  s.append(sorted(list(input())))
s.sort()
ans=0
ren=1
for i in range(1,N):
  if s[i]==s[-1]:
    ren+=1
  else:
    ans+=ren*(ren-1)//2
    ren=1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
for i in range(N):
  s.append(sorted(list(input())))
s.sort
ans=0
ren=1
for i in range(1,N):
  if s[i]==s[-1]:
    ren+=1
  else:
    ans+=ren*(ren-1)//2
    ren=1
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [sorted(str(input())) for _ in range(N)]

B = []
for i in range(N):
    s = ''.join(S[i])
    print(s)
    B.append(s)
#print(B)

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    if set(S[i]) == set(S[j]):
      cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(''.join(sorted(list(input()))))
S.sort()
print('S', S)

count=0
n=1
for i in range(1,N):
    if S[i-1] == S[i]:
        n+=1
    else:
        count+= n*(n-1)*0.5
        n=1
count+=n*(n-1)*0.5
print(int(count))

Submission status: Wrong Answer

Solution code:
def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p
#print(comb(1,2))

N = int(input())
S = []
for i in range(N):
    S.append(sorted(list(input())))

S = sorted(S)
#print(S)

count=0
flag=1
SS = [(''.join(S[0]))]
for i in range(1,N):
    SS.append(''.join(S[i]))
    if SS[-2] == SS[-1]:
        #count+=1
        flag+=1

    #elif flag==1:
        #continue

    else:
        #print('ffsfsf',flag)
        count+=comb(flag,2)
        flag=1

if flag!=1:
    count+=comb(flag,2)
#print(SS)
print(count)

Submission status: Wrong Answer

Solution code:
def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p


N = int(input())
S = []
for i in range(N):
    S.append(sorted(list(input())))

S = sorted(S)
#print(S)

count=0
flag=1
SS = [(''.join(S[0]))]
for i in range(1,N):
    SS.append(''.join(S[i]))
    if SS[-2] == SS[-1]:
        #count+=1
        flag+=1

    #elif flag==1:
        #continue

    else:
        #print('ffsfsf',flag)
        count+=comb(flag,2)
        flag=1

if flag!=1:
    count+=comb(flag,2)
#print(SS)
print(count)

Submission status: Wrong Answer

Solution code:
def comb(n,m,p=10**9+7):
    if n < m : return 0
    if n < 0 or m < 0:return 0
    m = min(m, n-m)
    top = bot = 1
    for i in range(m):
        top = top*(n-i) % p
        bot = bot*(i+1) % p
    bot = pow(bot, p-2, p)
    return top*bot % p


N = int(input())
S = []
for i in range(N):
    S.append(sorted(list(input())))

S = sorted(S)
#print(S)

count=0
flag=1
SS = [(''.join(S[0]))]
for i in range(1,N):
    SS.append(''.join(S[i]))
    if SS[-2] == SS[-1]:
        #count+=1
        flag+=1

    elif flag==1:
        continue

    else:
        #print('ffsfsf',flag)
        count+=comb(flag,2)
        flag=1

if flag!=1:
    count+=comb(flag,2)
#print(SS)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = ["".join(sorted(input())) for i in range(N)]
print(s)
D = dict()
for st in s:
    if st in D:
        D[st] += 1
    else:
        D[st] = 1
ans = 0
for i in D:
    k = D[i]
    ans += (k*(k-1))//2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

res = 0
for v in dic.values():
  res += v
print(res)

Submission status: Wrong Answer

Solution code:
import collections

lst = []
cnt = 0
n = int(input())
for i in range(n):
  s = input()
  c = collections.Counter(s)
  if c in lst:
    cnt += 1
  else:
    lst.append(c)
print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
s = list(str(dict(Counter(sorted(input())))) for i in range(N))

def comb(n,k):
    nCk = 1
    MOD = 10**9+7

    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= MOD

    for i in range(1,k+1):
        nCk *= pow(i,MOD-2,MOD)
        nCk %= MOD
    return nCk
  
ans = 0
for i in Counter(s).keys():
    ans += comb(Counter(s)[i], 2) 
print(ans)

Submission status: Wrong Answer

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():
    if n>2:
        ans += math.factorial(n) // (math.factorial(n-2) * math.factorial(2))

print(ans)

Submission status: Wrong Answer

Solution code:
n = (int)(input())
s = [input() for i in range(n)]
count = [[0 for i in range(26)] for j in range(n)]
for i in range(n):
  for j in range(10):
    count[i][ord(s[i][j]) - 97] += 1
print(*count)

Submission status: Wrong Answer

Solution code:
n=int(input())
s = [input() for i in range(n)]
r=[]
c=0
a=0
for i in range(n):
   r.append((sorted([s[i][j] for j in range(10)])))

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

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = [str(sorted(input())) for _ in range(N)]

C = Counter(S)
ans = 0
for v in C.values():
    # ans += v * (v - 1) // 2
    if v > 1:
        if v == 2:
            ans += 1
        else:
            ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
S = [str(sorted(input())) for _ in range(N)]

C = Counter(S)
ans = 0
for v in C.values():
    if v > 1:
        if v == 2:
            ans += 1
        else:
            ans += v
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
count=0
for i in range(N):
  a = list(input())
  a.sort()
  s.append(a)

while True:
  if len(s) == 0:
    break
  count += s.count(s[0])
  s=[i for i in s if i != s[0]]
  
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
Y = {}
c = 0
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  u = t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+t[7]+t[8]+t[9]
  if u not in Y:
    Y[u] = 1
  else :
    Y[u] += Y[u]

for v in Y.values():
  c += v-1 
print(c)

Submission status: Wrong Answer

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

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

cnt = 0
while(s_sorted):
    n = s_sorted.count(s_sorted[0])
    cnt = sum(range(n))
    for i in range(n):
        k = s_sorted.pop(0)

print(cnt)

Submission status: Wrong Answer

Solution code:

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

d = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

_ans = 0
for k, v in d.items():
    if v == 0: continue
    _ans += math.factorial(v + 1) // 2

print(_ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

d = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0

_ans = 0
for k, v in d.items():
    if v == 0:
        continue
    elif v == 1:
        _ans += 1
    else:
        _ans += v + 1

print(_ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
    s = ''.format(sorted(input()))
    l.append(s)
    print(s)
ans = 0
for j in range(n-1):
    if l[j] == l[j+1]:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
dict={}
count=0
for i in range(0,n):
  temp=str(input())
  temp=sorted(list(temp))
  temp="".join(temp)
  if temp in dict:
    dict[temp]=dict[temp]+1
    count=count+dict[temp]
  else:
    dict[temp]=1
print(count)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
li = []
count = 1
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    li2 = []
    if li[0] == li[1]:
        f += 1
        del li[0]
    else:
        for i in range(f):
            li2.append(i+1)
        count += len(list(itertools.combinations(li2, 2)))
        f = 1
        del li[0]
print(count)

Submission status: Wrong Answer

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 in S.keys()
            if k != i
            and S[k] == S[i]
        ]
    )
    if add > 0:
        m_append(S[k])
    cnt += add

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# input
N = int(input())
S = []
s_append = S.append
for n in range(N):
    s = input()
    counter = Counter(s)
    s_append(counter)

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

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter

# input
N = int(input())
S = []
s_append = S.append
for n in range(N):
    s = input()
    counter = Counter(s)
    s_append(counter)

matched = []
cnt = 0
m_append = matched.append
for i, s in enumerate(S):
    if s in matched:
        continue
    for c in S[i + 1:]:
        if s == c:
            cnt += 1
            m_append(s)

print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = list(list(input()) for i in range(n))
count = 0

for i in range(n):
  for j in range(i + 1, n):
    test = s[i]
    for k in s[j]:
      if(k in test):
        test.remove(k)
    if(len(test) == 0):
      count += 1

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = sorted(input())
    # a.sort()
    sa = ''.join(a)
    # print(sa)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

ans = []

print(index)

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for r in range(2):
            # c = r
            d *= (s[i] - r)
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    # print(sa)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

Submission status: Wrong Answer

Solution code:
## from collections import Counter
from collections import Counter

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

for i in range(N):
    Temp_Word=''.join(sorted(input()))
    Word_List.append(Temp_Word)

Word_Count=Counter(Word_List)
Word_PairCount_List = [i for i in Word_Count.values() if i > 1]
print(len(Word_PairCount_List))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    # print(sa)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

ans = []

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for r in range(1,s[i]+1):
            c = r
            d *= c
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Wrong Answer

Solution code:
out = {}
N = int(input().strip())
for _ in range(N):
  s = input().strip()
  d = ''.join(sorted(s))
  if d in out:
    out[d] += out[d]+1
  else:
    out[d] = 0
print(sum(out.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

ans = []

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for i in range(1,s[i]+1):
            c = i
            d *= c
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)
        
    
    # s.append(sa)
    
    print(sa)
    
print(s)
    
# st = list(set(s))

ans = []




for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for i in range(1,s[i]+1):
            c = i
            d *= c
            
        d //= 2
        
        # print(d)
        
        ans.append(d)
    
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(0)
        
    
    # s.append(sa)
    
    # print(sa)
    
print(sum(s))

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    s.append(sa)
    
st = list(set(s))

ans = []




for i in range(len(st)):
    b = s.count(st[i])
    
    # print(b)
    
    
    
    if b >= 2:
        d = 1
        for i in range(1,b+1):
            c = i
            d *= c
            
        d //= 2
        
        # print(d)
        
        ans.append(d)
    
print(sum(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
li = []
lic = []
count = 0
a = 0
for i in range(n):
    lic.append(i+1)
    lia = list(input())
    lia.sort()
    li.append(lia)
li.sort()
for i in range(n-1):
    if li[0] == li[1]:
        count += 1
        a = 1
    else:
        del li[0]
        if a == 1:
            count += 1
            a = 0
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
for i in range(n):
  s = list(input())
  s = sorted(s)
  lst.append(s)
lst = sorted(lst)
sum_ = 0

for i in range(1, n):
  count = 1
  if lst[i] == lst[i-1]:
    count += 1
  else:
    sum_ += count * (count-1)//2
    count = 1
print(sum_)

Submission status: Wrong Answer

Solution code:
n = int(input())
Dict = {}
ans = 0
for i in range(n):
    tmp = list(input())
    tmp = tmp.sort()
    tmp = str(tmp)

    if tmp not in Dict:
        Dict[tmp] = 1
    else:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter


n=int(input())
S = []
for i in range(n):
    S.append(''.join(sorted(input())))

cnt = Counter(S)
 
ans = 0
for num in cnt.values():
    ans += num*(num-1)/2
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]

print(Counter(s).values())
ans = 0
for i in Counter(s).values():
    ans += i * (i-1) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
sd = {}
cnt = 0
for i in range(N):
    str = ','.join(sorted(input()))
    if str in sd:
        sd[str] += sd[str]
    else:
        sd[str] = 1

print(sum(sd.values())-len(sd))

Submission status: Wrong Answer

Solution code:
N = int(input())
sd = {}
cnt = 0
for i in range(N):
    str = sorted(input())
    str = ','.join(str)
    if str in sd:
        sd[str] += 1
    else:
        sd[str] = 0
print(sum(sd.values()))

Submission status: Wrong Answer

Solution code:
N=int(input())
dic={}
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
print((max(dic.values())-1)**2)

Submission status: Wrong Answer

Solution code:

import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

n=int(input())
s_lis=["".join(sorted(readline().rstrip().decode())) for _ in range(n)]

from collections import Counter
counter = Counter(s_lis) # 同一文字列の出現回数リスト取得
 
answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Submission status: Wrong Answer

Solution code:

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import Counter

N = int(input())
S = [''.join(map(str,(sorted(str(input()))))) for i in range(N)]
print(S)
counter = Counter(S)
print(counter)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=set()
b=[]
import collections
import math
for i in range(n):
    s=input()
    s=sorted(s)
    a.add("".join(s))
    b.append("".join(s))
ans=0
a=list(a)
c=collections.Counter(b)
for i in range(len(a)):
    ans+=math.factorial(c[a[i]])
print(ans-len(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
d=dict()
for _ in range(n):
    s=''.join(sorted(input()))
    if s in d:
        d[s]+=d[s]
    else:
        d[s]=1
print(sum(d.values())-len(d))

Submission status: Wrong Answer

Solution code:
import sys
import collections

n = int(input())
uq = []
for x in sys.stdin.readlines():
    tmp = collections.Counter(x.rstrip())
    if tmp not in uq:
        uq.append(tmp)

print(n - len(uq))

Submission status: Wrong Answer

Solution code:
N=int(input())
S={}
cnt=0
for i in range(N):
    Z=sorted(list(input()))
    K="".join(Z)
    if K in S:
        S[K]+=1
    else:
        S[K]=1
for T in S.values():
    mul=1
    v=1
    if T>1:
        for t in range(T,1,-1):
            mul*=t
        cnt+=mul
    else:
        continue
print(int(cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())

a = [input() for i in range(n)]

for i in range(n):
    a[i] = ''.join(sorted(a[i]))

a = sorted(a)

ans = 0
sum = 1
for i in range(n-1):
    if a[i] == a[i+1]:
        sum += 1
    else :
        ans += (sum*(sum-1))/2
        sum = 1

ans += (sum*(sum-1))/2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
s = sorted(S)
s.append(["X"])
sum = 0
print(s)
num = 1
for i in range(N):
  if s[i] == s[i+1]:
    num += 1
  else:
    sum += num*(num-1)//2
    num = 1
print(sum)

Submission status: Wrong Answer

Solution code:
import collections
from math import factorial

def combinations_count(n, r): #組み合わせ
    return factorial(n) // (factorial(n - r) * factorial(r))

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

for i in range(n):
    s = list(input())
    s.sort()
    li.append(''.join(s))

c = list(collections.Counter(li).values())

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

print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import math

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

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

for i in range(n):
    s = list(input())
    s.sort()
    li.append(''.join(s))

c = list(collections.Counter(li).values())

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter as counter

ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,s):
    res = 0
    for i in counter(s).values():
        if i <= 1 : break
        res += int(i*(i-1)/2)
    print(res)

n = ii()
s = list("".join(sorted(input())) for _ in range(n))
main(n,s)

Submission status: Wrong Answer

Solution code:
import math
from collections import Counter as counter
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(li() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,s):
    res = 0
    for i in counter(s).values():
        if i <= 1 : break
        res += i*(i-1)/2
    print(res)

n = ii()
s = list("".join(sorted(input())) for _ in range(n))
main(n,s)