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:
s = input().split()
n=int(s[0])
d={}
count=0
for i in range(n):
    s = input().split()
    l=sorted(s[0])
    l=''.join(l)
    p = d.setdefault(l,i)
    if p<i:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [str(sorted(input())) for _ in range(n)]
se = set(s)
print(len(s)-len(se))

Submission status: Wrong Answer

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

ans = 0
d = {}
for i in s:
    a = [c for c in i]
    a.sort()
    print(a)
    a = "".join(a)
    if a in d:
        ans+= d[a]
        d[a] +=1
    else:
        d[a] = 1
print(ans)

Submission status: Wrong Answer

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

ans = 0
d = {}
for i in s:
    a = [c for c in i]
    a.sort()
    print(a)
    a = "".join(a)
    if a in d:
        print(d[a])
        ans+= d[a]
        d[a] +=1
    else:
        d[a] = 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = [sorted(list(input())) for i in range(n)]
         
li2 = []
for i in range(len(li)):
    li2.append(li.count(li[i]))
         
li3 = list(set(li2))
#print(li3)
num = 0   

if len(li3)<=1:
    print(0)
for i in range(len(li3)):
    if li3[i] >= 2:
        num += li3[i]*(li3[i]-1)//2        
         
print(num)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s = list(input())
        s.sort()
        s_l.append(''.join(s))

# for i in range(n):
#         s_l.append(''.join(sorted(s_i_l[i])))
#         # for x in sorted(s_l[i]):
#         #         a += x
#         # s_l[i] = a
cnt = 0

set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        l = []
        for val in set_s_l:
                l.append(s_l.count(val))
        for i in l:
                if i > 1:
                        if i == 2:
                                cnt += 1
                        elif i == 3:
                                cnt +=i
                        else:
                                cnt += (i*(i-1))/2
        print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
# k,x = map(int,input().split())
s_i_l = []
for i in range(n):
        s_i_l.append(input())
s_l = []
for i in range(n):
        s_l.append(''.join(sorted(s_i_l[i])))
        # for x in sorted(s_l[i]):
        #         a += x
        # s_l[i] = a
cnt = 0

set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        l = []
        for val in set_s_l:
                l.append(s_l.count(val))
        for i in l:
                if i > 1:
                        if i == 2:
                                cnt += 1
                        elif i == 3:
                                cnt +=i
                        else:
                                cnt += (i*(i-1))/2
        print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

cnt = 0

set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        l = []
        for val in set_s_l:
                l.append(s_l.count(val))
        for i in l:
                if i > 1:
                        if i == 2:
                                cnt += 1
                        elif i == 3:
                                cnt +=i
                        else:
                                cnt += (i*(i-1))/2
        print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = ['']*N

for i in range(N):
  str = input()
  s[i] = ''.join(sorted(str))

s.sort()
ans = 0
for i in range(N):
  current = s[i] 
  samenum = 1
  if(i == N-1):
    break
    
  while(s[i+1] == current):
    samenum += 1
    i += 1
    if(i == N-1):
      break
      
  ans += (samenum * (samenum-1)//2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = ['']*N

for i in range(N):
  str = input()
  s[i] = ''.join(sorted(str))

s.sort()
ans = 0
for i in range(N):
  current = s[i]
  if(i == N-1):
    break
  
  samenum = 0
  while(s[i] == current):
    if(i == N-1):
      break
    samenum += 1
    i += 1
  ans += (samenum * (samenum-1)//2)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = ['']*N

for i in range(N):
  str = input()
  s[i] = ''.join(sorted(str))

s.sort()
ans = 0
for i in range(N):
  current = s[i]
  if(i == N-1):
    break
  if(s[i+1] == current):
    ans += 1
    i += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
d = defaultdict(lambda: 0)

for _s in s:
    d[_s] += 1

print(sum(map(lambda x: x * (x+1) / 2, d.values())))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
d = defaultdict(lambda: 0)

for _s in s:
    d[_s] += 1

print(sum(d.values()))

Submission status: Wrong Answer

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

dct = {}

for i in range(n):
    item = s[i]
    if item in dct:
        dct[item] += 1
        if item in dct and dct[item] >= 2:
            num = dct[item] - 1
            dct[item] += num
    else:
        dct.setdefault(item, 0)

print(sum(dct.values()))

Submission status: Wrong Answer

Solution code:
N=int(input())
b=[]
x=0
t=1
for i in range(N):

    a=list(input())

    a.sort(reverse=False)

    b.append(a)


while True:

    if len(b)==1:
        break

    q=b[0]

    if q==b[t]:

        x+=1

    

    if t==len(b)-1:

        del b[0]
        t=0

    t+=1

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline


def ns():
    """
    入力を`[\\s]`を除いて文字列として取得
    """
    return readline().rstrip()


def ni():
    """
    入力を`int`に変換
    """
    return int(ns())


def main():
    from collections import defaultdict
    n = ni()
    primes = defaultdict(lambda: -1)
    for _ in range(n):
        # key = tuple(sorted(ns()))
        key = ''.join(sorted(ns()))

        if key not in primes:
            primes[key] = 0
        else:
            primes[key] += primes[key] + 1
    print(sum(primes.values()))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
b=[]
x=0
c=0
t=0
for i in range(N):

    a=list(input())

    a.sort(reverse=False)

    b.append(a)

while True:
    q=b.pop(0)

    for k in range(1,N-t-1):

        if q==b[k]:

            x+=1
    t+=1
    c+=1
    if c==N:
        break


print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = sorted([sorted(input()) for _ in range(N)])
ans = [1]
for i in range(N - 1):
    if S[i] == S[i + 1]:
        ans[-1] += 1
    elif ans[-1] > 2:
        ans += [1]
ret = 0
for a in ans:
    ret += a * (a - 1) // 2
print(ret)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    sl = [ tuple(input()) for _ in range(n) ] 
    ans = 0
    
    st = tuple(sl)
    
    for i in range(len(st)-1):
        for j in range(i+1,len(st)):
            if st[i] == st[j]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in D:
        D[S] += 1
    else:
        D[S] = 1
 
out = 0
for i in D.values():
    out += i-1
print(out)

Submission status: Wrong Answer

Solution code:
N=int(input())
b=[]
x=0
for i in range(N):

    a=list(input())

    a.sort(reverse=False)

    b.append(a)

for j in range(N):

    q=b.pop(0)

    for k in range(1,N-j-1):

        if q==b[k]:

            x+=1



print(x)

Submission status: Wrong Answer

Solution code:
from collections import Counter, defaultdict
from itertools import combinations

num = int(input())
keywords = [input() for _ in range(num)]

def anagrams(words):
  anagrams = defaultdict(list)
  for word in words:
    element = tuple(Counter(word).items())
    anagrams[element].append(word)
  return list(anagrams.values())

results = anagrams(keywords)
total_count = 0

for anagram in results:
  total_count += len(list(combinations(anagram, 2)))
  
print(total_count)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

print(lst)

for i in lst:
  if not i in d:
    d[i] = 1
    continue
  else:
    d[i] = d[i] + 1
    count = count + d[i]-1


print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

print(lst)

for i in lst:
  if not i in d:
    d[i] = 1
    continue
  else:
    d[i] = d[i] + 1
    coutn = count + d[i]-1


print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
l = {}
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    # print(tmp)
    if tmp in l.keys():
        if l[tmp] != 0:
            l[tmp] += ((l[tmp])*(l[tmp]+1)) // 2 + 1
        else:
            l[tmp] = 1
    else: 
        l[tmp] = 0
    # print(l)
print(sum(l.values()))

Submission status: Wrong Answer

Solution code:
from math import factorial

num=int(input())
stl =[''.join(sorted(input())) for i in range(num)]
stl.sort()

duplicate=[x for x in set(stl) if stl.count(x) > 1]
print(duplicate)

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += factorial(n) // 2 // factorial(n - 2)
print(count)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
N = int(input())
l = {}
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    if tmp in l.keys():
        if l[tmp] != 0:
            l[tmp] += l[tmp] + 1 
        else:
            l[tmp] += 1
    else: 
        l[tmp] = 0
print(sum(l.values()))

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    prev = (ok[val] - 1)
    if prev != 0:
        count += math.floor(ok[val] * prev / 2)

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(''.join(sorted(input())))
    
v = list(Counter(s).values())
ans = []
for i in range(len(v)):
    if v[i] >= 2:
        ans.append((v[i] * (v[i]-1))/2)

print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    prev = (ok[val] - 1)
    if prev != 0:
        count += math.floor(ok[val] * prev / prev)

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = [input() for _ in range(int(N))]
import math
ok = {}
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        ok[s] += 1 
    else:
        ok[s] = 1

for val in ok:
    count += math.floor(ok[val] * 2 / ok[val])
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

print(lst)

for i in lst:
  if not i in d:
    d[i] = 0
    continue
  else:
      if d[i] == 0:
        d[i] = d[i] + 1
        count = count + 1
      else:
        d[i] = d[i] + 1
        count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = []

for i in range(N):
    lst.append("".join(sorted(list(input()))))


d={}
count = 0

print(lst)

for i in lst:
  if not i in d:
    d[i] = 0
    continue
  else:
      if d[i] == 0:
        d[i] = d[i] + 2
        count = count + 2
      else:
        d[i] = d[i] + 1
        count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
from math import factorial
import sys

input=sys.stdin.readline

num=int(input())
stl =[''.join(sorted(input().strip('\n'))) for i in range(num)]
print(stl)

duplicate=[x for x in set(stl) if stl.count(x) > 1]

count=0

for dup in duplicate:
    n=stl.count(dup)
    count += factorial(n) // 2 // factorial(n - 2)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s_list = [input() for _ in range(int(N))]
ok = []
count = 0
for s in s_list:
    s = ''.join(sorted(s))
    if s in ok:
        count += 1
    else:
        ok.append(s)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for _ in range(n)]
existed = {}
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))
  num = existed.get(sorted_s, 0)
  existed[sorted_s] = num*2 if num != 0 else 1
cnt = 0
for k, v in existed.items():
  cnt += v
print(cnt-len(existed))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [input() for _ in range(n)]
existed = {}
for i in range(n):
  sorted_s = ''.join(sorted(s[i]))
  num = existed.get(sorted_s, 0)
  existed[sorted_s] = num*2 if num != 0 else 1
cnt = 0
for k, v in existed.items():
  cnt += v
print(cnt-2)

Submission status: Wrong Answer

Solution code:
# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()
print(l)

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s += 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += int(s * (s-1) / 2)
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
l=[]
for _ in range(n):
    l.append(input())
dic={}
for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    if aa not in dic.keys():
        dic[aa]=1
    else:
        dic[aa]+=dic[aa]

ans=0
for k in dic.values():
    ans+=int(k)

print(ans-len(dic))

Submission status: Wrong Answer

Solution code:
# -*- coding: UTF-8 -*-

n = int(input())
l = []

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()
print(l)

p = 0
s = 1
f = 0

for i in range(n-1):
    if l[i] == l[i+1] and i != n-2:
        s =+ 1
        f = 1

    elif l[i] != l[i+1] and f == 1:
        f = 0
        p += s * (s-1) / 2
        s = 1

    elif l[i] == l[i+1] and i == n-2:
        s += 1
        f = 0
        p += int(s * (s-1) / 2)


print(p)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
l=[]
for _ in range(n):
    l.append(input())
dic={}
for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    if aa in dic.keys():
        dic[aa]+=dic[aa]
    else:
        dic[aa]=1

ans=0
for k in dic.values():
    ans+=int(k)

print(ans-len(dic))

Submission status: Wrong Answer

Solution code:
def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = ''.join(sorted(input()))
        if word not in word_dict.keys():
            word_dict[word] = 1
        else:
            count += 1

    print(count)

if __name__ == '__main__':
    C()

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
#c = 0
#sort_dict = dict()
sort_list = list()
for i in range(n):
  i_sort = "".join(sorted(input()))
  #sort_dict[i] = i_sort
  sort_list.append(i_sort)
  #if not sort_dict[0]:
  #  if sort_dict[i] == sort_dict[i-1]:
  #    c += 1
counts = 0
cc = collections.Counter(sort_list)
v, c = zip(*cc.most_common())
#print(c)
for c_ in c:
  counts += (c_ * (c_ - 1)) / 2
print(counts)
"""
values, counts = zip(*cc.most_common())
if counts != 1:
  print(counts)
 """

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

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

line = defaultdict(int)

for anagram in s:
  a = sorted(anagram)
  line[''.join(a)] += 1

_sum = 0

for i in line:
  if line[i] == 1:
    continue
  elif line[i] == 2:
    _sum +=1
  else:
    _sum += line[i]

print(_sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 23:27:57 2019

@author: doppe
"""

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}

ans = 0
for i in range(0, len(S)):
    a = list(S[i])
    a.sort()
    b = ''.join(a)
    if b in groupDict:
        groupDict[b] += 1
    else :
        groupDict[b] = 1

for v in groupDict.values():
    ans += (v * (v - 1)) / 2
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())

dd = {'a1':0}
cnt = 0

for i in range(n):
  s = ''.join(sorted(input()))
  if s in dd.keys():
    dd[s] += 1
    cnt += 1
  else:
    dd[s] = 0
  
  
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
S=[input() for _ in range(n)]
SS=[''.join(sorted(i)) for i in S]
l=[]
ans=0
for s in SS:
    if s in l:
        ans+=1
    else:
        l.append(s)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
#print(dicS)
		
ans = 0
for v in dicS.values():
	if v != 1:
		ans += v*(v-1)/2
	
print(ans)

Submission status: Wrong Answer

Solution code:
import math
a=int(input())
b=[sorted(input()) for j in range(a)]
b.sort()
sum=0
c=1
for i in range(a-1):
  if b[i]==b[i+1]:
    c+=1
  else:
    sum+=math.factorial(c)//2
    c=1
  if i==a-2:
    sum+=c*(c-1)//2
    
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
# スペース区切りの整数の入力
a = []
for i in range(N):
  a.append(input())

b = []
for s in a:
  temp = list(s)
  temp.sort()
  b.append("".join(temp))

print(len(b) - len(set(b)))

Submission status: Wrong Answer

Solution code:
import numpy as np
import string

a = string.ascii_lowercase

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

for i in range(N):
    s.append(input())
    
k = np.zeros((N,26))

for i in range(N):
    for j in range(26):
        k[i,j] = s[i].count(a[j])

l = np.zeros(N)
for i in range(N):
    for j in range(26):
        l[i] += (5**(j+1)) * k[i,j]

m = np.zeros(0)
for j in range(N):
    i = 0
    m = np.append(m, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

ans = 0
for i in range(np.size(m)):
    ans += m[i] * (m[i]-1) /2
    
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
a=int(input())
b=[sorted(input()) for j in range(a)]
b.sort()
sum=0
c=1
for i in range(a-1):
  if b[i]==b[i+1]:
    c+=1
  else:
    sum+=math.factorial(c)//2
    c=1
  if i==a-2:
    sum+=math.factorial(c)//2
    
print(sum)

Submission status: Wrong Answer

Solution code:
import numpy as np
import string

a = string.ascii_lowercase

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

for i in range(N):
    s.append(input())
    
k = np.zeros((N,26))

for i in range(N):
    for j in range(26):
        k[i,j] = s[i].count(a[j])

l = np.zeros(N)
for i in range(N):
    for j in range(26):
        l[i] += (11**(j+1)) * k[i,j]

m = np.zeros(0)
for j in range(N):
    i = 0
    m = np.append(m, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

ans = 0
for i in range(np.size(m)):
    ans += m[i] * (m[i]-1) /2
    
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)
n = int(input())
s=[]
for i in range(n):
    s.append(input())

list_s = []
for j in range(n):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

def cmb(num):
    if num == 1:
        return 0
    elif num == 2:
        return 1
    else:
        return (num * (num-1) // 2)
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]] )


print(count)

Submission status: Wrong Answer

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

list_s = []
for j in range(n):
    #list_s.append(sorted(list(s[j])))
    list_s.append(''.join(sorted(s[j])))

m = {}
for i in range(n):
    if list_s[i] not in m:
        m[list_s[i]] = 1
    else:
        m[list_s[i]] += 1

def cmb(num):
    if num == 1:
        return 0
    elif num == 2:
        return 1
    else:
        return (num * (num-1) // 2)
  
count = 0
for k in range(len(m)):
        count += cmb( m[list_s[k]] )


print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
slist = []
for i in range(n):
    w = input()
    slist.append(''.join(sorted(w)))

n_dup = len(slist) - len(list(set(slist)))
print(n_dup)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

N = int(input())

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

line = defaultdict(int)

for anagram in s:
  a = sorted(anagram)
  line[''.join(a)] += 1

_sum = 0

for i in line:
#  _sum += int((line[i] * (line[i] - 1)) / 2)
  if  line[i] == 2:
    _sum += line[i] - 1
  else:
    _sum += line[i]

print(_sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = map(str, input().split())
slist = []
for w in a:
    _w = ''.join(sorted(list(w)))
    slist.append(_w)
    print(_w)
n_dup = len(slist) - len(list(set(slist)))
print(n_dup)

Submission status: Wrong Answer

Solution code:
N = int(input())

str_list = [input() for i in range(N)]

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 0
        continue
    if cnt_dict[s_str] == 0:
        cnt_dict[s_str] += 1
    else:
        cnt_dict[s_str] += cnt_dict[s_str] + 1

print(sum(list(cnt_dict.values())))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(raw_input())
cnt = 0
dic = {}

for _ in xrange(N):
	rs = ''.join(sorted(raw_input()))
	
	print rs
	print dic
	
	
	if rs in dic:
		cnt += dic[rs]
		dic[rs] += 1
	else:
		dic[rs] = 1
print cnt

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input() for _ in range(N)]
mydict = {}
ans = 0
for i in range(N):
    T = [str(x) for x in S[i]]
    T.sort()
    S[i] = ''.join(T)
for j in range(N):
    if S[j] in mydict.keys():
        ans += 1
    else:
        mydict.setdefault(S[j],j)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
s_dic = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in s_dic.keys():
        s_dic[s] += 1
        cnt += s_dic[s]
    else:
        s_dic[s] = 1
        cnt += s_dic[s]

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
l_cnt = []
for i in range(N):
  s.append(''.join(sorted(input())))

dic = {}
for x in s:
  if dic.get(x) == None:
    dic[x] = 1
  else:
    dic[x] += 1

print(list(map(lambda n: n*(n-1)//2,list(dic.values()))))

Submission status: Wrong Answer

Solution code:
N=int(input())
slist=[]
ans=0
for s in range(N):
	line=list(input()).sort()
	slist+=[line]
	ans+=slist.count(line)-1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = 0
s_dic = {}
for _ in range(n):
    s = ''.join(sorted(input()))
    if s in s_dic:
        s_dic[s] += 1
        cnt += s_dic[s]
    else:
        s_dic[s] = 1
        cnt += s_dic[s]

print(cnt)

Submission status: Wrong Answer

Solution code:
a = map(str, input().split())
slist = []
for w in a:
    _w = ''.join(sorted(list(w)))
    slist.append(_w)
n_dup = len(slist) - len(list(set(slist)))
print(n_dup)

Submission status: Wrong Answer

Solution code:
N = int(input())

str_list = [input() for i in range(N)]

cnt_dict = {}

for str in str_list:
    s_str = "".join(sorted(str))
    print(s_str)
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    total += len(list(itertools.combinations(range(cnt), 2)))

print(total)

Submission status: Wrong Answer

Solution code:
from collections import Counter
lens = int(input())
hashes = [''.join(sorted(input())) for _ in range(lens)]
ansv = Counter(hashes).values()
ans = sum([x//2 * 2 for x in ansv ])
print(ans)

Submission status: Wrong Answer

Solution code:
def find(strings):
    count={}
    ans=0
    for s in strings:
        s="".join(sorted([x for x in s]))
        print(s)
        if s in count:
            count[s]+=1
        else:
            count[s]=1
    for s in count:
        temp=count[s]
        ans+=temp*(temp-1)
    return ans//2
strings=[]
for _ in range(int(input())):
    
    strings+=[input()]
print(find(strings))

Submission status: Wrong Answer

Solution code:
n = int(input())
d = {}
ans = 0
for st in range(n):
    s = ''.join(sorted(input()))
    if d.get(s) == None:
        d[s] = 1
    else:
        ans += d[s]
        d[s] += 1

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [input() for i in range(N)]
d = {}
S_trans = [''.join(sorted(list(s))) for s in S]
print(S_trans)
count = 0
for s in S_trans:
  if s in d:
    count += d[s]
    d[s] += 1
  else:
    d[s] = 1
  #print(d, count)
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

dic = {}
for i in range(N):
	s = input()
	s = ''.join(sorted(s))
	if s in dic:
		dic[s] += dic[s]+1
	else:
		dic[s] = 0
print(sum(dic.values()))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
ans = [s.count(a) for a in list(set(s)) if s.count(a) > 1]
for i in range(len(ans)):
    if ans[i] == 2:
        ans[i] -= 1
print(sum(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in dic.keys():
    dic[s] = 2 * dic[s] + 1
  else:
    dic[s] = 0
count = sum(dic.values())
print(count)

Submission status: Wrong Answer

Solution code:
import sys

n=int(input())
l=[]
for _ in range(n):
    l.append(input())
dic={}
for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    if aa in dic.keys():
        dic[aa]+=dic[aa]+1
    else:
        dic[aa]=0

ans=0
for k in dic.values():
    ans+=int(k)

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
dic = {}
for _ in range(N):
  s = ''.join(sorted(input()))
  if s in dic.keys():
    dic[s] = 1 if dic[s] == 0 else 2 * dic[s] + 1
  else:
    dic[s] = 0
count = sum(dic.values())
print(count)

Submission status: Wrong Answer

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

d = {}

S_trans = [''.join(sorted(list(s))) for s in S]

count = 0
for s in S_trans:
  if s in d:
    d[s] += 1
  else:
    d[s] = 1
  count += d[s]

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
S=[sorted(list(input())) for i in range(N)] 
Slist = [0] * N
for i in range(N):
   Slist[i] = sorted(S[i])
def get_unique_list(seq):
   seen = []
   return [x for x in seq if x not in seen and not seen.append(x)]
if len(Slist) - len(get_unique_list(Slist)) == 0:
   print(0)
else:
   print(len(Slist) - len(get_unique_list(Slist)))

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
ans = 0
s_d = set()
for i in range(N):
    if s[i] in s_d:
        ans += 1
    s_d.add(s[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
S=[sorted(list(input())) for i in range(N)] 
Slist = [0] * N
for i in range(N):
   Slist[i] = sorted(S[i])
def get_unique_list(seq):
   seen = []
   return [x for x in seq if x not in seen and not seen.append(x)]
if len(Slist) - len(get_unique_list(Slist)) == 0:
   print(0)
else:
   print(len(Slist) - len(get_unique_list(Slist)) + 1)

Submission status: Wrong Answer

Solution code:
n = int( input() )

dict = {}
for i in range( n ):
	sorted_input = "".join( sorted( list( input() ) ) )
	if dict.get( sorted_input ) == None:
		dict[ sorted_input ] = 0
	else :
		dict[ sorted_input ] += 1

count = 0
for eachValue in dict.values():
	count += eachValue
print( count )

Submission status: Wrong Answer

Solution code:
n = int( input() )

dict = {}
for i in range( n ):
	sorted_input = "".join( sorted( list( input() ) ) )
	print( sorted_input )
	if dict.get( sorted_input ) == None:
		dict[ sorted_input ] = 0
	else :
		dict[ sorted_input ] += 1

count = 0
for eachValue in dict.values():
	count += eachValue
print( count )

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
strList = []
for i in range(N):
    inStr = input()
    inNum = 0
    for j in range(len(inStr)):
        inNum = inNum + ord(inStr[j])-64
    strList.append(inNum)

anaglam = 0

c = collections.Counter(strList)
for i in c.keys():
    anaglam = anaglam + c[i]*(c[i]-1)//2
    
print(anaglam)

Submission status: Wrong Answer

Solution code:
import math


def main():
    n = int(input())
    ans = {}
    for i in range(n):
        inp = ''.join(sorted(input()))

        one = ans.get(inp)
        if one is None:
            ans[inp] = 0
        else:
            tmp = ans[inp]
            ans[inp] += ans[inp] + 1
    print(sum(ans.values()))


if __name__ == '__main__':
    main()