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:
import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

def get_runlength(s): # ex) s = 'RRLLLLRLRLRLRR'
    ret = []
    count = 1
    for i in range(len(s)):
        if i == len(s) - 1:
            ret.append((s[i], count))
            continue
        if s[i] == s[i + 1]:
            count += 1
        else:
            ret.append((s[i], count))
            count = 1
    return ret

n = int(input())
dic = {}
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    try:
        dic[sin] += 1
    except:
        dic[sin] = 1

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

Submission status: Accepted

Solution code:
n=int(input())
a = [input() for i in range(n)]
new_a = [0]*len(a)
cnt = 1
ans = 0
for i in range(len(a)):
    new_a[i] = sorted(a[i]) 
b = sorted(new_a)
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt - 1)/2 #組み合わせ(cnt C 2)
        cnt = 1
ans += cnt*(cnt - 1)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
sorted_word = {}

for i in range(n):
  word = ''.join(sorted(input()))
  sorted_word.setdefault(word, 0)
  sorted_word[word] += 1

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

print(sum(map(pair_num, sorted_word.values())))

Submission status: Accepted

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 += word_dict[word]
            word_dict[word] += 1

    print(count)

if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = n * (n-1) /2
    return int(a) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Submission status: Accepted

Solution code:
import sys

n = int(input())

d = {}
cnt = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]
"""
c = 0
c1 =  0
p = sorted(q)

for i in range(n):
	if p[i] == p[i+1]:
		c+=1
	else:
		
		if c>0:
			for j in range(c+1):
				c1+=j
				
		c=0
"""
count_by_kw = Counter()

for i in range(n):
	count_by_kw[q[i]] += 1
ans = 0
for kw, count in count_by_kw.most_common():

	ans += count*(count-1) /2

print(int(ans))

Submission status: Accepted

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

dictS = {}
for new_st in s:
    new_st = "".join(sorted([x for x in new_st]))
    if new_st in dictS:
        dictS[new_st] += 1
    else:
        dictS[new_st] = 1

ans = sum([int(x * (x - 1) / 2) for x in dictS.values()])
print(ans)

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())
a = [''.join(sorted(input())) for _ in range(n)]
a.sort()
cnt = 0

# print(a)
cntsub = 1
for i in range(len(a) - 1):
    if a[i] == a[i + 1]:
        cntsub += 1
    elif cntsub > 1:
        # print(cntsub)
        cnt += int(cmb(cntsub, 2))
        cntsub = 1

if cntsub > 1:
    # print(cntsub)
    cnt += int(cmb(cntsub, 2))
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def cmb(n,r):  #nCr = n!/(n-r)!r!
    retVal = 1
    for i in range(n-r+1,n+1):
        retVal *= i
    for i in range(2,r+1):
        retVal //= i
    return retVal
def main():
    from collections import defaultdict
    N = int(input())
    d = defaultdict(lambda:0)
    base = ord('a')
    ans = 0
    for _ in range(N):
        s = input().strip() 
        s = ''.join(sorted(s))
        ans += d[s]
        d[s] += 1

    
    print(ans)

        

    





    pass
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
s_dict = {}
for i in range(N):
  s = "".join(sorted(input()))
  if s in s_dict:
    s_dict[s] += 1
  else:
    s_dict[s] = 1
result = sum(v * (v - 1) // 2 for v in s_dict.values())
print(result)

Submission status: Accepted

Solution code:
N = int(input())
#S = [input() for i in range(N)]
S=[]
ans_dic={}
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    temp = ''.join(temp)
    #S.append(''.join(temp))
    #alpha_dic[temp[0]].append(i) 
    if temp in ans_dic:
        ans_dic[temp] += 1
    else:
        ans_dic[temp] = 1
    
for key,value in ans_dic.items():
    ans += value*(value-1)/2

print(round(ans))

Submission status: Accepted

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(int(ans))

Submission status: Accepted

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 m.keys():
        count += cmb( m[k] )


print(count)

Submission status: Accepted

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(int(counts))
"""
values, counts = zip(*cc.most_common())
if counts != 1:
  print(counts)
 """

Submission status: Accepted

Solution code:
n = int(input())
sraw = dict()

for nn in range(n):
    i = "".join(sorted(input()))
    if i in sraw:
        sraw[i] += 1
    else:
        sraw[i] = 1

ans = 0

for ss in sraw:
    ans += round(sraw[ss]*(sraw[ss]-1)/2)

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n = int(input())
s = Counter(["".join(sorted(input())) for _ in [0]*n]).values()

cnt = 0

for i in s:
    cnt += i*(i-1)//2

print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
i = 0
sortedSet = {}
while i < n:
    temp = ''.join(sorted(input()))

    if temp in sortedSet:
        sortedSet[temp]+=1
    else:
        sortedSet[temp]=1
    i += 1

result = 0
for v in sortedSet.values():
    result = int(result + v*(v-1)/2)

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    d = Counter()
    for s in S:
        d[tuple(sorted(s))] += 1
    return reduce(lambda x, y: x + (y*(y-1))//2, d.values(), 0)


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = sys.stdout.write
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = True
def cmb(n,r):  #nCr = n!/(n-r)!r!
    retVal = 1
    for i in range(n-r+1,n+1):
        retVal *= i
    for i in range(2,r+1):
        retVal //= i
    return retVal
def main():
    from collections import defaultdict
    N = int(input())
    d = defaultdict(lambda:0)
    base = ord('a')
    ans = 0
    for _ in range(N):
        s = input().strip()
        num = 0
        for c in s:
            num += 26 ** (ord(c) - base)
        ans += d[num]
        d[num] += 1

    
    print(ans)

        

    





    pass
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ln = []
cnt = 1
ans = 0

for i in range(n):
    ln.append(''.join(sorted(input())))

ln.sort()

for i in range(len(ln)-1):
    if ln[i] == ln[i+1]:
        cnt += 1
    else:
        ans += cnt*(cnt - 1)/2
        cnt = 1

ans += cnt*(cnt - 1)/2

print(int(ans))

Submission status: Accepted

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

mp = {}
for c in s:
    if c in mp:
        mp[c] += 1
    else:
        mp[c] = 1

ans = 0
for key in mp.keys():
    ans += mp[key]*(mp[key]-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result


from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
d = defaultdict(int)
for i in range(N):
    S[i] = sorted(S[i])
    d["".join(S[i])] += 1
ans = 0
for i in d.values():
    if i >= 2:
        ans += cmb(i, 2)

print(ans)

Submission status: Accepted

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 += int((v*(v-1))/2)
	
print(ans)

Submission status: Accepted

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+=c*(c-1)//2
    c=1
  if i==a-2:
    sum+=c*(c-1)//2
    
print(sum)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
counter = Counter()
for i in range(N):
    counter[tuple(sorted(input()))] += 1

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

print(int(res))

Submission status: Accepted

Solution code:

def combinatnion(num, cmb):
    nmrtr = 1
    dnmntr = 1

    for i in range(cmb):
        nmrtr = nmrtr * (num - i)
        dnmntr = dnmntr * (i + 1)

    ans = int(nmrtr/dnmntr)
    return ans

n = int(input())

inputList=[]
for i in range(n):
    line = input()
    inputList.append(line)

# print(inputList)

sortedList = []
dic = {}
for i in range(n):
    tmpList = list(inputList[i])
    tmpList.sort()
    tmpword = "".join(tmpList)

    if tmpword in dic:
        dic[tmpword] = dic[tmpword] + 1
    else:
        dic[tmpword] = 1

    # print(dic)

# print(tmpword)

cnt = 0
for val in dic.values():
    if val != 1:
        cnt += combinatnion(val, 2)

print(cnt)

Submission status: Accepted

Solution code:
N = input().split()
N = int(N[0])
d={}
score = 0

for i in range(N):
  S = input()
  S = sorted(S)
  S = ''.join(S)
  
  if S in d:
    score += d[S]
    d[S] +=1
  else:
    d[S] = 1
    
print(score)

Submission status: Accepted

Solution code:
from collections import defaultdict

n = int(input())
d = defaultdict(int)
ans = 0
for _ in range(n):
    s = input()
    s = str(sorted(s))
    ans += d[s]
    d[s] += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ans = 0
s = {}
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	tmp.sort()
	stmp = ''.join(tmp)
	if stmp in s and s[stmp] > 0:
		ans += s[stmp]
		s[stmp] = s[stmp]+1
	else:
		s[stmp] = 1
print(ans)

Submission status: Accepted

Solution code:

N = int(input())

cnt_dict = {}

for i in range(N):
    s_list = list(input())
    s_list.sort()
    s_str = "".join(s_list)
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += cnt * (cnt - 1) // 2

print(total)

Submission status: Accepted

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

ans = 0
s_dict = {}
for i in s_li :
    s_i = [ch for ch in i]
    s_i.sort()
    s_i = "".join(s_i)
    if s_i in s_dict :
        ans += s_dict[s_i]
        s_dict[s_i] += 1
    else :
        s_dict[s_i] = 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
dic={}
ans=0
for _ in range(n):
    s=input()
    s=sorted(s)
    s="".join(s)

    if s in dic:
        ans+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(ans)

Submission status: Accepted

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

from collections import Counter
counter = Counter(s)
ans = sum(n*(n-1)//2 for n in counter.values())
print(ans)

Submission status: Accepted

Solution code:
import sys,math,collections
N = int(input())
s = []
ans = 0
for i in range(N):
    li_tmp = list(input())
    li_tmp.sort()
    st = "".join(li_tmp)
    s.append(st)
cnt = collections.Counter(s)
for i in cnt.values():
    if i != 1:
        ans += i*(i-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N = int(input())
H = defaultdict(int)
for _ in range(N):
  S = input()
  H[''.join(sorted([s for s in S]))] += 1
cnt = 0
for v in H.values():
  cnt += v * (v - 1) // 2
print(cnt)

Submission status: Accepted

Solution code:
n = int(input())

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

s.sort()

i = 0
j = 0
ans = 0
while i < n:
    while j < n and s[i] == s[j]:
        j += 1
    ans += (j-i) * (j-i-1) // 2
    i = j

print(ans)

Submission status: Accepted

Solution code:

N=int(input())
S=[]
total=0

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Submission status: Accepted

Solution code:
import math

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

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
s = list([input() for i in range(n)])
q = [''.join(sorted(x)) for x in s]

c = 0
c1 =  0
p = sorted(q)
p.append("a")

for i in range(n):
	if p[i] == p[i+1]:
		c+=1
	else:
		
		if c>0:
			for j in range(c+1):
				c1+=j
				
		c=0
print(c1)

Submission status: Accepted

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

dic = {}
cnt = 0

for moji in moji_lst:
    x = ''.join(sorted(moji))

    if x in dic:
        dic[x] += 1
        cnt += dic[x]
    else:
        dic[x] = 0


print(cnt)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
d = {}
ans = 0
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
for string in s:
    if string in d:
        ans += d[string]
        d[string] += 1
    else:
        d[string] = 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
 
N = int(input())
 
ans = {}
answer = 0
for _ in range(N):
    s = "".join(sorted(input()))
 
    if s not in ans:
        ans[s] = 0
 
    else:
        ans[s] += 1
        answer += ans[s]
 
print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
D = {}
SUM = 0

for n in range(N):
  s = input()
  l = sorted(s)
  l = ''.join(l)
  
  if l in D:
    SUM = SUM + D[l]
    D[l] = D[l] + 1
  else:
    D[l] = 1
  
print(SUM)

Submission status: Accepted

Solution code:
n=int(input())
stats=[]
res={}

for i in range(n):
    s=list(input())
    s.sort()
    s="".join(s)
    if s in res:
        res[s]+=1
    else:
        res[s]=1

ans=0
for i in res:
    ans+=res[i]*(res[i]-1)//2
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = dict()
    pairs = 0
    for i in s:
        i = ''.join(sorted(list(i)))

        if i in ans:
            pairs += ans[i]
            ans[i] += 1
            continue

        ans[i] = 1

    print(pairs)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

dic = {}

for i in range(N):
	s = input()
	s = ''.join(sorted(s))
	if s in dic:
		dic[s] += int((-1+(1+8*(dic[s]))**0.5)/2)+1
	else:
		dic[s] = 0
print(sum(dic.values()))

Submission status: Accepted

Solution code:
from collections import Counter
print(sum((c * (c-1)) // 2 for c in Counter("".join(sorted(input().strip())) for i in range(int(input()))).values()))

Submission status: Accepted

Solution code:
import collections

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

counter = collections.Counter(s)

ans = 0
for i in counter.values():
   if i > 0:
        ans += i * (i - 1) // 2

print(ans)

Submission status: Accepted

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] = 0

print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

def main():
    N = int(input())
    counter = Counter()
    for i in range(N):
        k = "".join(sorted(input().strip()))
        counter[k] += 1
    answer = 0
    for k, c in counter.items():
        answer += (c * (c-1)) // 2
    print(answer)

def main2():
    N = int(input())
    counter = Counter("".join(sorted(input().strip())) for i in range(N))
    print(sum((c * (c-1)) // 2 for c in counter.values()))

def main3():
    print(sum((c * (c-1)) // 2 for c in Counter("".join(sorted(input().strip())) for i in range(int(input()))).values()))


main3()

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
dictionary = {}
for i in range(N):
	s = input()
	sorted_s = "".join(sorted([char for char in s]))
	if not sorted_s in dictionary:
		dictionary[sorted_s] = 0
	ans += dictionary[sorted_s]
	dictionary[sorted_s] += 1
print(ans)

Submission status: Accepted

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(sum(map(lambda n: n*(n-1)//2,list(dic.values()))))

Submission status: Accepted

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

N = int(input())

dd=defaultdict(int)

Sread = sys.stdin.read()


for s in Sread.split('\n'):
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    #print('-', s)
    dd[s]+=1

#FAC = {}
#FAC[1] = 1
#
#for i in range(2,N+1):
#    FAC[i] = FAC[i-1]*i
    
count = 0

for k in dd:
    s_counts = dd[k]
    if s_counts > 1:
        #count += FAC[s_counts]//2
        count += comb(s_counts, 2, exact=True)

print(count)

Submission status: Accepted

Solution code:
import sys 
from collections import Counter
from math import factorial

def combinations_count(n, r):
  return factorial(n) // (factorial(n - r) * factorial(r))
 
def main():
  inpurt = sys.stdin.readline
  N = int(input())
  texts = [''.join(sorted(list(input().rstrip()))) for _ in range(N)]
  c = Counter(texts)
  cnt = 0
  for t in c.values():
    if t > 1:
      cnt += combinations_count(t, 2)
  print(cnt)
 
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())

# check = []
# ans = {}
# answer = 0
# for _ in range(N):
#     s = Counter(input())
#     if s not in check:
#         check.append(s)
#         ans[str(sorted(s.items(), key=lambda x:x[0]))] = 0
#
#     else:
#         ans[str(sorted(s.items(), key=lambda x:x[0]))] += 1
#         answer += ans[str(sorted(s.items(), key=lambda x:x[0]))]
#
# print(answer)

ans = {}
answer = 0
for _ in range(N):
    s = "".join(sorted(input()))

    if s not in ans:
        ans[s] = 0

    else:
        ans[s] += 1
        answer += ans[s]

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
ws = [list(input()) for _ in range(n)]
 
def sort_l(l):
    l.sort()
    return l
ws = list(map(sort_l, ws))
ws.sort()
 
i = 0
j = 0
r = 0
ans = 0
while(i<n-1):
    i += 1
    if ws[i] == ws[j]:
        r += 1
    else:
        ans += r * (r+1) // 2
        r = 0
        j = i
ans += r * (r+1) // 2
 
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import sys

input = sys.stdin.readline
n = int(input())
str_list = [''.join(sorted(input().rstrip())) for i in range(n)]
ans = 0
count_list = list(Counter(str_list).values())
for i in count_list:
  sum = 0
  for j in range(int(i)):
    sum += j
  ans +=sum
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ss = {}
ht = []
ans = 0

for i in range(N):
    s = ''.join(sorted(input()))
    if not s in ss.keys():
        ss[s] = 1
    else:
        ss[s] += 1
        
for i in ss.keys():
    if ss[i] > 1:
        ans += int((ss[i]*(ss[i]-1))/2)

print(ans)

Submission status: Accepted

Solution code:
N = int(input())
sets = []

cnt = 0
s2c = {} #counter

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

Submission status: Accepted

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

import collections
import math

c = collections.Counter(S)
ans = 0
for i in c.values():
    if i == 1:
      continue
    else:
      ans += i*(i-1)//2
print(int(ans))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    count = 0
    count_dict = {}
    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in count_dict:
            count += count_dict[input_data]
            count_dict[input_data] += 1
        else:
            count_dict[input_data] = 1
    print(count)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

nlist=[""]*N
d={}
for i in range(N):
    t=str(input())
    t=''.join(sorted(t))
    if d.get(t,None)==None:
        d[t]=1
    else:
        d[t]+=1 
ans=0

#print(d.keys(),d.values())
for i in d.values():
    ans += i*(i-1)/2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
strings = [''.join(sorted(list(input()))) for i in range(n)]
dictionary = {}
ans = 0
for i in range(n) :
    if strings[i] in dictionary :
        ans += dictionary[strings[i]]
        dictionary[strings[i]] += 1
    else :
        dictionary[strings[i]] = 1
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
dic={}
ans=0
for _ in range(n):
  s=input()
  s=str(sorted(s))
  if s not in dic:
    dic[s]=1
  else:
    ans+=dic[s]    
    dic[s]+=1
print(ans)

Submission status: Accepted

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

def sort_l(l):
    l.sort()
    return l
ws = list(map(sort_l, ws))
ws.sort()

i = 0
j = 0
r = 0
ans = 0
while(i<n-1):
    i += 1
    if ws[i] == ws[j]:
        r += 1
    else:
        ans += r * (r+1) // 2
        r = 0
        j = i
ans += r * (r+1) // 2

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

S, ans = {}, 0
for i in range(N):
    s = ''.join(sorted(list(input())))
    S[s] = S[s] + 1 if s in S else 1
    ans += S[s] - 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
 
i=0
sortedSet={}
while i<N:
  temp=''.join(sorted(input()))
  
  if temp in sortedSet:
    sortedSet[temp]=sortedSet[temp]+1
  else:
    sortedSet[temp]=1
  i=i+1

  
result=0
for v in sortedSet.values():
  result=int(result+v*(v-1)/2)
 
print(result)

Submission status: Accepted

Solution code:
n=int(input())
c=[''.join(sorted(input())) for _ in range(n)]
an=0
d={}

for i in c:
    if i in d:
        an += d[i]
        d[i]+=1
    else:
        d[i]=1

print(an)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

lst = []
for _ in range(N):
    tmp = list(input())
    tmp.sort()
    lst.append(tmp)
lst.sort()
tmp = lst[0]
count = 1
ans = 0
for i in range(1, N):
    if tmp == lst[i]:
        count += 1
    else:
        ans = ans + (count * (count - 1))//2
        count = 1
        tmp = lst[i]
ans = ans + (count * (count - 1))//2
print (ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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:
    count += d[s]
    d[s] += 1
  else:
    d[s] = 1
print(count)

Submission status: Accepted

Solution code:
from collections import Counter
N = int(input())
S = [input() for i in range(N)]
counter = Counter()
ans = 0
for s in S:
    a = ''.join(sorted(list(s)))
    if a in counter:
        ans += counter[a]
    counter[a] += 1
print(ans)