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:
N = int(input())
s_list = ["".join(sorted(input())) for i in range(N)]

count = 0

s_list = sorted(s_list)

flag = False

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if s_list[i] == s_list[j]:
      count += 1
      flag = True
    if s_list[i] != s_list[j] and flag == True:
      flag = False
      continue
      
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):
    for j in range(i + 1, N):
        si = set(S[i])
        sj = set(S[j])
        if len(si) == len(sj) and si == sj:
            count += 1
        else:
            ci = Counter(S[i])
            cj = Counter(S[j])
            if ci == cj:
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = input()
ss = [raw_input() for _ in range(n)]
ss = map(sorted, ss)

print sum(1 for i in xrange(n) for j in xrange(i + 1, n) if ss[i] == ss[j])

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)

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

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

print(ans)

Submission status: Time Limit Exceeded

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

def encode(s):
#     print(s)
    res = 0
    for ss in s:
        key = ord(ss)-ord('a')
        res += 10**key
    return res

lst = []
count = 0
for s in ss:
    en = encode(s)
#     print(en)
    for ls in lst:
        if ls == en:
            count += 1
#         print(s)
    lst.append(en)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

sList = [0 for _ in range(N)]

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

confilm = [False for _ in range(N)]

ans = 0
for i in range(N) :
    if confilm[i] :
        continue
    confilm[i] = True
    count = 1
    for j in range(i + 1, N) :
        if sList[i] == sList[j] :
            confilm[j] = True
            count += 1
    ans += count * (count - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
cnt = 0
for i in range(N):
    s = sorted(input())
    for s_tmp in S:
        if s_tmp == s:
            cnt += 1
    S.append(s)

print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=[]
for i in range(n):
    s=input()
    l.append(Counter(s))
ans=0

for i in range(n):
    for j in range(n):
        if i<j:
             if l[i]==l[j]:
                 ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
hists = []
for n in range(N):
	line = input()
	h = [0]*27
	for i in range(len(line)):
		h[ord(line[i])-ord('a')] += 1
	hists.append(h)

ans = 0
for n in range(len(hists)):
	for m in range(n+1,len(hists)):
		for i in range(27):
			if hists[n][i]!=hists[m][i]:
				break
		else:
			ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        if verify_anagrams(s[i], s[j]) == True:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(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 = [input() for _ in range(n)]
result = 0
for i in range(n):
  s[i] = ''.join(sorted(s[i]))
for i in range(n - 1):
  for j in range(i + 1, n):
    if s[i] == s[j]:
      result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
s.sort()
count = 0
for i in range(N):
    for j in range(i+1, N):
        Flag = True
        for k in range(10):
            if s[i][k] != s[j][k]:
                Flag = False
                break
        if Flag:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter 
def anagram(input1, input2): 
    return Counter(input1) == Counter(input2) 
n=int(input())
val=0
l=[]
for i in range(n):
    s=input()
    l.append(s)
for j in range(len(l)):
    for k in range(j+1,len(l)):
        if anagram(l[j],l[k]):
            val+=1
print(val)

Submission status: Time Limit Exceeded

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

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

# print(S)
ans = 0
for i in range(N):
    si = S[i]
    for j in range(i + 1, N):
        sj = S[j]
        if si == sj:
            # print(i, j, si, sj)
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

s_list2=["".join(sorted(x)) for x in s_list]
c=0
for i in range(len(s_list2)):
    for j in range(i+1,N):
        if s_list2[i]==s_list2[j]:
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
ss = [input() for i in range(N)]
sdic = []
for s in ss:
  dic = defaultdict(int)
  for c in s:
    dic[c] += 1
  sdic.append(dic)
ans = 0
for i in range(N):
  for j in range(i+1, N):
    if sdic[i] == sdic[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import  Counter
N=int(input())
L=[]
ans=0
for i in range(N):
    s=Counter(list(input()))
    for j,[k,ss] in enumerate(L):
        if s==ss:
            L[j][0]+=1
            ans+=k+1
            break
    else:
        L.append([0,s])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(list(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())
S = [None] * N
for i in range(N):
    S[i] = input()
nums = [None] * N
for i, s in enumerate(S):
    tmp = [0] * 26
    for c in s:
        tmp[ord(c)-97] += 1
    nums[i] = ' '.join(map(str, tmp))

ans = 0
for i, s_i in enumerate(nums):
    for s_j in nums[i+1:]:
        if s_i == s_j:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i 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:
import collections

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

c = [0] * N
for i in range(N):
    c[i] = collections.Counter(s[i])

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

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
strings = []
while t > 0:
  strings.append(sorted(input()))
  t -= 1
n = len(strings)
count = 0
for i in range(n):
  for j in range(i+1,n):
    if strings[i] == strings[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from math import factorial
# alpha = 'abcdefghijklmnopqrstuvwxyz'

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

N = int(input())
anss = []
ans = 0
dic = defaultdict(int)
for i in range(N):
    t = input()
    t = sorted(t)
    if t in anss:
        dic[anss.index(t)] += 1
    else: anss.append(t)
# print(dic)
for k in dic.keys():
    if dic[k] > 1:
        ans += com(dic[k]+1,2)
    else: ans += dic[k]
print(ans)

Submission status: Time Limit Exceeded

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

adict=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

slist=[]
for _ in range(N):
    slist.append([])

for i in range(len(adict)):
    for j in range(N):
        for k in range(10):
            if adict[i]==s[j][k]:
                slist[j].append([adict[i]])

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

print(num)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

N = int(input())
ss = [''.join(sorted(input())) for _ in range(N)]
ssset = set(ss)

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

ans = 0
for s in ssset:
    n = ss.count(s)
    if n > 1:
        ans += cmb(n, 2)

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections


if __name__ == '__main__':
    n = int(input())
    s = [str(input()) for i in range(n)]

    c = []


    for i in range(n):
        c.append(collections.Counter(s[i]))

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

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

    print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
count = []

for _ in range(N):
    s = input()
    count.append(Counter(s))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
#s=[input() for i in range(n)]
s=[Counter(input()) for i 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)
#def verify_anagrams(first_word, second_word):
#    return Counter(first_word) == Counter(second_word)

Submission status: Time Limit Exceeded

Solution code:
import bisect
from collections import Counter
n=int(input())
strings=[]
for _ in range(n):
    s=input()
    s=sorted(s)
    s="".join(s)
    i=bisect.bisect_left(strings, s)
    strings.insert(i, s)
c=Counter(strings)
ans=0
for i,v in c.items():
    ans+=int(v*(v-1)*0.5)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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:
n = int(input())
arr = []
for i in range(n):
    arr.append(sorted(input()))
count = 0    

for i in range(n-1):
    for j in range(i+1,n):
        flag = 0
        for k in range(10):
            if arr[i][k]!=arr[j][k]:
                flag=1
                break
        if flag==0:
            count+=1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
S = [sorted(input()) for _ in range(n)]

for i in range(n):
    for j in range(i+1, n):
        a = S[i]
        b = S[j]
        if a == b:
            ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
strs = [sorted(list(input())) for _ in range(K)]

answer = 0
for i in range(K-1):
    for j in range(i+1,K):
        if strs[i] == strs[j]:
            answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

cnts = []
for i in s:
        cnts.append(collections.Counter(i))

ans = 0
for c in cnts:
        tmp = cnts.count(c)
        if tmp > 1:
                ans += tmp - 1

print(ans // 2)

Submission status: Time Limit Exceeded

Solution code:
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=[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:
N = int(input())

s = [sorted(list(input())) for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1, N):
        f = True
        for k in range(10):
            if s[i][k]!=s[j][k]:
                f = False
                break
        if f: ans+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        if collections.Counter(S[i]) == collections.Counter(S[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(str(input()))
    s[i]=''.join(sorted(s[i]))
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())
wordlist=[input() for i in range(n)]
count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=list(wordlist[i])
        b=list(wordlist[j])
        a.sort()
        b.sort()
        if a==b:
            count+=1
print(count)

Submission status: Time Limit Exceeded

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

col_S = [Counter(s) for s in S]

cnt = 0
for ind, col_s in enumerate(col_S):
    for ref_ind, ref_col_s in enumerate(col_S[ind+1:]):
        if col_s == ref_col_s: cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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



stock = []
ans = 0
for i in range(n):
  str = collections.Counter(input().strip())
  ans += stock.count(str)
  stock.append(str)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
s_list = [collections.Counter(input()) for _ in range(N)]
cnt = 0
for i, s in enumerate(s_list):
    for t in s_list[i+1:]:
        if (s==t): cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
c = 0
l = [''.join(sorted(input())) for _ in range(n)]
c = 0
for i in range(n):
    for j in range(i+1, n):
        if l[i] == l[j]:
            c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())


s = []
for i in range(N):
    s0 = input()  
    c = collections.Counter(s0)
    s.append(c)

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(sorted(input()))

cnt = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        if s[i] == s[j]:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#! python


#K, X = [int(x) for x in input().split()]

N = int(input())
S = []
for _i in range(N):
    S.append(input())

sortedS = [sorted(s) for s in S]

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    s=input()
    ss=sorted(s)
    l.append([ss])
ans=0
for i in range(n):
    for j in range(n):
        if i<j:
             if l[i]==l[j]:
                 ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
b = [sorted(list(input())) for _ in range(a)]
b.sort()
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        if b[i][0] == b[j][0]:
            if "".join(b[i]) == "".join(b[j]):
                cnt += 1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
strings = []
while t > 0:
  strings.append(input())
  t -= 1
n = len(strings)
count = 0
for i in range(n):
  for j in range(i+1,n):
    if sorted(strings[i]) == sorted(strings[j]):
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n = int(input())
ct_ls = []
for i in range(n):
    ct_ls.append(sorted(input()))
cnt = 0
for combi in combinations(ct_ls, 2):
    if combi[0] == combi[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Ts = []
for i in range(N):
  S = input()
  T = sorted(S)
  Ts.append(T)
r = 0
for i in range(N):
  for j in range(i+1, N):
    if Ts[i] == Ts[j]:
      r += 1
print(r)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
tmp = []
for i in range(n):
    s = list(str(input()))
    s.sort()
    tmpstr = "".join(s)
    tmp.append(tmpstr)
T = set(tmp)
ans = 0
for i in T:
    ans += (tmp.count(i) - 1 )*(tmp.count(i))//2
print(ans)

Submission status: Time Limit Exceeded

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

result = 0

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

print(result)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python

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

l_s = []
for i in range(n):
    l_s.append(sorted(l[i]))

c = 0
for i in range(len(l_s)):
    for j in range(i+1, len(l_s)):
        if l_s[i] == l_s[j]:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
n = int(input())
lst = [input() for i in range(n)]
cnt = 0
for j in range(n - 1):
    for k in range(j + 1, n):
        if sorted(list(lst[j])) == sorted(list(lst[k])):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

s.sort()

cnt = 0
for i in range(n):
    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 = []
ans = 0
for i in range(N):
  s = list(input())
  c = Counter(s)
  S.append(c)
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:
#[int(i) for i in input().split()]
n = int(input())
s = []
cnt = 0
for i in range(n):
    s.append(sorted(input()))
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:
n = int(input())

s_input_list = []

for i in range(n):
    tmp = input()
    s_input_list.append(tmp)

s_sorted_list = []
for s in s_input_list:
    tmp = list(s)
    tmp.sort()
    s_sorted_list.append(tmp)

#print(s_sorted_list)

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

Submission status: Time Limit Exceeded

Solution code:
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_list = [sorted(input()) for i in range(N)]

count = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = [input() for _ in range(N)]
PS = ["".join([c + str(s.count(c)) for c in sorted(list(set(s)))]) for s in S]

t = 0
for ps in set(PS):
    n = PS.count(ps)
    t += n * (n - 1) // 2

print(t)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import Counter

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

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

cs = [Counter(seq) for seq in S]

ans = 0
for si, sj in combinations(cs, 2):
    if si == sj:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[''.join(sorted(input())) for _ in range(n)]
ans=0
t=[]
for i in range(n):
    ans+=t.count(s[i])
    t.append(s[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

c = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if Ss[i] == Ss[j]:
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from math import *
from collections import deque, defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappush, heappop
from copy import copy, deepcopy

N = int(input())
xs = []
for i in range(N):
    x = input()
    xs.append(x)

us = "abcdefghijklmnopqrstuvwxyz"

cs = []
ess = []
for x in xs:
    c = Counter(x)
    es = [0,] * 26
    for i,u in enumerate(us):
        e = c[u]
        es[i] = e
    cs.append(c)
    ess.append(tuple(es))


g = Counter(ess)

re = 0
for k,v in g.items():
    re += v*(v-1)//2
print(re)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n):
    for j in range(n):
        if i!=j:
            if a[i] == a[j]:
                ans +=1
print(ans//2)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = [sorted(list(input())) for i 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 _ in range(n)]

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

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
s = []
for n in range(N):
	line0 = input()
	line = ''.join(sorted(line0))
	s.append(line)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
str_list = []
for i in range(N):
  str_dict = {}
  for j in input():
    if j in str_dict:
      str_dict[j] += 1
    else:
      str_dict[j] = 1
  str_list.append(str_dict)
  
count = 0
for i in range(N):
  for j in range(i+1, N):
    if str_list[i] == str_list[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())

ss = []
for i in range(n):
	s = input()
	ss.append(collections.Counter(s))

c = 0
for i in range(n):
	for k in range(i+1,n):
		if ss[i] == ss[k]:
			c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s_list = [input() for i in range(N)]

count = 0

for i in range(len(s_list)):
  for j in range(i+1, len(s_list)):
    if sorted(s_list[i]) == sorted(s_list[j]):
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for i 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 = []
ans = 0
for i in range(N):
        si = sorted(input())
        if si in s:
                ans += s.count(si)
        s.append(si)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

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

N = int(input())
ans = [collections.Counter(list(input())) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if ans[i] == ans[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    s = [sorted(input().strip()) 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)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy
a = int(input())
b = [list(input()) for _ in range(a)]
cnt = 0
for i in range(a):
    for j in range(i + 1, a):
        c = numpy.sort((b[i]))
        d = numpy.sort(b[j])
        if (c == d).all():
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# ソートして全探索

n = int(input())
arr = []
for _ in range(n):
    arr.append(list(sorted(input())))

c = 0
for i in range(n - 1, -1, -1):
    for j in range(i - 1, -1, -1):
        if arr[i] == arr[j]:
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n=int(input())
ss=[input() for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        if Counter(ss[i])==Counter(ss[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    n=int(input())
    l=[Counter(input())for i in range(n)]
    ans=0
    for i in range(len(l)):
        for j in range(len(l)):
            if i==j:
                continue
            else:
                if l[i]==l[j]:
                    ans+=1
    print(ans//2)
                    
        
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [""]*N
for i in range(N) :
    L[i] = "".join(sorted(list(input())))

ans = 0

for i in range(N-1) :
    a = L[i]
    for j in range(i+1,N) :
        b = L[j]
        if a == b :
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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