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().strip())

count_by_kw = {}
for i in range(n):
    s=''.join(sorted(input().strip()))
    if s in count_by_kw.keys():
        count_by_kw[s]+=1
    else:
        count_by_kw[s]=1

c=list(count_by_kw.values())
ans=0
for val in c:
    ans+=val*(val-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input().strip())

count_by_kw = Counter()
for i in range(n):
    s=str(sorted(input().strip()))
    count_by_kw[s]+=1

c=list(count_by_kw.values())
ans=0
for val in c:
    ans+=val*(val-1)//2
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input().strip())

count_by_kw = Counter()
c=0
for i in range(n):
    s=str(sorted(input().strip()))
    if s in count_by_kw:
        c+=count_by_kw[s]
    count_by_kw[s]+=1
    
print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
i = 0
while i < n:
    c = S.count(S[i])
    if c > 1:
        C.append(c)
    i += c

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

for j in range(n):
    for k in range(j+1,n):
        if sorted(list(s[j]))==sorted(list(s[k])):
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

A = [Counter(input()) for _ in range(n)]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s = []
textSet = set()
ans = 0

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

s.sort()

# print(s)
cnt = 0

for i in range(1, n):
    if s[i] == s[i-1]:
        cnt += 1
    elif cnt > 0:
        # ans += cntC2
        ans += len(list(itertools.combinations(range(cnt+1), 2)))
        cnt = 0

if cnt > 0:
    ans += len(list(itertools.combinations(range(cnt + 1), 2)))

print(ans)

Submission status: Time Limit Exceeded

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

l = len(s)
while l > 0:
  i = s[0]
  s = [ss for ss in s if ss != i]
  t = l - len(s)
  if t != 1:
    a.append(t)
  l = l-t

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

Submission status: Time Limit Exceeded

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

l = len(s)
while l > 0:
  i = s[0]
  s = [ss for ss in s if ss != i]
  ll = len(s)
  a.append(l-ll)
  l = ll

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

Submission status: Time Limit Exceeded

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

while len(s) > 0:
  l = s[0]
  t = [ss for ss in s if ss != l]
  a.append(len(s)-len(t))
  s = t

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

Submission status: Time Limit Exceeded

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

while len(s) > 0:
  l = s[0]
  a.append(s.count(l))
  s = [ss for ss in s if ss != l]

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

Submission status: Time Limit Exceeded

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

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())
s = []; count = 0
for i in range(N):
    spell = ''.join(sorted(input()))
    if spell in s:
        count += int(s.count(spell))
    s.append(spell)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []; count = 0
for i in range(N):
    spell = ''.join(sorted(input()))
    for j in range(len(s)):
        if spell == s[j]:
            count += 1
    s.append(spell)

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
    s.append(''.join(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:
# TODO: WAなので修正する
from math import factorial
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())
li = []
for i in range(n):
    s = input()
    s = "".join(sorted(s))
    li.append(s)

li.sort()
index = 0
anagram_cnt_sum = 0
while(index < n):
    anagram_cnt = li.count(li[index])
    if anagram_cnt > 1:
        anagram_cnt_sum += cmb(anagram_cnt, 2)
    index += anagram_cnt
print(anagram_cnt_sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
li = [input() for x in range(N)]
ans = 0
wli = list()
for k in li:
    wli.append(''.join(sorted(list(k))))
for i in range(N):
    word = wli[i]
    for j in range(i+1, N):
        comp = wli[j]
        if word == comp:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
li = [input() for x in range(N)]
ans = 0
wli = list()
for k in li:
    wli.append(sorted(list(k)))
for i in range(N):
    word = wli[i]
    for j in range(i+1, N):
        comp = wli[j]
        if word == comp:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
li = [input() for x in range(N)]
ans = 0
for i in range(N):
    word = list(li[i])
    for j in range(i+1, N):
        comp = list(li[j])
        if sorted(word) == sorted(comp):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())

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

    count = 0
    for s in list(set(s_list)):
        i = s_list.count(s)
        if i == 1:
            continue
        else:
            count += i * (i-1) // 2

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())

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

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

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
stock = dict()
ans = 0
for i in range(N):
    c="".join(sorted(input()))
    for k, v in stock.items():
        if c == k:
            ans += v
            stock[k] += 1
            break
    else:
        stock[c] = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
stock = dict()
ans = 0
for i in range(N):
    s = list(input())
    s.sort()
    c = str(s)
    for k, v in stock.items():
        #print(sto)
        #print(c)
        #print(sto == c)
        if c == k:
            ans += v
            stock[k] += 1
            break
    else:
        stock[c] = 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
stock = list()
ans = 0
for i in range(N):
    s = list(input())
    c  = collections.Counter(s)
    for sto in stock:
        #print(sto)
        #print(c)
        #print(sto == c)
        if c == sto:
            ans +=1
    
    stock.append(collections.Counter(s))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

S.sort()
ans = 0

for n in range(N - 1):
    tmp = n
    while S[tmp + 1] == S[tmp]:
        ans += 1
        if tmp == N - 2:
            break
        tmp += 1

print(ans)
#print(S)

Submission status: Time Limit Exceeded

Solution code:
n = int(input()) #n行の入力をリストに入れる
l = []
for i in range(n):
    l.append(input()) 

from collections import Counter

def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

def verify_anagrams(first_word, second_word):
    return get_counter(first_word) == get_counter(second_word)

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

print(count)
#print(verify_anagrams(l[0],l[2]))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

count = 0

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
while len(s)>1:
  k=s.count(s[0])
  if k==1:
    continue
  else:
    cnt+=int(k*(k-1)/2)
  del s[:k]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    for k in range(10):
      if s[i][k]!=s[j][k]:
        break
      elif k==9:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def chk(A,B):
  nL=len(A)
  ans=0
  for i in range(nL):
    if A[i]!=B[i]:
      break
    elif i==nL-1:
      ans=1
  return ans
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    k=chk(s[i],s[j])
    if k==0:
      break
    else:
      cnt+=k
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def chk(A,B):
  nL=len(A)
  if A[0]==B[0]:
    if nL==1:
      return 1
    else:
      return chk(A[1:],B[1:])
  else:
    return 0
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
k=0
for i in range(n-1):
  for j in range(i+1,n):
    k=chk(s[i],s[j])
    if k==0:
      break
    else:
      cnt+=k
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def chk(A,B):
  nL=len(A)
  if A[0]==B[0]:
    if nL==1:
      return 1
    else:
      return chk(A[1:],B[1:])
  else:
    return 0
n=int(input())
s=[sorted(input()) for i in range(n)]
s.sort()
cnt=0
for i in range(n-1):
  for j in range(i+1,n):
    cnt+=chk(s[i],s[j])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = ["".join(sorted(input())) for i in range(n)]
cnt = 0
for i in range(n):
	for j in range(i+1,n):
		if a[i] == a[j]:
			cnt += 1
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
ans = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    tmp = "".join(tmp)
    S.append(tmp)
L = set(S)
L = list(L)
L_cnt = [0 for i in range(len(L))]
for i in S:
    L_cnt[L.index(i)]+=1
L_ans = [((L_cnt[i])*(L_cnt[i]-1))//2 for i in range(len(L))]
print(sum(L_ans))

Submission status: Time Limit Exceeded

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

p = itertools.combinations(a,2)
cnt = 0
for i,j in p:
	s = sorted(list(i))
	t = sorted(list(j))
	if s == t:
		cnt += 1
		#print (i,j)
print (cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
cnt = 0
for i in range(N):
    tmp = list(input())
    tmp.sort()
    S.append(tmp)
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=[]
for _ in range(n):
    l=[0]*26
    ch=input()
    for i in range(26):
        x=ch.count(chr(97+i))
        l[i]=x
    s.append(l)
y=0
for i in range(n-1):
    for j in range(i+1,n):
        if s[i]==s[j]:
            y+=1
print(y)

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
s=[sorted(list(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:
import collections
N=int(input())
s=[collections.Counter(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())
S = []
for _ in range(N):
    s = list(input())
    s.sort()
    s = ''.join(s)
    S.append(s)

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 = []
for _ in range(N):
    s = list(input())
    s.sort()
    s = tuple(s)
    S.append(s)

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 = []
for _ in range(N):
    s.append(sorted(input()))

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:
# 15:20
n = int(input())
s = [0] * n
ans = 0
for i in range(n):
    t = sorted(input())
    ans += s.count(t)
    s[i] = t
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# 15:20
n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
ans = 0
for i in range(n-1):
    ans += s[i+1:].count(s[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 15:20
n = int(input())
s = []
for i in range(n):
    s.append(input())
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:
# 15:20
n = int(input())
s = []
for i in range(n):
    s.append(input())
ans = 0
for i in range(n-1):
    L = []
    for j in range(10):
        L.append((s[i][j], s[i].count(s[i][j])))
    L = sorted(L)
    for k in range(i+1,n):
        R = []
        for l in range(10):
            R.append((s[k][l], s[k].count(s[k][l])))
        R = sorted(R)
        if L == R:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
count=0
for i in range(n):
    d=input()
    d="".join(sorted(d))
    count+=a.count(d)
    a.append(d)
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count=0
for i in range(n):
    temp=a.pop()
    count+=a.count(temp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    d=input()
    a.append(sorted(d))
#print(a)

count=0
for i in range(n):
    temp=a.pop()
    count+=a.count(temp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n):
    d=input()
    a.append(sorted(d))
#print(a)

count=0
for i in range(n):
    temp=a.pop()
    if temp in a:
        count+=a.count(temp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as ddict

n=int(input())
a=[]
dict={}
for i in range(n):
    d=ddict(int)
    s=input()
    for x in s:
        d[x]+=1
    a.append(sorted(d.items()))
#print(a)

count=0
for i in range(n):
    temp=a.pop()
    if temp in a:
        count+=a.count(temp)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict as ddict

n=int(input())
a=[]
dict={}
for i in range(n):
    d=ddict(int)
    s=input()
    for x in s:
        d[x]+=1
    a.append(sorted(d.items()))
#print(a)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
count = 0
for string in strings:
    tmp = strings.count(string)
    if tmp > 1:
        count += (tmp - 1) / 2

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N=int(input())
strings=list("".join(sorted(input())) for _ in range(N))
strings_set = set(strings)
count = 0
for string in strings_set:
    tmp = strings.count(string)
    if tmp > 1:
        count += tmp * (tmp - 1) // 2

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
ans = 0

for i in range(n):
    s = input()
    l.append(sorted(s))
    
for i in range(n-1):
    for j in range(i+1,n):
        if l[i] == l[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC-137-C
from collections import Counter
N = int(input())
S = []
for _ in range(N):
    si = Counter(input())
    S.append(si)

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

ans=0
result=[]
for i in range(N):
    s= ''.join(sorted(input()))
    ans+=result.count(s)
    result.append(s)
print(ans)

Submission status: Time Limit Exceeded

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

ans=0
result=[]
for i in range(N):
    s=s_[i]
    ans+=result.count(s)
    result.append(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections as cl
N=int(input())
s_=[sorted(input()) for i in range(N)]

ans=0
result_=[]
for j in range(N):
    cnt=cl.Counter(s_[j]).items()
    for l in range(j):
        if cnt==result_[l]:
            ans+=1
        else:
            ans+=0

    result_.append(cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
ans=0
N=int(input())
s_lst=[input() for _ in range(N)]
for i in range(N-1):
    for j in range(i+1,N):
        si=collections.Counter(s_lst[i])
        sj=collections.Counter(s_lst[j])
        if si==sj:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]
ans=0
for i in range(n):
  s=list(input())
  s.sort()
  a.append(str(s))
a.sort()
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]==a[j]:
      ans+=1
    #print(a[i],a[j],ans)
  




print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

cnt = 0

N = int(input())
string_counters = [collections.Counter(input()) for i in range(N)]
for pair in list(itertools.combinations(string_counters, 2)):
    if pair[0] == pair[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def compareLists(string1, string2):
    result = 1
    list1 = sorted(string1)
    list2 = sorted(string2)
    if list1 != list2:
        result = 0
    return result

N = int(input())
list_s = []
list_for_dic = []

for _ in range(N):
    s = input()
    list_s.append(s)
    
list_comparisions = list(itertools.combinations(list_s, 2))
score = 0
for compare in list_comparisions:
    score += compareLists(compare[0], compare[1])
    
print(score)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def compareLists(string1, string2):
    result = 1
    list1 = sorted(string1)
    list2 = sorted(string2)
    for i in range(len(list1)):
        if (list1[i] != list2[i]):
            result = 0
    return result
  
N = int(input())
list_s = []
list_for_dic = []

for _ in range(N):
    s = input()
    list_s.append(s)
    
list_comparisions = list(itertools.combinations(list_s, 2))
score = 0
for compare in list_comparisions:
    score += compareLists(compare[0], compare[1])
    
print(score)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = []
count = 0
for i in range(N):
    a += [''.join(sorted(input()))]
sorted_a = sorted(a)
for i in range(N-1):
    for j in range(1, N):
        if i+j >= N:
            break
        if sorted_a[i] == sorted_a[i+j]:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

for j in range(n):
    arr2.append("".join(arr[j]))

ans = 0
for k in range(n):
    for l in range(k+1,n):
        if arr2[k] == arr2[l] :
            ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
#S = list(map(str, input().split()))
# S = list(map(str, input().split()))
S = []
for _ in range(N):
    S.append(input())

#受け取った文字列をアルファベットに並び替え
S=[''.join(sorted(a)) for a in S]

#バケットを作って、出現回数をカウント
count=[0]*(len(set(S)))
unique_S=list(set(S))
ans=0
for ele in S:
    count[unique_S.index(ele)]+=1
count=sorted(count,reverse=True)

#階乗のコード
def cor(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact
#組み合わせのコード
def combination(n,c):
    a=(cor(n))/(cor(n-c)*cor(c))
    return a

for i in count:
    if i==1:
        break
    else:
        ans+=combination(i,2)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[list(str(input())) for i in range(n)]
for k in l:
  k.sort()
  k="".join(k)
nums=[x for x in range(n-1)]
cnt=0
for i in nums:
  for j in l[i+1:]:
    if(l[i]==j):
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
l=[list(str(input())) for i in range(n)]
nums=[x for x in range(n-1)]
cnt=0
for i in nums:
  for j in l[i+1:]:
    if(Counter(l[i])==Counter(j)):
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = []
arr2 = []
arr3 = []
for i in range(n):
    arr.append(list(input()))

for j in range(n):
    arr2.append(sorted(arr[j]))

for k in range(n):
    arr3.append(" ".join(arr2[k]))

ans = 0

for l in range(n):
     ans += arr3.count(arr3[l])-1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
arr = []
arr2 = []
arr3 = []
for i in range(n):
    arr.append(list(input()))

for j in range(n):
    arr2.append(sorted(arr[j]))

for k in range(n):
    arr3.append(" ".join(arr2[k]))

ans = 0

for l in range(n-1):
    for m in range(l+1,n):
        if arr3[l] == arr3[m]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

#Nのみを見ればよい
ans=0
for i in range(1,N):
  for j in range(i):
    if A[i]==A[j]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
count = 0
s_new = []
for word in s:
  word_new = sorted(word)
  count += s_new.count(word_new)
  s_new.append(word_new)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [list(input()) for _ in range(n)]
for index, word in enumerate(s):
  s[index] = str(s[index].count("a")) + str(s[index].count("b")) + str(s[index].count("c")) + str(s[index].count("d")) + str(s[index].count("e")) + str(s[index].count("f")) + str(s[index].count("g")) + str(s[index].count("h")) + str(s[index].count("i")) + str(s[index].count("j")) + str(s[index].count("k")) + str(s[index].count("l")) + str(s[index].count("m")) + str(s[index].count("n")) + str(s[index].count("o")) + str(s[index].count("p")) + str(s[index].count("q")) + str(s[index].count("r")) + str(s[index].count("s")) + str(s[index].count("t")) + str(s[index].count("u")) + str(s[index].count("v")) + str(s[index].count("w")) + str(s[index].count("x")) + str(s[index].count("y")) + str(s[index].count("z"))
count = 0
for index, word in enumerate(s):
  count += s[index + 1:].count(word)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[list(str(input())) for i in range(n)]
cnt=0
nums=[x for x in range(n)]
for m in l:
  m.sort()
for i in nums[:n-1]:
  for j in l[i+1:]:
    if(l[i]==j):
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    string = "".join(sorted(list(input())))

    if string in s:
        ans += s.count(string)

    s.append(string)

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#ABC137_C
N=int(input())
str_list=["".join(sorted(input(),reverse=True)) for _ in range(N)]
cnt=0
for _ in range(N-1):
    cnt+=str_list.count(str_list.pop(-1))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#ABC137_C
N=int(input())
ans=[]
cnt=0
for _ in range(N):
    str_list=input()
    dic={}
    for i in range(10):
        if str_list[i] in dic:
            dic[str_list[i]]+=1
        else:
            dic[str_list[i]]=1
    ans.append(dic)
while len(ans)>1: 
    cnt+=ans.count(ans.pop(0))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [list(input()) for i in range(N)]
for i in range(N):
    Si = S[i]
    Si.sort()
    Si2 = ''.join(Si)
    S[i] = Si2
ans = 0
for i in range(N-1):
    Si = S[i]
    for j in range(i+1,N):
        Sj = S[j]
        if Si == Sj:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [list(input()) for i in range(N)]
for i in range(N):
    Si = S[i]
    Si.sort()
    S[i] = Si
ans = 0
for i in range(N-1):
    Si = S[i]
    for j in range(i+1,N):
        Sj = S[j]
        if Si == Sj:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N = int(input())
a = []
b = []
c = np.array([[0]*26]*N)
count = 0
for i in range(N):
    a.append(input())

for i in range(N):
    b = a[i]
    for j in range(10):
        if b[j] == 'a':
            c[i][0] +=1
        elif b[j] == 'b':
            c[i][1] +=1
        elif b[j] == 'c':
            c[i][2] +=1
        elif b[j] == 'd':
            c[i][3] +=1
        elif b[j] == 'e':
            c[i][4] +=1
        elif b[j] == 'f':
            c[i][5] +=1
        elif b[j] == 'g':
            c[i][6] +=1
        elif b[j] == 'h':
            c[i][7] +=1
        elif b[j] == 'i':
            c[i][8] +=1
        elif b[j] == 'j':
            c[i][9] +=1
        elif b[j] == 'k':
            c[i][10] +=1
        elif b[j] == 'l':
            c[i][11] +=1
        elif b[j] == 'm':
            c[i][12] +=1
        elif b[j] == 'n':
            c[i][13] +=1
        elif b[j] == 'o':
            c[i][14] +=1
        elif b[j] == 'p':
            c[i][15] +=1
        elif b[j] == 'q':
            c[i][16] +=1
        elif b[j] == 'r':
            c[i][17] +=1
        elif b[j] == 's':
            c[i][18] +=1
        elif b[j] == 't':
            c[i][19] +=1
        elif b[j] == 'u':
            c[i][20] +=1
        elif b[j] == 'v':
            c[i][21] +=1
        elif b[j] == 'w':
            c[i][22] +=1
        elif b[j] == 'x':
            c[i][23] +=1
        elif b[j] == 'w':
            c[i][24] +=1
        elif b[j] == 'z':
            c[i][25] +=1
for i in range(N):
    for j in range(1,N):
        if i < j:
            if c[i].all!=0:
                if c[j].all!=0:
                    if (c[i] == c[j]).all():
                        count += 1
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = [list(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    Si = collections.Counter(S[i]).most_common()
    Si.sort(key=lambda x: x[0])
    for j in range(i+1,N):
        Sj = collections.Counter(S[j]).most_common()
        Sj.sort(key=lambda x: x[0])
        if Si == Sj:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
S = [0] * N
for i in range(N):
    S[i] = sorted(str(input()))

Sum = 0
hoge = 1

S.sort()

for i in range(N-1):
    if S[i] == S[i+1]:
        hoge += 1
    if (S[i] != S[i+1] or i == N-2) and hoge != 1:
        Sum += math.factorial(hoge) // (math.factorial(hoge - 2) * math.factorial(2))
        hoge = 1

print(Sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [0] * N
for i in range(N):
    S[i] = str(input())

Sum = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        S1 = sorted(S[i])
        S2 = sorted(S[j])
        
        for k in range(10):
            if S1[k] != S2[k]:
                break
            if k == 9:
                Sum += 1

print(Sum)