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.

Solution (Python):
import math
def is_anagram(string1, string2):
  for a in string1:
    if a not in string2:
      return False
    string2 = string2.replace(a, "", 1)
  if len(string2) == 0:
    return True
  else:
    return False

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())
anagrams = {}
for i in range(N):
  string = ''.join(sorted(input()))
  if string in anagrams:
    anagrams[string] += 1
  else:
    anagrams[string] = 0

ans = 0
for anagram_num in anagrams.values():
  if anagram_num> 0:
    ans += int(cmb(anagram_num+1,2)) 
print(ans)

Solution (Python):
import collections

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

lists2 = ["".join(sorted(i)) for i in lists]
l = collections.Counter(lists2)
c = l.values()
 
print(int(sum([i * (i - 1)/ 2 for i in c])))

Solution (Python):
from collections import Counter

N = int(input())
strings = [str(sorted(Counter(input()).items())) for _ in range(N)]

counts = Counter(strings)
ans = 0
for i in counts.values():
    ans += sum(range(i))

print(ans)

Solution (Python):
import math

n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
ren = 0;
for i in range(1,n) :
	ok = 1;
	if s[i-1]==s[i]:
		ans += 1;
		ans += ren;
		ren += 1;
	else :
		ren = 0;

print(ans);

Solution (Python):

n = int(input())
count=0
dic={}
for i in range(n):
    
    b=list(input())
    b.sort()
    mojiretu = ''.join(b)
    if mojiretu not in dic:
        dic[mojiretu] =1
    else:
        dic[mojiretu] +=1
for v in dic.values():
    count += v*(v-1)//2
print(count)

Solution (Python):
import collections


N=int(input())
c=0
ans=[]
for n in range(N):
    a=input()
    a=sorted(a)
    a=''.join(a)
    ans.append(a)
c = collections.Counter(ans)
values, counts = zip(*c.most_common())
uu=0
for n in range(len(counts)):
    uu+=(counts[n]*(counts[n]-1))/2
print(round(uu))

Solution (Python):
N=int(input())

def listdict(s1):
    ret={}
    rets=""
    for i in s1:
        tmp=ret.get(i,0)
        if tmp==0:
            ret[i]=1
        else:
            ret[i]+=1
    ret_sorted = sorted(ret.items(), key=lambda x:x[0])
    
    for k in range(len(ret_sorted)):
        rets+=str(ret_sorted[k][0])
        rets+=str(ret_sorted[k][1])
    return rets

sN=[listdict(input()) for _ in range(N)]

d1={}
for i in sN:
    tmp=d1.get(i,0)
    if tmp==0:
        d1[i]=1
    else:
        d1[i]+=1
ret=0
for i in d1.values():
    if i ==1:
        continue
    for j in range(1,i):
        ret+=j
print(ret)

Solution (Python):
N = int(input())
S = {}
for i in range(N):
    j = "".join(sorted(input()))
    if j in S:
        S[j] += 1
    else:
        S[j] = 0

res = 0
for x in S.values():
  for y in range(1,x+1):
    res+=y
print(res)

Solution (Python):
import collections
N = int(input())
ch = []
for i in range(N):
    ch.append(''.join(sorted(list(input()))))
cnt = 0
ch = sorted(ch)


cnt = collections.Counter(ch)


h={}
sum=0
for i in range(N):
    h[i]=sum+i
    sum+=i
sum = 0
for i in cnt.values():
    sum += h[i-1]
print(sum)

Solution (Python):
def conv(st):
    res = [0]*26
    for s in st:
        res[ord(s)-ord('a')] += 1
    return ''.join(map(str,res))

N = int(input())
S = {}
res = 0
for i in range(N):
    s = conv(input())
    if s not in S.keys():
        S[s] = 1
    else:
        S[s] += 1
    if S[s] > 1:
        res += S[s]-1
print(res)

Solution (Python):
import collections
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

max = int(input())
i = 0
strings = []
while True:
  if i == max:
    break
  strings.append(input())
  i+=1



strings2 = [list(str) for str in strings]
[str.sort() for str in strings2] 

strs3 = [''.join(str) for str in strings2] 



c = collections.Counter(strs3)

counts = list(c.values()) 
counts2 = [ c for c in counts if c > 1] 



print(sum([int(cmb(n, 2)) for n in counts2]))

Solution (Python):
import string
import collections

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

str = collections.Counter(CountList)

count = 0
for s in str:
    count += sum(range(str[s]))

print(count)

Solution (Python):
N = int(input())
dicts = {}
for _ in range(N):
    s = "".join(sorted((input())))
    if s not in dicts:
        dicts[s] = 1
    else:
        dicts[s] += 1
print(sum([n*(n-1)//2 for n in list(dicts.values()) if 0<n]))
print("")

Solution (Python):
N = int(input())

V = dict()
for i in range(N):
	s = ''.join(sorted(input()))
	if s not in V.keys():
		V[s]=1
	else:
		V[s]+=1

result = 0
for key in V.keys():
	result += ((V[key]-1)*(1+V[key]-1))//2

print(result)

Solution (Python):
import sys
from functools import reduce
from operator import mul
from collections import Counter

input = sys.stdin.readline


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


def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for _, v in Counter(lines).most_common():
        if v == 1:
            break
        count += cmb(v, 2)
    print(count)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())

tmp = []
counter = 0
for i in range(N):
    new_str = ''.join(sorted(str(input())))
    
    
    
    tmp.append(new_str)

import collections
c = collections.Counter(tmp)




    
    
    
value = list(c.values())


for j in value:
    for k in range(j):
        counter += k

print(counter)

Solution (Python):

amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 0
sum2 = 0

for i in range(len(strings)):
	
	abc = list(strings[i])
	abc.sort()
	strings[i] = ''.join(abc)
	

strings.sort()

for j in range(len(strings)-1):
	
	
	if strings[j] == strings[j+1]:
		sum2 = sum2+1
	else:
		sum = sum + sum2 * (sum2+1) / 2
		sum2 = 0

sum = sum + sum2 * (sum2+1) / 2
print(int(sum))

Solution (Python):
import collections
import math

N = int(input())
b =[]
for i in range(N):
    a = input()
    b.append([j for j in a])
    b[i].sort()
a = [''.join(j) for j in b]
b = [k for k in collections.Counter(a).values()]
c = 0
for x in range(len(b)):
    if b[x] > 1:
        c += math.factorial(b[x]) // (math.factorial(b[x] - 2) * math.factorial(2))
    else:
        None
print(c)

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

sdict = [{c:s.count(c) for c in s} for s in S]
c = [ "".join( [c+str(sd[c]) for c in 'abcdefghijklmnopqrstuvwxyz' if c in sd] ) for sd in sdict ]

sdictc = {}
maxSdictc = 0
for cc in c:
    
    if cc in sdictc:
        maxSdictc += sdictc[cc]
        sdictc[cc] += 1
    else:
        sdictc[cc] = 1

print(maxSdictc)

Solution (Python):
n=int(input())
s=list(input() for _ in range(n))

t=['']*n

for i in range(n):
	t[i]=sorted(s[i])

u=sorted(t)

cnt=0








cnt_a=0
cnt_b=0

u.append(['0'])




for i in range(n):
	if u[i+1]==u[i]:
		cnt_a+=1
		
	else:
		if cnt_a>0:
			cnt_b+=(cnt_a+1)*cnt_a//2
			
			cnt_a=0

print(cnt_b)

Solution (Python):
N = int(input())
S = [input() for _ in range(N)]
 
from collections import Counter
 
nS = []
for s in S:
    s  = ''.join(sorted(s))
    nS.append(s)

c = Counter(nS)
 
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

acc = 0
for cnt in list(c.values()):
    if cnt!=1:
        acc+=cmb(cnt, 2)
    
print(acc)

Solution (Python):
import collections as c
import math

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

def C(n, r):
  return P(n, r)//math.factorial(r)

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

for i in s:
  count.append(''.join(sorted(list(i))))



comb = [i[1] for i in c.Counter(count).most_common()]
print(sum([C(i, 2) for i in comb if i >= 2]))

Solution (Python):
n = int(input())
s = []
count = 0
for i in range(n):
    s1 = list(input())
    s1.sort()
    s1 = "".join(s1)
    s.append(s1)
s.sort()
s2 = list(set(s))
s2.sort()
if len(s) == len(s2):
    print("0")
else:
    j1 = 0
    j2 = 0
    count1 = 0
    while j1 < n and j2 < len(s2):
        if s[j1] == s2[j2]:
            count1 = count1 + 1
            j1 = j1 + 1
        else:
            count = count + int(count1*(count1-1)/2)
            j2 = j2 + 1
            count1 = 0
    count = count + int(count1*(count1-1)/2)
    print(count)

Solution (Python):
import collections
import math

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

N = int(input())
s = [""]*N
S = []
for i in range(N):
    s[i] = input()
    test = list(s[i])
    test.sort()
    S.append("".join(test))
ana = sorted(collections.Counter(S).values())
count = 0
for i in ana:
    if i >= 2:
        count += combinations_count(i,2)
print(count)

Solution (Python):
import collections as cl
import itertools as it
N = int(input())
s = []
for i in range(N):
    ss = input()
    s.append(ss)

t = sorted(s)
t= []
for i in range(N):
    tt= sorted(s[i])
    ts = ",".join(tt)
    t.append(ts)


l = cl.Counter(t)

count = 0
for v in l.values():
    if v > 1:
        count = count + v*(v-1)/2

print(int(count))

Solution (Python):
def norm_str(s):
  ls = list(s)
  return "".join(sorted(ls))
  
ans = 0
pool = {}
n = int(input())
for i in range(n):
  s = input()
  norm = norm_str(s)
  
  if norm in pool:
    pool[norm] += 1
    ans += pool[norm]
    
  else:
    pool[norm] = 0
  
print(ans)

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

s.sort()

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

Solution (Python):
import collections
import math


n = int(input())

inputlist = []

for i in range(n):
    inputlist.append("".join(sorted(list(input()))))

counter = collections.Counter(inputlist)

counter = dict(counter)
valuelist = list(map(int, counter.values()))

ans = 0

for i in valuelist:
    if i == 1:
        continue
    if i == 2:
        ans += 1
        continue
    temp = math.factorial(i)
    temp /= math.factorial(i-2)
    temp = int(temp / 2)
    ans += temp

print(ans)

Solution (Python):

from collections import Counter
from itertools import combinations

N = int(input())
c = ["".join(sorted(str(input()))) for x in range(N)]
cs = Counter(c)

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

print(int(ans))

Solution (Python):


N = int(input())

alphabet = "abcdefghijklmnopqrstuvwxyz"

ans_dic = {}

for i in range(N):
    word = input()
    tmp = 0
    for s in word:
        tmp += 10**alphabet.index(s)

    if tmp in ans_dic:
        ans_dic[tmp] += 1
    else:
        ans_dic[tmp] = 1
ans = 0
for k, v in ans_dic.items():
    ans += v * (v-1) // 2
print(ans)

Solution (Python):
def f(x):
    return 10 ** (ord(x) - ord('a') + 1)


import math


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


from collections import Counter

N = int(input())
counter = Counter()
for i in range(N):
    counter[sum([f(i) for i in input()])] += 1
res = 0
for v in counter.values():
    if v > 1:
        res += combinations_count(v, 2)
print(res)

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

def helper(s):
  d = {}
  for c in s:
    if c not in d:
      d[c] = 0
    d[c] += 1
  
  return d

def pairs(n):
    return int(n * (n - 1) / 2)

d = {}
for s in S:
  if s not in d:
    d[s] = 0
  d[s] += 1

ans = sum([pairs(v) for v in d.values() if v > 1])
  
print(ans)

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

Dic = [1]*N
prime = {"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":101}

from operator import mul
from functools import reduce

def comb(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


for i in range(N):
    for s in S[i]:
        Dic[i]*= prime[s]

Dic.sort()
pre = Dic[0]
ans = 0
temp = 1
for d in Dic[1:]:
    if pre == d:
        temp += 1
    else:
        if temp >= 2:
            ans += comb(temp,2)
        pre = d
        temp = 1

ans += comb(temp,2) if temp >= 2 else 0
print(int(ans))

Solution (Python):
n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    if input_word in word_list:
        word_list[input_word] += 1
        result += word_list[input_word]
    else:
        word_list[input_word] = 0

print(result)

Solution (Python):
import sys
import collections

n = int(input())
lst = [None] * n
for i in range(n):
    lst[i] = "".join(sorted(list(sys.stdin.readline().strip())))

ans = 0
for v in collections.Counter(lst).values():
    ans += v * (v - 1) // 2
print(ans)

Solution (Python):
N = int(input())

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

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

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

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

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
    if c > 1:
        count += cmb(c, 2)

print(count)

Solution (Python):
import sys
from collections import Counter
from collections import defaultdict

N=input()

C=defaultdict(lambda: 0) 
for i in range(N):
	s=sys.stdin.readline().strip()
	s=list(s)
	s.sort()
	s="".join(s)
	C[s]+=1
ans=0

for i in C.values():
	ans+=i*(i-1)/2

print ans

Solution (Python):
import collections
import math

N = int(input())
s =[]
ans = 0
for i in range(N):
    s.append(input())
    letters = list(s[i])
    letters.sort()
    s[i] = "".join(map(str,letters))

H = collections.Counter(s)
I  = H.most_common()
for i in range(len(I)):
    if I[i][1] > 1:
        ans += int(math.factorial(I[i][1])/math.factorial(I[i][1]-2)/2)

print(ans)

Solution (Python):
from collections import defaultdict
N = int(input())
s = [input() for _ in range(N)]
dic = defaultdict(int)

for i in range(N):
    os = "".join(sorted(s[i]))
    dic[os] += 1

cnt = 0
for s, c in dic.items():
    
    cnt += c * (c-1) // 2
    
print(cnt)

Solution (Python):
n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    if input_word in word_list:
        word_list[input_word] += 1
        result += word_list[input_word]
        flag = 0
    else:
        word_list[input_word] = 0

print(result)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
l = ["".join(sorted([c for c in input()])) for i in range(N)]
l.sort()


def fac(n):
    """階乗"""
    res = 0
    for i in range(1, n+1):
        res += i
    return res


hash_l = []
for i in range(N-1):
    if l[i] == l[i+1]:
        if i == 0:
            hash_l.append(0)
        if l[i-1] == l[i]:
            hash_l[-1] += 1
        else:
            hash_l.append(1)

cnt = 0
for x in hash_l:
    cnt += fac(x)
print(cnt)

Solution (Python):
N = int(input())
obj = {}
for i in range(N):
  s = input()

  w = ''.join(sorted(list(s)))
  if not obj.get(w):
    obj[w] = 1
  else:
    obj[w] += 1

cnt = 0
for i in obj:
  v = obj[i]
  cnt += (v*(v-1))/2

print(int(cnt))

Solution (Python):
from collections import Counter
import math

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

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

[s[i].sort() for i in range(len(s))]

s = [' '.join(s[i]) for i in range(len(s))]
mycounter = Counter(s)
mycounter = list(mycounter.values())

mycounter = [mycounter[i] for i in range(len(mycounter)) if mycounter[i] > 1]
mycounter = [combinations_count(mycounter[i], 2) for i in range(len(mycounter))]

print(sum(mycounter))

Solution (Python):
import math
import sys
import itertools
import queue
from fractions import gcd

import sys
sys.setrecursionlimit(10000)

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""

a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654


char_list = list("abcd") 



    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())


    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  
"""

from math import factorial
import collections

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    
    sl = []
    for _ in range(N):
        tmp = sorted(sys.stdin.readline().rstrip())
        
        sl.append(''.join(tmp))
    
    c = collections.Counter(sl)
    ans = 0
    for n in c.values():
        r = 2
        if n > 1:
            ans += factorial(n) // (factorial(n - r) * factorial(r))

    print(int(ans))

Solution (Python):
def encode(s):







  r = 0
  for n in range(len(s)):
    so = ord(s[n]) - ord('a')
    r += 11**so
  return r

N = int(input())

S = [0]*N

for n in range(N):
  s = str(input())
  S[n] = encode(s)

S.sort()

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Solution (Python):
N = int(input())
s = {}
ans = 0
for n in range(N):
  chars = str(sorted(list(input())))

  if chars in s:
    s[chars] += 1
  else:
    s[chars] = 0
    
for value in s.values():
  ans += value * (value+1) // 2
  
print(ans)

Solution (Python):
import collections
n = int(input())
d = collections.defaultdict(int)
for _ in range(n):
    a = sorted(input())
    s = ''.join(a)
    d[s] += 1
count = 0
for v in d.values():
    count += v * (v-1) // 2
print(count)

Solution (Python):
import math

N = int(input())
s = [[""]*10 for i in range(N)]
a =[[0]*26 for i in range(N)]
b =[""]*N

cn =ord("a")

for i in range(N):
    s[i] = list(input())
    s[i].sort()
    b[i] ="".join(s[i])

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))

Solution (Python):
from collections import Counter
from scipy.misc import comb
N = int(input())
string_list=["".join(sorted(input())) for i in range(N)]

ans = 0
c = Counter(string_list)

for v in c.values():
    ans += comb(v, 2, exact=True)

print(ans)

Solution (Python):
def nCr(n, r):
    r = min(r, n-r)

    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i

    return numerator // denominator


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


ans = 0
cnt = 0
for i in range(n-1):
    if i == n-2 and s[i] == s[i+1]:
        cnt += 1
        ans += nCr(cnt+1, 2)
        print(ans)
        exit()
    if s[i] == s[i+1]:
        cnt += 1
    else:
        if cnt > 0:
            ans += nCr(cnt+1, 2)
            cnt = 0
print(ans)

Solution (Python):
from collections import Counter
n = int(input())
string_list=["".join(sorted(input())) for i in range(n)]

ans = 0
cnt = Counter(string_list)
for i in cnt.most_common():
    if i[1] != 1:
        ans += (i[1] * (i[1]-1) ) // 2
print(ans)

Solution (Python):
import collections
import math

N = int(input())

al = "abcdefghijklmnopqrstuvwxyz"
al_dict = {}
for i, c in enumerate(al):
    al_dict[c] = i

ss = []
for i in range(N):
    counts = [0 for i in range(26)]
    for char in input():
        ind = al_dict[char]
        counts[ind] += 1
    counts = [str(count) for count in counts]
    key = ",".join(counts)
    
    
    ss.append(key)


cc = collections.Counter(ss)


out = 0
for count in cc.values():
    if count == 1:
        continue
    out += math.factorial(count) // (math.factorial(count-2) * 2)
print(out)

Solution (Python):
import math

n = int(input())

setmap = dict()
for index in range(n):
  s = input()
  sorted_s = ''.join(sorted(s))
  if setmap.get(sorted_s) is not None:
    setmap[sorted_s] = setmap[sorted_s] + 1
  else:
    setmap[sorted_s] = 1

same_count = 0
for val in setmap.values():
  if val != 1:
    same_count += int(math.factorial(val) / (2 *  math.factorial(val - 2)))
print(same_count)

Solution (Python):
N = int(input())

def nume(x):
    return x*(x-1)/2-(x-1)

save = []

for i in range(N):
    s = ''.join(sorted(input()))
    save.append(s)

save.sort()

cnt = 0
serial = 1
for i in range(N-1):
    if save[i] == save[i+1]:
        cnt += 1
        serial += 1
    else:
        cnt += int(nume(serial))
        serial = 1

cnt += int(nume(serial))
print(cnt)

Solution (Python):
def main(text=""):
    n = int(input())
    a = [input() for i in range(n)]
    
    num = 0
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    i = 0
    while i < len(a):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            j = j + 1
        if j != 1:
            num = num + combination(j)
            i = i+j
        else:
            i = i+1
    print(num)


def combination(x):
    return int(x*(x-1)/2)


main()

Solution (Python):
n = int(input())
sl = sorted([''.join(sorted(input())) for _ in [0]*n])
count = 0
while len(sl)>1:
  i = 1
  flag = True
  while flag:
    if sl[-1] == sl[-(i+1)]:
      i += 1
      if i == len(sl):
        flag=False
    else:
      flag = False
  if i>1:
    count += i*(i-1)//2
  del sl[-i:]
  flag=True
print(count)

Solution (Python):

import math

l_s = set()
c = 0
n = int(input())
dup = {}

for i in range(n):
    st = sorted(input())
    s  = "".join(st)
    if s in l_s:
        if s in dup.keys():
            dup[s] += 1
        else:
            dup[s] = 1
        c += dup[s]
    l_s.add(s)

print(c)

Solution (Python):
N = int(input())
X =[]
for i in range(N):
    Y =list(input())
    Y.sort()
    X.append(Y)
X.sort()
    
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1
            Z = Z * count * (count-1)
            Z = Z // 2
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1
    Z = Z * count * (count-1)
    Z = Z // 2
    ans = ans + Z
        
print(ans)

Solution (Python):
import collections

N = int(input())

word_list = []
for i in range(N):
    S = list(input())
    c = collections.Counter(sorted(S))
    count = c.values()
    words = c.keys()
    word_list.append(''.join(words)+str(count))

ans_dict = collections.Counter(word_list)
ans_count = list(ans_dict.values())
temp = [i for i in ans_count if i>1]
ans = int(sum([t*(t-1)/2 for t in temp]))
print(ans)

Solution (Python):
from collections import Counter
N = int(input())
lis = ["".join(sorted(list(input()))) for _ in range(N)]
keys, values = zip(*Counter(lis).most_common())
values = list(filter(lambda x: x >= 2, values))

sums = 0
for k in values:
  sums += ((k - 1) * (k)) / 2
  
print(int(sums))

Solution (Python):
N = int(input())
ss = []
for i in range(N):
    s = list(input())
    s.sort()
    ss.append(s)

ss.sort()
ans = 0
tmp = 1
for i in range(N-1):
    if ss[i] == ss[i+1]:
        tmp += 1
        if i == N-2:
            ans += (tmp * (tmp-1)) // 2
    else:
        ans += (tmp * (tmp-1)) // 2
        tmp = 1

print(ans)

Solution (Python):


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



n = int(input())
s = []
for i in range(n):
  s.append(input())
h = []
b = 'abcdefghijklmnopqrstuvwyz'
for i in s:
  a = [0] * 27
  for c,d in enumerate(b):
    a[c] = i.count(d)
  ss = ''
  for j in a:
    ss += str(j)
  h.append(ss)
 
ans = 0
c = {}
for i in h:
  if c.get(i, -1) == -1:
    c[i] = 1
  else:
    c[i] += 1
sum = 0
for i in c:
  if c[i] < 2:
    continue
  ans += cmb(c[i],2)

print(ans)

Solution (Python):
N=int(input())
S=[]
T=[]
for i in range(N):
	s=str(input())
	S.append(s)
for j in range(N):
	X=sorted(str(S[j])[k] for k in range(10))
	Y=X[0]+X[1]+X[2]+X[3]+X[4]+X[5]+X[6]+X[7]+X[8]+X[9]
	T.append(Y)
R=sorted(T)

l,r=0,0
ans=0
while r<N:
	if R[r]==R[l] and r==N-1:
		ans=ans+int((r-l)*(r-l+1)/2)
		r=r+1
	elif R[r]==R[l]:
		r=r+1
	else:
		ans=ans+int((r-l-1)*(r-l)/2)
		l=r
print(int(ans))

Solution (Python):
ss = []
N = int(input())
for n in range(N):
    s = sorted(input())
    ss.append(s)

ss = sorted(ss)

total = 0
count = 0
for n in range(N):
    if n==0:
        continue
    
    
    if ss[n-1]==ss[n]:
        count += 1
    else:
        total += int(count*(count+1)/2)
        count = 0
    
total += int(count*(count+1)/2)
count = 0

print(int(total))

Solution (Python):
import collections
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 = []
for i in range(N):
  s = "".join(sorted(list(input())))
  a.append(s)

c = collections.Counter(a)
r = 2
total = 0
for k in c.keys():
  n = int(c[k])
  if n != 1:
    total += cmb(n, r)

print(total)

Solution (Python):
n = int(input())
s = []
for _ in range(n):
  x = input()
  s.append("".join(sorted(x)))

s = sorted(s)

j = 0
x = []
for i in range(1, n):
  if s[i] == s[i-1]:
    j += 1
  else:
    if j > 0:
      x.append(j)
      j=0
if j > 0:
  x.append(j)

def func(n):
  return (n+1)*n/2

ret = sum(map(func, x))

print(int(ret))

Solution (Python):
def ss(s):
    
    res = s[0]
    for i in s[1:]:
        flg = False
        for j, e in enumerate(res):
            if e > i:
                res = res[:j] + i + res[j:]
                flg = True
                break

        if not flg:
            res += i
    return res


def poe(n):
    return sum([i - 1 for i in range(2, n + 1)])


def main():
    n = int(input())
    slist = {}
    for i in range(n):
        s = ss(input())
        if s in slist:
            slist[s] += 1
        else:
            slist[s] = 1

    ans = 0
    for k, v in slist.items():
        a = poe(v)
        ans += a
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math

num = int(input())
tmp = {}
flg = 0
ans = 0
for i in range(num):
  inp = ''.join(sorted(input()))
  if inp not in tmp: tmp[inp]=1
  else: tmp[inp]+=1
for k, v in tmp.items():
  if v > 1:
    ans += v*(v-1)//2
    flg = 1
print(ans)

Solution (Python):
import collections

m = [0] * (10**6)
for i in range(1, len(m)):
    m[i] = m[i-1] + i

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

c = 0
for k, v in collections.Counter(s).items():
    if v <= 1:
        continue
    c += m[v-1]

print(c)

Solution (Python):
n = int(input())
ans = 0
d = {}
for i in range(n):
    s = ''.join(sorted(input()))
    if s not in d.keys():
        d[s] = 1
    else:
        ans += d[s]
        d[s] += 1

print(ans)

Solution (Python):

n = int(input())
s = []
dict = {}
for i in range(n):
    ss = sorted(input())
    st = "".join(map(str,ss))
    if st in dict:
        dict[st]+=1
    else:
        dict[st] = 1
    

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

print(count)

Solution (Python):
N = int(input())
s = [None]*N
s_sort = [None]*N
for _ in range(N):
    s[_] = sorted(list(input()))
    s_sort[_] = ''.join(s[_])
s_sort.sort()
inst = s_sort[0]
s_sort.append("fuckatcorder")
count = 0
lis = []
for i in range(1,N+1):
    if s_sort[i] == inst:
        count += 1
    else:
        if count != 0:
            lis.append(count)
            count = 0
            inst = s_sort[i]
        else:
            inst = s_sort[i]
ans = 0
for k in range(len(lis)):
    ans += lis[k]*(lis[k]+1)//2
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

from collections import Counter
counter = Counter(S)

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