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:
N = int(input())
S = [input() for _ in range(N)]
check_box = []
ans = 0
for s in S:
  s = sorted(s)
  s = ''.join(s)
  if s in check_box:
    ans += 1
  else:
    check_box.append(s)
print(ans)

Submission status: Wrong Answer

Solution code:
import collections  
n = int(input())
s = [str(sorted(input())) for i in range(n)]
c = collections.Counter(s)
print(c.values())

print(sum((v*(v-1))//2 for v in c.values()))

Submission status: Wrong Answer

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

s.sort()
ans = 0

for i in range(n-1):
    if s[i] == s[i+1]:
            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(str(input()))

B =[]
for i in S:
    S1 =list(Counter(i).items())
    #S1 =sorted(S1, reverse = False)
    B.append(S1)

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S =[]
for i in range(N):
    S.append(str(input()))

B =[]
for i in S:
    S1 =list(Counter(i).items())
    #S1 =sorted(S1, reverse = False)
    B.append(S1)

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

Submission status: Wrong Answer

Solution code:
import collections
n = int(input())
a = []
res= 0
for i in range(n):
  tmp = collections.Counter(input()).most_common()
  if a.count(tmp) >= 1:
    res += a.count(tmp)
  a.append(tmp)
print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def solve():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        a = ''.join(sorted(list(input())))
        if a in d:
            d[a] += d[a]+1
        else:
            d[a] = 0
    return sum([i for i in d.values()])

print(solve())

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

SETS = defaultdict(int)
for i in range(N):
    SETS[tuple(set(S[i]))] += 1


def factorial(n):
    r = 1
    for i in range(1, n+1):
        r *= i
    return r


ans = 0
for i in SETS:
    if SETS[i] > 1:
        ans += factorial(SETS[i]) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

d = defaultdict(int)

for s in S:
    s.sort()
    s = "".join(s)
    d[s] += 1

ans = 0

for key in list(d):
    ans += d[key] * (d[key] - 1) // 2

print(ans)
print(d)

Submission status: Wrong Answer

Solution code:
from math import factorial

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

for s in S:
    s.sort()

S.sort()

cnt = 1
ans = 0
tmp = []

for s in S:
    if s == tmp:
        cnt += 1
    else:
        tmp = s
        ans += factorial(cnt) // 2
        cnt = 1

ans += factorial(cnt) // 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
l = {}
for i in range(N):
  s = input()
  s = ''.join(sorted(s))
  if s in l:
    l[s] += 1
  else:
    l[s] = 0
ans = 0
value_l = [1]
for value in l.values():
  if len(value_l) >= value:
    tmp = value_l[value - 1]
  else:
    l_val = len(value_l)
    for i in range(l_val, value):
      value_l.append(value_l[i-1] + i + 1)
    tmp = value_l[value - 1]
  ans += tmp

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
words = dict()
count = 0
for i in range(N):
    s = ''.join(sorted(input()))
    if s in words:
        count += words[s]
        words[s] += 1
    else:
        words[s] = 1

Submission status: Wrong Answer

Solution code:
N = int(input())
sc = [list(input()) for i in range(N)]
for i in sc:
    i.sort()
count = 0
for i in range(0 , len(sc)-1):
    for j in range(i+1,len(sc)):
        if sc[i] == sc[j]:
            count += 1

Submission status: Wrong Answer

Solution code:

n = int(input())
s = []
ans = 0
for i in range(n):
    a = list(input())
    a.sort()
    s.append("".join(a))

x = set(s)
y = []
for i in range(len(x)):
    y.append(s.count(s[i]))

#print(y)
for j in range(len(y)):
    ans += int((y[j]*(y[j]-1))/2)

print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
list_voc = [str(input()) for _ in range(n)]
list_mo = []
for i, s in enumerate(list_voc):
    list_n = list(s)
    list_n.sort()
    list_n = ''.join(list_n)
    list_mo.append(list_n)


set_mo = set(list_mo)
list_mo_s = list(set_mo)
ans = []
for s in list_mo_s:
    ans.append(list_mo.count(s))

ans_val = []

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

ans.reverse()
for i in range(len(ans)):
    if ans[i] == 1:
        break
    else:
        ans_val.append(cmb(ans[i], 2))

print(sum(ans_val))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
list_voc = [str(input()) for _ in range(n)]
list_mo = []
for i, s in enumerate(list_voc):
    list_n = list(s)
    list_n.sort()
    list_n = ''.join(list_n)
    list_mo.append(list_n)


set_mo = set(list_mo)
list_mo_s = list(set_mo)
ans = []
for s in list_mo_s:
    ans.append(list_mo.count(s))

ans_val = []
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in range(len(ans)):
    if ans[i] == 1:
        break
    else:
        ans_val.append(combinations_count(ans[i], 2))

print(sum(ans_val))

Submission status: Wrong Answer

Solution code:
n = int(input())
list_voc = [str(input()) for _ in range(n)]
list_mo = []
for i, s in enumerate(list_voc):
    list_n = list(s)
    list_n.sort()
    list_n = ''.join(list_n)
    list_mo.append(list_n)


set_mo = set(list_mo)
list_mo_s = list(set_mo)
ans = []
for s in list_mo_s:
    ans.append(list_mo.count(s))

if max(ans) == 1:
    print(0)
else:
    print(sum(ans) - 1)

Submission status: Wrong Answer

Solution code:
from math import factorial
from collections import Counter
def comb(n,k):
  if n<0 or k<0 or n<k:return 0
  if n==0 and k==0:return 1
  a=factorial(n)
  b=factorial(k)
  c=factorial(n-k)
  return a//(b*c)
n=int(input())
s=[list(Counter(input())) for i in range(n)]
s.sort()
cnt=1
ans=0
for i in range(1,n):
  if s[i]==s[i-1]:
    cnt+=1
  else:
    ans+=comb(cnt,2)
    cnt=1
if cnt>=2:
  ans+=comb(cnt,2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    lines = ["".join(sorted(line.rstrip())) for line in sys.stdin.readlines()]

    ret = 0
    for n in range(0, N-1):
        item = lines.pop(n)
        if item in lines:
            ret += 1

        lines.insert(n, item)

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = int(sys.stdin.readline().rstrip())
    lines = ["".join(sorted(line.rstrip())) for line in sys.stdin.readlines()]
    sortedline = sorted(lines)

    ret = 0
    for n in range(N - 1):
        if sortedline[n] == sortedline[n + 1] or sortedline[n] == sortedline[n - 1]:
            ret += 1

    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
ss = []
for _ in range(n):
  s = input()
  S = []
  for c in s:
    S.append(c)
  S.sort()
  ss.append(''.join(S))
  
print(n-len(set(ss)))

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sort_tmp=sorted(tmp)
    stmp=''.join(sort_tmp)
    if((stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)

total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(s,total)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
for _ in range(N):
    tmp=list(input())
    s.append(sorted(tmp))
total=0

while (s):
    cnt=0
    comp=s.pop(0)
    for word in (s):
        if(comp==word):
            cnt+=1
            s.remove(comp)
    total+=(1+cnt)*cnt//2


print(total)

Submission status: Wrong Answer

Solution code:
N=int(input())
s=[]
for _ in range(N):
    tmp=list(input())
    s.append(sorted(tmp))

cnt=0
def hantei(s):
    global cnt
    comp=s.pop(0)
    for n,word in enumerate(s):
        if(comp==word):
            cnt+=1
            s.remove(comp)
        else:
            hantei(s[:])

hantei(s[:])

print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
dictionary={}
for i in range(N):
    s="".join(sorted(input()))
    if s in dictionary:
        dictionary[s]+=dictionary[s]
    else:
        dictionary[s]=1
count=0
for value in dictionary.values():
    count+=value-1
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

for j in d.values():
    if j == 1:
        pass
    elif j == 2:
        ans += 1
    else:
        ans += j
        
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())

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

for j in d.values():
    if j == 1:
        pass
    else:
        ans += math.factorial(j)//2
        

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0]*n

for i in range(n):
  a = input()
  b = 0
  for j in range(10):
    b += ord(a[j])
  s[i] = b

t = list(set(s))

p = 0
for i in t:
  x = s.count(i)
  if x > 1:
    p += x*(x-1)//2
print(p)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [0]*n

for i in range(n):
  a = input()
  b = 0
  for j in range(10):
    b += ord(a[j])
  s[i] = b

t = list(set(s))
p = 0
for i in t:
  x = s.count(i)
  if x > 1:
    p += x*(x-1)/2
print(int(p))

Submission status: Wrong Answer

Solution code:
from collections import Counter
from collections import defaultdict
from scipy.misc import comb

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

dd = defaultdict(int)
for i in range(N):
  s = "".join(sorted(S[i]))
  dd[s] += 1

ans = 0
for key, val in dd.items():
  ans += comb(val, 2)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from math import factorial
n = int(input())
dic = {}
ans = 0
for i in range(n):
    x = sorted(list(input()))
    s = "".join(x)
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
        
for j in dic.values():
    if j >= 2:
        ans += factorial(j) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
l.sort()
c = 0
b = l[0]
ans = 0
for s in l[1:]:
    if s == b:
        c += 1
    else:
        ans += c * (c + 1) * 0.5
        c = 0
    b = s
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
l.sort()
c = 0
b = l[0]
ans = 0
for s in l[1:]:
    if s == b:
        c += 1
        ans += math.factorial(c)
    else:
        c = 0
    b = s
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
d = [0 for i in range(n)]
for i in range(n):
    a = 0
    for j in input():
        a += 2**(ord(j)-97)
    d[i] = a
d = sorted(d)
ans = 0
co = 1
for i in range(1, n):
    if d[i-1] == d[i]:
        co += 1
    else:
        ans += co*(co-1) // 2
        co = 1
ans += co*(co-1) // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import collections
from scipy.misc import comb
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
r = collections.Counter(s)
for k, v in r.items():
    if v > 1:
        c += comb(v, 2)

print(int(c))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
import collections
from scipy.misc import comb
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
r = collections.Counter(s)
for k, v in r.items():
    if v > 1:
        c += comb(v, 2)

print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = "anfenvdids"
    #s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
list=sorted(list)
n=list[0]
m=0
for j in range(1,N):
  if n==list[j]:
    m+=1
    n=list[j]
  else:
    m=m
    n=list[j]
    
print(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
list=sorted(list)
n=list[0]
m=0
for j in range(1,N):
  if list[j]==n:
    m+=1
    n=list[j]
print(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
list=sorted(list)
n=list[0]
m=0
for j in range(1,N):
  if n==list[j]:
    m+=1
    n=list[j]
print(m)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
list=sorted(list)
t=0
n=list[0]
for i in range(N-1):
    if n==list[i+1]:
      t+=1
      n=list[i+1]
    else:
      t=t
      n=list[i+1]
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
list=sorted(list)
t=0
n=list[0]
for i in range(N-1):
    if n==list[i+1]:
      t+=1
      n=list[i+1]
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
t=0
n=list[0]
for i in range(N-1):
  if n==list[i+1]:
    t+=1
    n=list[i+1]
  else:
    t=t
    n=list[i+1]
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
t=0
n=list[0]
for i in range(N-1):
  if n==list[i+1]:
    t+=1
    n=list[i+1]
  else:
    t=t
    n=list[i+1]
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
t=0
n=list[0]
for i in range(N-1):
  if n==list[i+1]:
      t+=1
      n=list[i+1]
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=sorted(input())
  list.append(s)
  list=sorted(list)
t=0
for i in range(N-1):
  if list[i]==list[i+1]:
    t+=1
  else:
    t=t
print(t)

Submission status: Wrong Answer

Solution code:
N=int(input())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
  list=sorted(list)
t=0
for i in range(N-1):
  if list[i]==list[i+1]:
    t+=1
print(t)

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
import numpy as np

n, *s = sys.stdin.read().split()
n = int(n)

def comb_2(n):
    return n * (n - 1) // 2

def main():
    t = [''.join(sorted(t)) for t in s]
    v = np.array(list(Counter(t).values()), dtype=np.int32)
    return np.sum(comb_2(v))

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def Speed_Anag_Count(String):
    count = {}
    for i in String:
        i = sorted(i)
        i = str(''.join(i))
        if count.get(i) != True:
            count[i] = 0
        count[i] += 1
    
    return count

N = int(input())

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

count = Speed_Anag_Count(S)

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

Submission status: Wrong Answer

Solution code:
import numpy as np

def Speed_Anag_Count(String):
    count = {}
    for i in String:
        i = sorted(i)
        i = str(''.join(i))
        if count.get(i) != True:
            count[i] = 0
        count[i] += 1
    
    return count

N = int(input())

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

count = Speed_Anag_Count(S)

ans=1
for i in count.values():
    ans = ans*(i*(i-1)/2)
    
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import collections

n=int(input())
s=[(input()) for _ in range(n)]

lis=[list(s[i]) for i in range(n)]
lis_sort = [sorted(lis[i]) for i in range(n)]
lis_sort = [''.join(lis_sort[i]) for i in range(n)]
lis_sort.sort()

c = collections.Counter(lis_sort)
values, counts = zip(*c.most_common(len(c)))
cnt=0
for i in range(len(counts)):
    if counts[i]==2: cnt+=1
    elif counts[i]>2: cnt+=counts[i]
print(cnt)

Submission status: Wrong Answer

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

lis=[list(s[i]) for i in range(n)]
lis_sort = [sorted(lis[i]) for i in range(n)]
lis_sort = [''.join(lis_sort[i]) for i in range(n)]

cnt=0#counter
ans=0
for i in range(n-1):
    if lis_sort[i]==lis_sort[i+1]:
        cnt+=1
    elif lis_sort[i]!=lis_sort[i+1]:
        ans+=cnt+1
        cnt=0

print(ans)

Submission status: Wrong Answer

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

lis=[list(s[i]) for i in range(n)]
lis_sort = [sorted(lis[i]) for i in range(n)]
lis_sort = [''.join(lis_sort[i]) for i in range(n)]

cnt=0
for i in range(n-1):
    if lis_sort[i]==lis_sort[i+1]: cnt+=1
print(cnt+1)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))

for i in range(n-1):
    string = s[i]
    if count_lst(string) in anagram_lst and anagram_lst.count(count_lst(string))>1:
        number += 1

print(number)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
from scipy import misc


def main():
    
    n = int(input())

    words_list = []
    for _ in range(n):
        sorted_word = ''.join(sorted(input()))
        words_list.append(sorted_word)
    words_set = set(words_list)

    anagram_pair_count_all = 0
    for word in words_set:
        same_word_count = words_list.count(word)
        anagram_pair_count_all += int(misc.comb(same_word_count, 2))

    print(anagram_pair_count_all)

    return 0


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
count = 0

def is_anagram(test:str, original:str):
    if len(test) != len(original):
        return False
    for letter in test.lower():
        if letter not in original.lower():
            return False
    for letter in original.lower():
        if letter not in test.lower():
            return False
    return True

for i in range(n):
    s = input()
    if i == 0:
        l.append(s)
        continue

    for line in l:
        if is_anagram(s, line):
            count += 1
    l.append(s)

print (count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def nCr(n, r):
    mod=10**9+7
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
n=int(input())
S=["".join(sorted(input())) for _ in range(n)]
D={}
for i in S:
    if i not in D:
        D[i]=1
    else:
        D[i]+=1
ans=0
for i in D.values():
    ans+=nCr(i,2)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def comb_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

N = INT()
S = [input() for _ in range(N)]
S = sorted(S)
for i in range(N):
	S[i] = sorted(S[i])

ku = []
kugiri = 0
for i in range(N - 1):
	if S[i] == S[i + 1]:
		kugiri += 1
		if i == N - 2:
			ku.append(kugiri + 1)

	else:
		ku.append(kugiri + 1)
		kugiri = 0

wa = 0
for i in range(len(ku)):
	if ku[i] == 1:
		continue
	wa += comb_count(ku[i], 2)

print(wa)

Submission status: Wrong Answer

Solution code:
n = int(input())
list_1 = []

def has_duplicates2(list_1):
    seen = []
    unique_list = [x for x in list_1 if x not in seen and not seen.append(x)]
    return len(unique_list)


for i in range(n):
    list_1.append(sorted(input()))



print(has_duplicates2(list_1))

Submission status: Wrong Answer

Solution code:
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

N = int(input())
s = [0]*(N+1)
for i in range(1, N+1):
    s[i] = input()

ans = 0
ss = set()
for i in range(1, N+1):
    now = "".join(sorted(list(s[i])))
    if now in ss:
        ans += 1
    else:
        ss.add(now)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
res = dict()
for i in range(n):
    m = input()
    m = sorted(m)
    m = ''.join(m)
    if m in res:
        res[m] += 1
    else:
        res[m] = 0
print(sum(res.values()))

Submission status: Wrong Answer

Solution code:
n = int(input())
moji = []
res = set()
count = 0
for i in range(n):
    m = input()
    m = sorted(m)
    m = ''.join(m)
    if m in res:
        count += 1
    else:
        res.add(m)
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
moji = []
res = set()
count = 0
for i in range(n):
    m = input()
    m = sorted(m)
    m = ''.join(m)
    if m in res:
        count += 1
    else:
        print(m)
        res.add(m)
print(count)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[sorted(input()) for _ in range(N)]
Y=[]
for i in range(len(L)):
    Y.append("".join(L[i]))
print(N-len(set(Y)))

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[sorted(input()) for _ in range(N)]
Y=[]
for i in range(len(L)):
    Y.append("".join(L[i]))
print(len(set(Y)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
ans = 0

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

for i in range(n):
    s = input()
    new_s = "".join(sorted(s))
    s_list.append(new_s)

for i in set(s_list):
    cnt = s_list.count(i)
    if cnt > 1:
        ans += math.factorial(cnt) // math.factorial(2)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
count = 0
for i in Counter(S).values():
  count = i*(i-1)//2
print(count)

Submission status: Wrong Answer

Solution code:
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
count = 0
for i in Counter(S).values():
  count = 1*(i-1)//2
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
S = []
for i in range(n):
    s = input()
    li = sorted(list(s))
    S.append(li)
ans = 0
S.sort()
fac = S[0]
cnt = -1
for i in range(n):
    if S[i] == fac:
        cnt += 1
    else:
        fac = S[i]
        ans += max(cnt,0)
        cnt = 0
ans += max(cnt,0)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())

# むずい！
anagrams = defaultdict(int)
for _ in range(N):
    chars = input()
    d = defaultdict(int)
    tuple_d = tuple(sorted(chars))
    if tuple_d in anagrams:
        anagrams[tuple_d] += anagrams[tuple_d]
    else:
        anagrams[tuple_d] += 1

print(sum([i-1 for i in anagrams.values() if i > 0]))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
N = int(input())

# むずい！
anagrams = defaultdict(int)
for _ in range(N):
    chars = input()
    d = defaultdict(int)
    tuple_d = tuple(sorted(chars))
    if tuple_d in anagrams:
        anagrams[tuple_d] += anagrams[tuple_d]
    else:
        anagrams[tuple_d] += 1

print(sum([i-1 for i in anagrams.values()]))

Submission status: Wrong Answer

Solution code:
n=int(input())
x=[]
cnt=0
for i in range(n):
  a=sorted(input())
for i in range(n):
  if a in x:cnt+=1
  else:x.append(a)
print(cnt)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = {}
ans = 0
for i in range(n):
    a = input()
    a = ''.join(sorted(a))
    if a in s:s[a] +=1
    else: s[a] = 1
for i in s:
    a = s[i]
    ans += math.factorial(a)//math.factorial(2)
print(ans)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
s = [0]*n
ans = {}
ans_v = 0

for i in range(n):
    s[i] = "".join(sorted(list(input())))
    
s_set = set(s)

for i in s_set:
    ans[i] = 0
    
for i in s:
    ans[i] += 1

for j in ans.values():
    if j >= 2:
        ans_v += math.factorial(j) /( (math.factorial(j - 2)* math.factorial(2)))
    
print(ans_v)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, s: "List[str]"):
    l = [''.join(sorted(list(i))) for i in s]
    from collections import Counter
    c = Counter(l)

    def combination(n, r, mod=10**9+7):
        n1, r = n+1, min(r, n-r)
        numer = denom = 1
        for i in range(1, r+1):
            numer = numer * (n1-i) % mod
            denom = denom * i % mod
        return numer * pow(denom, mod-2, mod) % mod

    ans = 0
    for k, v in c.most_common():
        if v >= 2:
            ans += combination(v, 2)

    print(ans)

    return



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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())

s = []

for i in range(N):
  moji = input()
  mojilist = list(moji).sort
  s.append(mojilist)
ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] == s[j]:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import math

N = int(input())
li = [input() for i in range(N)]
d = defaultdict(int)

count = 0

for i in li:
  s = sorted(list(i))
  t = "".join(s)

  if d[t] != 0:
    count += 1
  d[t] += 1
    
print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = []
for _ in range(n):
    #s.append(list(input())) # !!!
    #s.append(sorted(list(input()))) # !!!
    s.append(sorted(input())) # !!!
print(s)
 
x = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            x += 1
 
print(x)

Submission status: Wrong Answer

Solution code:
N = int(input())
e_tmp = []
for _ in range(N):
    e_tmp.append(list(input()))
import copy
e = copy.deepcopy(e_tmp)
for i in range(N):
    e[i] = sorted(e_tmp[i])
done_flg = [0]*N
cal = 0
for i in range(N):
    tmp_cal = 0
    done_flg[i] = 1
    for j in range(i+1,N):
        #print(j)
        if done_flg[j] == 0:
            if e[i] == e[j]:
                tmp_cal += 1
                done_flg[j] = 1
                if tmp_cal != 1:
                    tmp_cal = ((tmp_cal+1)*tmp_cal)/2
                    #print(((tmp_cal-1)*tmp_cal)/2)
    cal += tmp_cal
print(cal)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
x = []
for _ in range(n):
    x.extend(sorted([ord(i) - 97 for i in input()]))
x = np.array(x).reshape(n,10)
count = 0
for i in x:
    count += (len(np.where(x == i)[0])/10) - 1
print(int(count/2))

Submission status: Wrong Answer

Solution code:
nn,*a=open(0).read().split()
n=int(nn)
cnt=0
for left in range(n-1):
  for right in range(left+1,n):
    for leng in range(10):
      flg=True
      if not a[left][leng] in a[right]:
        flg=False
        break
    if flg:
      cnt+=1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())

memo = {}
ans = 0

for i in range(N):
  s = input()
  so = str(sorted(s))
  if so in memo:
    ans += 1
  else:
    memo[so] = True

print(ans)