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: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int)

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

ans = 0
for j in range(len(s)):
    mozi = sorted(s[j])
    mozi_s = "".join(mozi)
    ans += dic[mozi_s]
    dic[mozi_s] += 1
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

#Dictionaly
dic = {}

for i in range(N):
    words_sort = ''.join(sorted(s[i]))
    if (words_sort in dic) == True:
        dic[words_sort] += 1
    else:
        dic[words_sort] = 1

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

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
S = [""] * N
for n in range(N):
    S[n] = input()
from collections import defaultdict
dct = defaultdict(int)
for s in S:
    sorted_s = "".join(sorted(s))
    dct[sorted_s] += 1
ans = 0
for k,v in dct.items():
    ans += v*(v-1)//2
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip() for _ in range(n)]
new = []
for i in range(n):
    sort = sorted(data[i])
    sorting = "".join(sort)
    new.append(sorting)
new.sort()
score = 0
s = 0
count  = 0
while s<n-1:
    daburi = 1
    for p in range(s,n-1):
        if new[p] == new[p+1]:
            daburi += 1
        else:
            break
    score += daburi*(daburi-1)//2
    count += daburi
    s = count
print(score)

Submission status: Accepted

Solution code:
n = int(input())


res = 0
d = {}
for _ in range(n):
    ss = list(input())
    ss.sort()
    s = ''.join(ss)
    if s in d:
        res += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(res)

Submission status: Accepted

Solution code:
N = int(input())
S = []
for i in range(N):
    S.append(input())
# print(N, S)

for i in range(len(S)):
    s = S[i]
    t = list(s)
    t.sort()
    S[i] = ''.join(t)

S.sort()
# print(S)

ans = 0
count = 0
for i in range(N - 1):
    si = S[i]
    sj = S[i + 1]
    if si != sj:
        ans += count * (count + 1) // 2
        count = 0
    else:
        count += 1
        if i == N - 2:
            # 最後の足し忘れ防止
            ans += count * (count + 1) // 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
data = []
for i in range(n):data.append(sorted(input()))
data, backup, ans, temp = sorted(data), [], 0, 1
for i in data:
    if backup==i:temp+=1
    else:ans, temp = ans + int(temp*(temp-1)/2), 1
    backup = i
ans+= int(temp*(temp-1)/2)
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, stdin
from operator import mul
from functools import reduce
from collections import Counter
N = int(stdin.readline().rstrip())
S = Counter(''.join(sorted(list(stdin.readline().rstrip()))) for _ in range(N))

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 = 0
for i in S.values():
    if i > 1:
        ans += cmb(i, 2)
print(ans)

Submission status: Accepted

Solution code:
num = int(input())
li = [input() for i in range(num)]

dic = {}
ans = 0
for i in range(num):
    now = "".join(sorted(li[i]))
    if now in dic:
        dic[now] += 1
    else:
        dic[now] = 1
for i in dic:
    n = dic[i]
    ans += int((n*(n-1))/2)

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
from collections import defaultdict
d = defaultdict(list)
for i in range(n):
    d[anagrams[i]].append(i)
from scipy.misc import comb
cnt=0
for k, v in d.items():
    cnt+=comb(len(v), 2, exact=True)
print(cnt)

Submission status: Accepted

Solution code:
import collections
n=int(input())
s=[''.join(sorted(input())) for i in range(n)]
s_cnt=collections.Counter(s)
ans=sum(i*(i-1)//2 for i in s_cnt.values())
print(ans)

Submission status: Accepted

Solution code:
N = input()
sum = 0
mydict = {}
for i in range(int(N)):
    s = list()
    st2 = ""
    st = input()
    for i in range(10):
        s.append(st[i])
    s.sort()
    if st2.join(s) in mydict.keys():
        mydict[st2.join(s)] += 1
        sum += mydict[st2.join(s)]
    else:
        mydict[st2.join(s)] = 0

print(sum)

Submission status: Accepted

Solution code:
def sort_str(s):
    l = list(s)
    l.sort()
    return ''.join(l)

n = int(input())
counts = dict()
for _ in range(n):
    s = input()
    s = sort_str(s)
    counts.setdefault(s, 0)
    counts[s] += 1
ans = 0
for c in counts.values():
    ans += c * (c - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [input() for k in range(N)]
s = [''.join(sorted(list(s_element))) for s_element in s]
memory = {}
result = 0
for s_element in s:
    if s_element not in memory:
        memory[s_element] = 1
    else:
        result += memory[s_element]
        memory[s_element] += 1
print(result)

Submission status: Accepted

Solution code:
import collections
import sys
from scipy.misc import comb


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += str(v)
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c = [count_abc(st) for st in s]
  
  c_dict = collections.Counter(s_c)
  
  ans = 0
  
  for v in c_dict.values():
    if v > 1:
      ans += comb(v, 2, exact=True)
  
  print(ans)

  
if __name__ == "__main__":
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding: utf-8

from collections import Counter
N = int(input())

s_list = []
for i in range(N):
    input_string = list(input())
    input_string.sort()
    input_string = "".join(input_string)
    s_list.append(input_string)

s_list.sort()

list_counter = Counter(s_list)

count = 0
for key in list_counter.keys():
    tmp_count = list_counter[key]
    if tmp_count < 2:
        pass
    elif tmp_count == 2:
        count += 1
    else:
        permutations = tmp_count * (tmp_count - 1)
        combination = permutations/2
        count += int(combination)

print(int(count))

Submission status: Accepted

Solution code:
N = int(input()) 
s = [input() for i in range(N)]
LIS=[]
for i in range(N):
  LIS.append(''.join(sorted(s[i])))
LIS.sort()
n=0
prestr=LIS[0]
count=1
for st in LIS[1:]:
  if st==prestr:
    n+=count
    count+=1
  else:
    count=1
    prestr=st
print(int(n))

Submission status: Accepted

Solution code:
import math
import collections

n=int(input())
a=[list(input()) for i in range(n)]
b=[str(sorted(list(i))) for i in a]
count=list(collections.Counter(b).values())
count=[i for i in count if i>1]
print(int(sum([math.factorial(x)/(math.factorial(x-2)*2) for x in count])))

Submission status: Accepted

Solution code:
N=int(input())
s=[]
for k in range(N):
    s.append([None]*10)
    l=input()
    for j in range(10):
        s[k][j]=l[j]
    s[k].sort()
s.sort()
a=0
r=0
for i in range(N-1):
    if s[i]==s[i+1]:
        r+=1
    elif r!=0:
        a+=r*(r+1)//2
        r=0
a+=r*(r+1)//2
print(a)

Submission status: Accepted

Solution code:
n = int(input())
s = [input() for i in range(n)]
t = {}
cnt = 0
for i in s:
    tmp = "".join(sorted(list(i)))
    if tmp in t:
        t[tmp] += 1
        cnt += t[tmp]
    else:
        t[tmp] = 0
    
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    cnt = {}
    ans = 0
    for _ in range(N):
        s = input()
        ss = "".join(sorted(list(s)))
        if ss not in cnt:
            cnt[ss] = 0
        ans += cnt[ss]
        cnt[ss] += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#35 ABC137C
n=int(input())
s=["".join(sorted(list(input()))) for _ in range(n)]
from collections import Counter
c=Counter(s)
x=list(c.values())
res=0
for t in x:
	res+=t*(t-1)//2
print(res)

Submission status: Accepted

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

d = {}
ans = 0
for s in S:
    s = "".join(sorted(s))
    if s in d:
        ans += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = []
cnt = {}
ans = 0
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  s_ = "".join(s_)
  if s_ in cnt:
    ans += cnt[s_]
    cnt[s_] += 1
  else:
    cnt[s_] = 1

print(ans)

Submission status: Accepted

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

d = {}
for s in S:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for v in d.values():
    if v > 1:
        ans += v * (v - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A=[]
count=1
ss=0
for i in range(0,N):
    A.append(list(input()))
    A[i].sort()
A.sort()
A.append('0')
for j in range(1,N+1):
    if A[j-1]==A[j]:
        count+=1
        j+=1
    else:
        ss+=count*(count-1)/2
        count = 1
        j+=1

print(int(ss))

Submission status: Accepted

Solution code:
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for s in A:
    if s in D:
        count+=D[s]
        D[s]+=1
    else:
        D[s]=1
print(count)

Submission status: Accepted

Solution code:
import collections
N = int(input())
s = []
for i in range(N):
  word = input()
  chars = []
  sortedWord = ''

  for j in range(10):
    chars.append(word[j])
    chars.sort()

  #print(chars)
  
  for j in range(10):
    sortedWord += chars[j]

  #print(sortedWord)

  s.append(sortedWord)

c = collections.Counter(s)

sum = 0
for value in c.values():
  sum += (value * (value-1) / 2)

print(int(sum))

Submission status: Accepted

Solution code:
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


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

d = {}
for s in S:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for v in d.values():
    if v > 1:
        ans += cmb(v, 2)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [list(input()) for _ in range(N)]
S = []
for i in range(N):
    temp = "".join(sorted(s[i]))
    S.append(temp)

D = {}
cnt = 0
for str in S:
    if str in D:
        cnt += D[str]
        D[str] += 1
    else:
        D[str] = 1

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
ss = []
for _ in range(N):
    ss.append(''.join(sorted(input())))
d = {}
for s in ss:
    if s not in d:
        d[s] = 1
    else:
        d[s] += 1
print(sum(int((v * (v - 1)) / 2) for v in d.values() if v > 1))

Submission status: Accepted

Solution code:
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for s in A:
    if s in D:
        count+=D[s]
        D[s]+=1
    else:
        D[s]=1
print(count)

Submission status: Accepted

Solution code:
#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=0
dic={}
for l in range(N):
    s[l].sort()
    if dic.get(str(s[l]))==None:
        dic[str(s[l])]=0
    else:
        dic[str(s[l])]+=1
        total+=int(dic[str(s[l])])
print(total)

Submission status: Accepted

Solution code:
#Coding:Utf-8

N=int(input())
s=[list(input()) for i in range(N)]
total=num=0
dic={}
for l in range(N):
    s[l].sort()
    if dic.get(str(s[l]))==None:
        dic[str(s[l])]=0
    else:
        dic[str(s[l])]+=1
        total+=int(dic[str(s[l])])
print(total)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

prestr = mojiretues[0]
cnt = 1
ans = 0
for s in mojiretues[1:]:
	if prestr == s:
		ans += cnt
		cnt += 1
	else:
		prestr = s
		cnt = 1

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
S = ["".join(sorted(input())) for _ in range(0, N)]
d={}
result=0
for s in S:
    if s in d.keys():
        result+=d[s]
        d[s]+=1
    else:
        d[s]=1
print(result)

Submission status: Accepted

Solution code:
N = int(input())
wordl = {}
ans = 0

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    if w2 in wordl:
        ans += wordl[w2]
        wordl[w2] += 1
    else:
        wordl[w2] = 1

print(ans)

'''
#アルゴリズムはあってるがLTE
N = int(input())
wordl = []

for i in range(N):
    w = input()
    wl = []
    for j in range(10):
        wl.append(w[j])
    wl.sort()
    w2 = ' '
    for p in range(10):
        w2 += wl[p]
    wordl.append(w2)
wordl.sort()
#print(wordl)

ans = 0
for k in range(N):
    for q in range(k+1,N):
        if wordl[k] == wordl[q]:
            ans += 1
        else:
            break

print(ans)
'''

Submission status: Accepted

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(0, N)]
d = {}
result = 0
for s in S:
    if s in d.keys():
        result += d[s]
        d[s] += 1
    else:
        d[s] = 1
print(result)

Submission status: Accepted

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

for i in range(N):
  s = input()
  sorted_s = "".join(sorted(s))
  dct[sorted_s] += 1

ans = 0
for k, v in dct.items():
  ans += v*(v-1)//2

print(ans)

Submission status: Accepted

Solution code:
import collections
N = int(input())
s_dict = {}
count = 0
for i in range(N):
    s=sorted(input())
    s = ''.join(s)
    if s in s_dict:
        s_dict[s] += 1
        count += s_dict[s]
    else:
        s_dict[s] = 0
print(count)

Submission status: Accepted

Solution code:
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

lis=[]
for i in range(n):
    lis.append(ans[i][0])
    for j in range(9):
        lis[i]+=ans[i][j+1]

a=0
#print(lis)

dic={lis[0]:1}
for i in range(n-1):
    if lis[i+1] in dic.keys():
        a+=dic[lis[i+1]]
        dic[lis[i+1]]+=1
    else:
        dic[lis[i+1]]=1

print(int(a))

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
ans = 0
spc = defaultdict(int)

for _ in range(n):
    s = "".join(sorted(list(str(input()))))
    if s in spc:
        ans += spc[s]
        spc[s] += 1
    else:
        spc[s] = 1

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
import collections
from operator import mul
from functools import reduce

def input():
    return sys.stdin.readline().rstrip()
    
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

N = int(input())
a = [''.join(sorted(input())) for _ in range(N)]
c = collections.Counter(a)
c_array = list(filter(lambda x: x >= 2, c.values()))
ctr = 0

for i in c_array:
    ctr += cmb(i, 2)
print(ctr)

Submission status: Accepted

Solution code:
import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":59, "r":61, "s":67, "t":71, "u":73, "v":79, "w":83, "x":89, "y":97, "z":1}

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

for s in S:
    s1 = [D[x] for x in s]
    s2 = np.prod(s1)

    if s2 in Sdict:
        n_anagram = n_anagram + Sdict[s2]
        Sdict[s2] += 1
    else:
        Sdict[s2] = 1
   
print(n_anagram)

Submission status: Accepted

Solution code:
N=int(input())
a=[]
for i in range(N):
    s=list(str(input()))
    a.append(tuple(sorted(s)))

a=sorted(a)

ans=[]
count=0
for i in range(1,N):
    if a[i]==a[i-1]:
        count +=1
    elif a[i]!=a[i-1] and count >=1:
        ans.append(count)
        count=0

if count>=1:
    ans.append(count)


ans2=0
for i in ans:
    ans2 += (i+1)*i//2

print(ans2)

Submission status: Accepted

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict


dct = defaultdict(lambda:0)

N = int(input())
for _ in range(N):
  s = "".join(sorted(str(input())))
  dct[s] += 1

ans = 0
for k in dct:
  if dct[k] > 1:
    ans += dct[k]*(dct[k]-1)//2
print(ans)

Submission status: Accepted

Solution code:
import math
num = int(input())
words = {}

for i in range(num):
  a = str(sorted(list(input())))
  
  if a in words:
    words[a] += 1
  else:
  	words[a] = 1

points = list(words.values())
sum = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(len(points)):
  if points[i] > 1:
  	sum += combinations_count(points[i], 2)
print(sum)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
dict_word = {}
for i in range(N):
  sorted_word = str(''.join(sorted(list(input()))))
  try:
    ans += dict_word[sorted_word]
    dict_word[sorted_word] += 1
  except:
    dict_word[sorted_word] = 1
print(ans)

Submission status: Accepted

Solution code:
import math
 
N = int(input())

b =[""]*N
 
cn =ord("a")
 
for i in range(N):
    s = list(input())
    s.sort()
    b[i] ="".join(s)
 
b.sort()
c = 0
ans =0
 
for i in range(N-1):
    if b[i]==b[i+1]:
        c +=1
    else:
        if c !=0:
            ans=ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
            c = 0
 
 
if c !=0:
    ans = ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
    
 
print(int(ans))

Submission status: Accepted

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
S = [stdin.readline().rstrip() for _ in range(N)]
count = {}

for s in S:
    s = ''.join(sorted(s))
    if s not in count:
        count[s] = 1
    else:
        count[s] += 1

ans = 0
for c in count:
    if count[c] > 1:
        ans += count[c] * (count[c] - 1) // 2

print(ans)

Submission status: Accepted

Solution code:
def sum_list(i):
    return int((i*(i+1))/2)

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

ls.sort()
ans = 0
count = 0

for i in range(len(ls)):
    if (ls[i] == ls[i+1]):
        count += 1
    else:
        ans += sum_list(count)
        count = 0
    if (i == n-2):
      ans += sum_list(count)
      break

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
dict = {}
for _ in range(n):
  	#文字列をキーとする辞書型に出現回数を保持する
    s = str(''.join(sorted(list(input()))))
    try:
        ans += dict[s]
        dict[s] += 1
    except:
        dict[s] = 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
s=sorted([sorted(map(str,input())) for _ in [0]*n])+[[]]
c=0
i=0
while i<n:
    j=0
    while s[i+j+1]==s[i]:j+=1
    c+=j*(j+1)//2
    i+=j+1
print(c)

Submission status: Accepted

Solution code:
n=int(input())
d={}
ans=0
for i in range(n):
    s=sorted(list(input()))
    e=""
    for v in range(10):
        e+=s[v]
    if e in d:
        d[e]+=1
    else:
        d[e]=1
for _ in d:
    if d[_]==1:
        pass
    else:
        ans+=d[_]*(d[_]-1)//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
dict = {}
for _ in range(n):
    s = str(''.join(sorted(list(input()))))
    try:
        ans += dict[s]
        dict[s] += 1
    except:
        dict[s] = 1
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict

strings = defaultdict(int)
n = int(input())

res = 0

for _ in  range(n):
    temp = ''.join(sorted(list(input())))
    strings[temp] += 1
    res += strings[temp] - 1

print(res)

Submission status: Accepted

Solution code:
def nck(n):
    ret = 1
    for i in range(2):
        ret *= (n - i)
    return ret//2

N = int(input())
S = {}
for i in range(N):
    s = str(sorted(input()))
    if s not in S.keys():
        S[s] = 0
    S[s] += 1
ans = 0
for key in S.keys():
    if S[key] > 1:
        ans += nck(S[key])
print(ans)

Submission status: Accepted

Solution code:
import collections
n = int(input())
strs = ["".join(sorted(input())) for _ in range(n)]
d = collections.Counter(strs)
ans=0
for x in d.values():
  ans += x*(x-1)/2

print(int(ans))

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    S = sorted(list(sorted(input()) for _ in range(N)))
    count = 0
    S_dict = {}
    for i in range(N):
        s = str(S[i])
        if s in S_dict:
            tmp =  S_dict[s]
            S_dict[s] = tmp + 1
            count = count + tmp
        else:
            S_dict.setdefault(s,1)
    print(count)

    
resolve()

Submission status: Accepted

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

from collections import Counter
counter = Counter(s)

print(sum([x*(x-1)//2 for x in counter.values()]))

Submission status: Accepted

Solution code:
from math import factorial
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    # 辞書にキーが存在しなければキー追加
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
count = 0
# 辞書から値だけ取り出す
for d in dic.values():
    # dまでの値の組み合わせを合計する
    if d > 2:
        count += factorial(d) // 2 // factorial(d - 2)
    elif d == 2:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n = int(input())
strings = []
for i in range(n):
    s = input()
    s10 = []
    for j in range(10):
        s10.append(s[j])
        s10.sort()
    s = ''
    for j in range(10):
        s += s10[j]
    strings.append(s)

set_strings = dict()

for i in range(n):
    if not strings[i] in set_strings.keys():
        set_strings[strings[i]] = 1
    else:
        set_strings[strings[i]] += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

dic = {}
cnt = 0
for i in range(N):
    if s[i] in dic:
        cnt += dic[s[i]]
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1
print(cnt)

Submission status: Accepted

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

count = 0
dic1 = {}
# print(s)
for i in range(n):
    # print(s[i])
    so = ''.join(s[i])
    # print(so)
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    # print(count, dic1)
print(count)

Submission status: Accepted

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()
    a = "".join(a)
    if a in d:
        ans+= d[a]
        d[a] +=1
    else:
        d[a] = 1
print(ans)

Submission status: Accepted

Solution code:
def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    res = [0] * len(temp)
    cnt = 0
    for x in array:
        res[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ''.join([str(i) for i in res])

N = int(input())
s = [''.join(f(input())) for i in range(N)]

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

cnt = 0
for v in dic.values():
    cnt += v * (v - 1) // 2

print(cnt)

Submission status: Accepted

Solution code:
def f(array):
    temp = 'abcdefghijklmnopqrstuvwxyz'
    ret = [0] * len(temp)
    cnt = 0
    for x in array:
        ret[temp.index(x)] += 1
        cnt += 1
        if cnt == 10:
            break
    return ret

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

dic = {}
for i in range(N):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1

cnt = 0
for v in dic.values():
    cnt += v * (v - 1) // 2

print(cnt)

Submission status: Accepted

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

count = 0
dic1 = {}
#print(s)
for i in range(n):
    #print(s[i])
    so = ''.join(s[i])
    if so in dic1:
        count += dic1[so]
        dic1[so] += 1
    else:
        dic1[so] = 1
    #print(count, dic1)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
pair = 0

for i in range(n):
  line = "".join(sorted(input()))
  if line in dic:
    dic[line] += 1
  else:
    dic[line] = 1
  
for value in dic.values():
  pair += (value * (value-1)) / 2
  
print(int(pair))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from collections import defaultdict

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

d = defaultdict(lambda: 0)
for s in s_l:
        d[s] += 1

for v in d.values():
        cnt += int(v*(v-1)/2)
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
s = [0]*N
p = {}
ans = 0
for i in range(N):
    s[i] = "".join(sorted(input()))
    if s[i] in p:
        ans += p[s[i]]
        p[s[i]] += 1
    else:
        p[s[i]] = 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
Ss = {}
for i in range(N):
    s = ''.join(sorted(list(input().rstrip("\n"))))
    if s in Ss:
        Ss[s] += 1
    else:
        Ss[s] = 1

c = 0
for s in Ss.values():
    c += (s - 1) * s >> 1

print(c)

Submission status: Accepted

Solution code:
n = int(input())
sl ={}
ans = 0
for i in range(n):
    s = ''.join(sorted(input()))
    if s in sl:
        sl[s] +=1
    else:
        sl[s] =1
for i in sl.values():
    ans += i*(i-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip("\n"))) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c // 2

print(Su)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c // 2

print(Su)

Submission status: Accepted

Solution code:
''' بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ '''
gi = lambda : list(map(int,input().split()))
n, = gi()
ans = 0
mp = {}
while n:
	s = "".join(sorted(list(input())))
	if s in mp:
		ans += mp[s]
		mp[s] += 1
	else:
		mp[s] = 1
	n -= 1
print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
N = int(input())
Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

import collections

Co = collections.Counter(Ss)
Su = 0
for _, c in Co.most_common():
    if c < 2:
        break
    Su += (c - 1) * c

print(Su // 2)

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    N = int(input())
    Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

    import collections
    Co = collections.Counter(Ss)
    Su = 0
    for _, c in Co.most_common():
        if c < 2:
            break
        Su += (c - 1) * c

    print(Su // 2)

if __name__ == '__main__':
    resolve()