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: Time Limit Exceeded

Solution code:
import math


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


n = int(input())
c = [''.join(sorted(list(input()))) for _ in range(n)]
s = set(c)

anagram = [0] * len(s)
for i, si in enumerate(s):
    anagram[i] = c.count(si)

print(sum(comb(a, 2) for a in anagram if a > 1))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections


n = int(input())
c = list([collections.Counter(input()) for _ in range(n)])

summ = 0
for c1, c2 in itertools.combinations(c, 2):
    summ += c1 == c2
print(summ)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections


def is_anagram(s1, s2):
    c1 = collections.Counter(s1)
    c2 = collections.Counter(s2)
    return c1 == c2


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

summ = 0
for s1, s2 in itertools.combinations(s, 2):
    summ += is_anagram(s1, s2)

print(summ)

Submission status: Time Limit Exceeded

Solution code:
def is_anagram(s1, s2):
  d1 = {c1: s1.count(c1) for c1 in s1}
  d2 = {c2: s2.count(c2) for c2 in s2}
  return d1 == d2

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

num = 0
for i in range(n-1):
  for j in range(i+1, n):
    num += s[i] ==  s[j]
print(num)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
ListS = []
Number = []
ListN = []
Comb = 0
for _ in range(N):
    ListS.append(input())
for i in range(len(ListS)):
    for j in range(len(ListS[i])):
        Number.append(ListS[i][j])
    A = sorted(Number)
    B = "".join(A)
    ListN.append(B)
    Number = []

ListNs = list(set(ListN))
for k in range(len(ListNs)):
    if ListN.count(ListNs[k])>1:
        Comb += math.factorial(ListN.count(ListNs[k]))//(math.factorial(ListN.count(ListNs[k])-2)*2)

print(Comb)

Submission status: Time Limit Exceeded

Solution code:
import itertools
num =input()
num = int(num)
an = 0
all = []
for i in range(0, num):
    ele = []
    s = input()
    ans = list(itertools.permutations(s))
    for i in range(0, len(ans)):
        ele.append(''.join(ans[i]))
    all.append(ele)

for i in range(0, len(all)):
    st = all[i][0]
    for t in range(0, len(all)):
        if i != t:
            if st in all[t]:
                an += 1
print(an)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=["".join(sorted(input())) for i in range(n)]
Sn=set(S)
cnt=0
for s in Sn:
    if S.count(s)>=2:
        cnt+=S.count(s)*(S.count(s)-1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
import sys

N = int(input())
s = [collections.Counter(sys.stdin.readline().rstrip()) for _ in range(N)]

counted = []
count = 0
for s_count in s:
    if s_count not in counted:
        n = s.count(s_count)
        counted.append(s_count)
        count += n * (n - 1) // 2
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

s_count_list = [collections.Counter(S) for S in s]

counted = []
count = 0
for s_count in s_count_list:
    if s_count not in counted:
        n = s_count_list.count(s_count)
        counted.append(s_count)
        count += n * (n - 1) // 2
            
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

s_count_list = [collections.Counter(S) for S in s]

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

Submission status: Time Limit Exceeded

Solution code:
total = 0
A = int(input())
B = []
for i in range(A):
    C = list(input())
    C.sort()
    B.append("".join(C))
for i in range(A):
    D = B[i]
    for j in range(A-i-1):
        if D == B[i+1+j]:
            total += 1
print(total)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = ''.join(sorted(list(input())))
	for j in lst:
		if st == j:
			pair += 1
	lst.append(st)
print (pair)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1
    
ln2 = ([i for i in ln2 if i != 1])

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

x = 0

for k in ln2:
    x += cmb(k, 2)
    
print(x)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
ans = 0
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1

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

x = 0

for k in ln2:
    if k > 1:
        x += cmb(k, 2)
    
print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = []
pair = 0
for i in range(n):
	st = sorted(list(input()))
	for j in lst:
		if st == j:
			pair += 1
	lst.append(st)
print (pair)

Submission status: Time Limit Exceeded

Solution code:
import os, sys, re, math

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

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

Submission status: Time Limit Exceeded

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

    def combinations_count(n, r):
        """ 組み合わせ総数を計算 """
        import math
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

    ans = 0
    unique_list = set(S)
    for u in unique_list:
        cnt = S.count(u)
        if cnt >= 2:
            ans += combinations_count(cnt, 2)

    print(ans)

    
if __name__ == '__main__':
    q3()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
count=[]
ans=0
for i in range(N):
  s=sorted(input())
  if s in S:
    ans+=count[S.index(s)]
    count[S.index(s)]+=1
  else:
    S.append(s)
    count.append(1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
cnt=0
S=[input() for i in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        if sorted(S[i])==sorted(S[j]):
            cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
count = 0
for _ in range(N):
    s = list(input())
    s.sort()
    S.append(''.join(s))

for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
for _ in range(N):
    s=input()
    S.append("".join(sorted(s)))
    #S.append(sorted(s))
#print(S)
re=0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            re+=1
            #break
print(re)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
for _ in range(N):
    s=input()
    #S.append("".join(sorted(s)))
    S.append(sorted(s))
#print(S)
re=0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            re+=1
            #break
print(re)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
count = 0
for _ in range(N):
    s = list(input())
    s.sort()
    S.append(s)

for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = [""] * n
t = [""] * n

cnt = 0

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

t = sorted(t)

for i in range(n - 1):
    for j in range(i + 1, n):
        if t[i] == t[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = [""]*n
for i in range(n):
	slist[i] =sorted(input())
sslist=sorted(slist)
count=0
for i in range(n-1):
	for j in range(i+1,n):
		if sslist[i][0]==sslist[j][0]:
			if sslist[i]==sslist[j]:
				count = count +1
#	print(sslist[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = [""]*n
for i in range(n):
	slist[i] =sorted(input())
sslist=sorted(slist)
count=0
for i in range(n-1):
	for j in range(i+1,n):
		if sslist[i]==sslist[j]:
			count = count +1
#	print(sslist[i])
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial, log, log10, log2
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(readline())
  S = []
  for _ in range(n):
    s = sorted(input())
    S.append(s)
  ans = 0
  for i in range(n-1):
    for j in range(i+1, n):
      if S[i]==S[j]:
        ans+=1
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        if sorted(s[i]) == sorted(s[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())

cnt = 0
anas = [Counter(input())]

for _ in range(n-1):
    _s = Counter(input())
    for a in anas:
        if a == _s:
            cnt += 1

    anas.append(_s)

print(cnt)

Submission status: Time Limit Exceeded

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

def main():
  n = int(input())
  base = []
  base_ans = []

  for i in range(n):
    temp = 0
    s = input()
    sign = 0
  
    for j in range(10):
      temp  = temp + 10**(ord(s[j]) - 97)
    
    for j in range(len(base)):
      if temp == base[j][0]:
        base[j][1] = base[j][1] + 1
        sign = 1
      
    if sign == 0:
      base.append([temp,1])

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
base = []
base_ans = []

for i in range(n):
  temp = [0]*26
  s = input()
  sign = 0
  
  for j in range(10):
    temp[ord(s[j]) - 97]  = temp[ord(s[j]) - 97] + 1
    
  for j in range(len(base)):
    if temp == base[j][0]:
      base[j][1] = base[j][1] + 1
      sign = 1
      
  if sign == 0:
    base.append([temp,1])

ans = 0
for i in range(len(base)):
  if base[i][1] >= 2:
    ans = ans + base[i][1]*(base[i][1] - 1)//2


print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for _ in range(N)]
ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    if s[i] == s[j]: ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
  temp = [0]*26
  s = input()
  sign = 0
  
  for j in range(10):
    temp[ord(s[j]) - 97]  = temp[ord(s[j]) - 97] + 1
    
  for j in range(len(base)):
    if base[j][0] == temp:
      base[j][1] = base[j][1] + 1
      sign = 1
  
  if (temp not in base) and (sign == 0):
    base.append([temp,1])

ans = 0    
for i in range(len(base)):
  if base[i][1] >= 2:
    ans = ans + int(base[i][1]*(base[i][1] - 1)/2)


print(ans)

Submission status: Time Limit Exceeded

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

C = []
sum_ana = 0
for _ in range(N):
  s = list(input())
  c = Counter(s)
  sum_ana += C.count(c)
  C.append(c)
  
print(sum_ana)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
r = [[0 for _ in range(26)] for i in range(n)]
for i in range(n):
    s = str(input())
    for j in range(10):
        r[i][ord(s[j])-97] += 1
w = []
cnt = []
for i in range(n):
    if r[i] in w:
        cnt[w.index(r[i])] += 1
    else:
        w.append(r[i])
        cnt.append(1)
ans = 0
for i in range(len(cnt)):
    ans += (cnt[i]*(cnt[i]-1))//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [Counter(input()) for i in range(n)]
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
anslist = []
for i in range(n):
  s = input()
  slist = [i for i in s]
  slist.sort()
  for j in range(len(anslist)):
    if slist == anslist[j]:
      ans += 1
  anslist.append(slist)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
w = []
r = []
for i in range(n):
    s = str(input())
    s = sorted(s)
    if s in w:
        r[w.index(s)] += 1
    else:
        w.append(s)
        r.append(1)
ans = 0
for i in range(len(r)):
    ans += (r[i]*(r[i]-1))//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = []
cnt = 0
for i in range(n):
  s = input()
  s = sorted(s)
  
  s = ''.join(s)
  
  if slist:
    for i in range(len(slist)):
      if slist[i] == s:
        cnt += 1
  slist.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, *S = open(0).read().split()
N = int(N)

C = [Counter([]) for i in range(N)]
for i in range(N):
    C[i] = Counter(list(S[i]))

ans = 0
for i in range(N):
    for j in range(i):
        ans += 1 if C[i] == C[j] else 0
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
p = [list(str(input())) for _ in range(n)]
ans = 0
for i in p:
    i.sort()
for j in range(n):
    for k in range(j + 1, n):
        if p[j] == p[k]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n=int(input())
S=[]
ans=0
for i in range(n):
    s=input()
    S.append(s)
    for j in range(i):
        if Counter(S[j])==Counter(s):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n=int(input())
S=[]
ans=0
for i in range(n):
    s=input()
    S.append(s)
for i in range(n):
    for j in range(n-i-1):
        if Counter(S[j+i+1]) == Counter(S[i]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
lst=[None]*N
for i in range(N):
    lst[i]=''.join(sorted(input()))
count=0
for i in range(N-1):
    for j in range(i+1, N):
        if lst[i]==lst[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
lst=[None]*N
for i in range(N):
    lst[i]=''.join(sorted(input()))
count=0
for el in set(lst):
    num=lst.count(el)
    count+=num*(num-1)//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
for i in range(N):
    s_i = ''.join(sorted(input()))
    if s_i in s:
        ans += s.count(s_i)
    s.append(s_i)

# s.sort()
# ans = 0
# print(s)
# for i in range(N):
#     for j in range(i+1, N):
#         if s[i] == s[j]:
#             ans += 1
#         elif s[i] < s[j]:
#             print(s[i], s[j])
#             break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(''.join(sorted(input())))
s.sort()
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if s[i] == s[j]:
            ans += 1
        elif s[i] < s[j]:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [input() for _ in range(N)]
T = [sorted(s) for s in S]
ans = 0
for i in range(N):
  for j in range(i+1,N):
    if T[i] == T[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = []
for _ in range(N):
    a = str(input())
    S.append(a)
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if sorted(S[i]) == sorted(S[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sis = []
sin = []
for i in range(n):
  si = sorted(input())
  if not si in sis:
    sis.append(si)
    sin.append(1)
  else:
    sin[sis.index(si)] += 1
ans = 0
for j in sin:
  for k in range(1, j):
    ans += k
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = []
for i in range(N):
  L.append(input())
res = 0
anagrams = []
for i in range(N):
    for j in range(N):
        if i!=j and sorted(L[i]) == sorted(L[j]) and (i,j) not in anagrams:
            res += 1
            anagrams.append((i,j))
            anagrams.append((j,i))
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = [""]*n
for i in range(n):
  s = sorted(input())
  ans[i] = s
cnt = 0
for p in range(n):
  for q in range(p+1, n):
    if ans[p] == ans[q]:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
alphabetCount = []
for i in range(n):
  word = input()
  cnt = [0]*26
  for j in range(10):
    cnt[ord(word[j]) - ord("a")] += 1
  alphabetCount.append(cnt)

l = 0  
for p in range(n):
  for q in range(p+1, n):
    if alphabetCount[p] == alphabetCount[q]:
      l += 1
print(l)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(sorted(str(input())))
r = []
g = []
for i in range(n):
    if(s[i] in r):
        g[r.index(s[i])] += 1
    else:
        r.append(s[i])
        g.append(1)
ans = 0
for i in range(len(g)):
    ans += max(((g[i])*(g[i]-1))//2,0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(str(input()))
    s[i] = sorted(s[i])
r = []
g = []
for i in range(n):
    if(s[i] in r):
        g[r.index(s[i])] += 1
    else:
        r.append(s[i])
        g.append(1)
ans = 0
for i in range(len(g)):
    ans += max(((g[i])*(g[i]-1))//2,0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def Comb(n,k):
    comb_ans=1
    for i in range(1,k+1):
        comb_ans*=(n-i+1)/i
    comb_ans=int(comb_ans)
    return comb_ans

N=int(input())
S=[str(sorted(input())) for i in range(N)]
T=set(S)
ans=0
for i in T:
    cnt=S.count(i)
    ans+=Comb(cnt,2)
#print(S)
#print(T)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[str(sorted(input())) for i in range(N)]
cnt=0
for i in range(N-1):
    for j in range(i+1,N):
        if S[i]==S[j]:
            cnt+=1
#print(S)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
for nk in range(n):
  tmp = list(input())
  tmp.sort()
  mo = ''
  for i in tmp:
    mo += i

  s.append(mo)

s.sort()
count =0
for i in range(n):
  for j in range(i+1,n):
    if s[i] == s[j]:
      count += 1
    else:
      break
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
for nk in range(n):
  tmp = list(input())
  tmp.sort()
  mo = ''
  for i in tmp:
    mo += i

  s.append(mo)
  
count =0
for i in range(n):
  for j in range(i+1,n):
    if s[i] == s[j]:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    ans += s.count(s[0])-1
    del s[0]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
words = []
cnt = 0
for _ in range(n):
    s = list(input())
    ss = sorted(s)

    if ss in words:
       cnt += words.count(ss)
    words.append(ss)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S =[]
for i in range(N):
    S.append(sorted(list(Counter(str(input())).items()),reverse = False))
#print(S)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
L=[[] for _ in range(n)]
ans=0
for i in range(n):
    L[i]=list(input())
    L[i].sort()
    for j in range(i):
        if L[j]==L[i]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
from collections import Counter
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    S=[str(input()) for i in range(N)]


    cnt=0
    for i in range(N):
        for j in range(i+1,N):
            if Counter(S[i])==Counter(S[j]):
                cnt+=1

    print(cnt)

resolve()

Submission status: Time Limit Exceeded

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    S=[sorted(list(input())) for i in range(N)]

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

    print(cnt)

resolve()

Submission status: Time Limit Exceeded

Solution code:
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
n = int(input())
# 列ベクトルとかの受け取り
lists = [Counter(input()) for _ in range(n)]

check = []

ans = 0
i = 0
while i < len(lists):
    j = i+1
    while j <len(lists):
        if lists[i] == lists[j]:
            ans += 1
        j += 1
    i += 1

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

se=[]
cnt=0
for i in range(n):
    s=list(input())
    s.sort()

    for j in se:
        if s == j:
            cnt+=1

    se.append(s)    
    
print(cnt)

Submission status: Time Limit Exceeded

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

N = int(input().strip())
s_list = [input().strip() for _ in range(N)]
#-----

for i,s in enumerate(s_list):
    s_list[i] = "".join(sorted(s))

cnt=0
for i in range(len(s_list)):
    for j in range( (i+1),len(s_list)):
        if s_list[i] == s_list[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#137_C
from collections import Counter
n = int(input())
s = [Counter(input()) for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [sorted(list(input())) for n in range(N)]

cnt = 0
for n in range(N):
    s = S.pop(0)
    cnt += S.count(s)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
D={}
ans = 0
for i in range(N):
    a = str(sorted(input()))
    if a in D:
        D[a] += 1
        ans += D[a]
    else:
        D[a] = 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A=[]
for i in range(N):
    x= sorted(list(input()))
    A.append(x)
ans = 0
for i in range(N):
    ans += A[i+1:].count(A[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(N):
    for j in range(i+1,N):
        if(l[i] == l[j]):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(len(l)):
    for j in range(i+1,len(l)):
        #if(i != j):
            if(l[i] == l[j]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list(input() for _ in range(N))

l = list(map(sorted,s))
cnt = 0
for i in range(len(l)):
    for j in range(i,len(l)):
        if(i != j):
            #print(i,",",j)
            if(l[i] == l[j]):
                cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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


for i in range(n):
    x = list(str(input()))
    x.sort()
    s.append(''.join(x))

count = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            count += 1

            
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = []
for _ in range(n):
    s.append(list(input()))
count = 0
for i in range(n-1):
    for j in range(i+1, n):
        if Counter(s[i]) == Counter(s[j]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

n = int(input())
lst = []
ans = 0

for i in range(n):
    s = input()
    c = sorted(collections.Counter(s).most_common())
    tmp_str = ""
    for i in c:
        tmp = str(i[1])
        tmp_str += i[0] + tmp
    lst.append(tmp_str)
    
d = collections.Counter(lst)
for i in d.values():
    if i >= 2:
        ans += combinations_count(i, 2)
print(ans)

Submission status: Time Limit Exceeded

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

n = int(input())
lst = []
cnt = [0] * n
ans = 0

for i in range(n):
    s = input()
    c = collections.Counter(s)
    if c not in lst:
        lst.append(c)
    else:
        cnt[lst.index(c)] += 1

for i in cnt:
    if i != 0:
        ans += combinations_count(i+1, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
count = []

for _ in range(N):
    tmp = collections.OrderedDict(sorted(collections.Counter([s for s in input()]).items()))
    count.append("".join(list(tmp.keys())) + "".join(map(str, list(tmp.values()))))
        
ans = 0
for v in collections.Counter(count).values():
    ans += v * (v - 1) // 2

print(ans)