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 collections
N = int(input())
count = {}

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
strings=sorted([sorted(list(input())) for i in range(N)])
cnt=0
for i in range(N-1):
    for k in range(1,N-i):
        if strings[i]==strings[i+k]:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(list(input()))) for _ in range(N)]
flag = [False] * N
ans = 0
for i in range(N - 1):
    if flag[i]:
        continue
    flag[i] = True
    cnt = 0
    for j in range(i + 1, N):
        if s[i] == s[j]:
            flag[j] = True
            cnt += 1
    ans += sum([n for n in range(cnt, 0, -1)])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(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:
n=int(input())
s=[]
ans=0
for i in range(n):
  S=str(sorted(input()))
  s.append(S)

for i in range(len(set(s))):
  tmp = s.count(list(set(s))[i])
  if tmp==1:
    ans+=0
  else:
    ans+=tmp*(tmp-1)/2
  
print(int(ans))

Submission status: Time Limit Exceeded

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

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

s = sorted(s)
count = 0
for i in range(n-1):
	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:
from sys import stdin

N = int(stdin.readline().rstrip())
Ss = []
Sd = {}
ans = 0

for i in range(N):
    s = sorted([x for x in stdin.readline().rstrip()])
    ss = ("".join(s))
    if ss in Ss:
        ans += Sd[ss]
        Sd[ss] += 1
    else:
        Ss.append(ss)
        Sd[ss] = 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
Ss = []
ans = 0

for i in range(N):
    s = [x for x in stdin.readline().rstrip()]
    s.sort()
    if s in Ss:
        ans += Ss.count(s)
    Ss.append(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
a=int(input())
c=[0]*a
d=[0]*10
x=0
for i in range(a):
	e=input()
	for j in range(10):
		d[j]=e[j]
	d.sort()
	c[i]=d[0]+d[1]+d[2]+d[3]+d[4]+d[5]+d[6]+d[7]+d[8]+d[9]

for k in range(0,a):
	for l in range(k+1,a):
		if c[k]==c[l]:
			x=x+1
print(x)

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
for i in range(len(L)):
    ans+=((L_cnt[i])*(L_cnt[i]-1))//2
print(ans)

Submission status: Time Limit Exceeded

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

def sorted_str(string):
    s = sorted(string)
    return s

dic_list = []
for i in range(N):
    dic_list.append(sorted_str(s_list[i]))

cnt = 0
for i in range(N):
    #dic = strcount(s_list[i])
    dic_i = dic_list[i]
    for j in range(i + 1, N):
        #dic = strcount(s_list[i])
        dic_j = dic_list[j]
        if dic_i == dic_j:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

def strcount(string):
    dic = {}
    for s in string:
        if s not in dic:
            dic[s] = 1
        else:
            dic[s] += 1
    return dic

dic_list = []
for i in range(N):
    dic_list.append(strcount(s_list[i]))

cnt = 0
for i in range(N):
    #dic = strcount(s_list[i])
    dic_i = dic_list[i]
    for j in range(i + 1, N):
        #dic = strcount(s_list[i])
        dic_j = dic_list[j]
        if dic_i == dic_j:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

def strcount(string):
    dic = {}
    for s in string:
        if s not in dic:
            dic[s] = 1
        else:
            dic[s] += 1
    return dic

cnt = 0
for i in range(N):
    dic = strcount(s_list[i])
    for j in range(i + 1, N):
        #dic = strcount(s_list[i])
        if dic == strcount(s_list[j]):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

def strcount(string):
    dic = {}
    for s in string:
        if s not in dic:
            dic[s] = 1
        else:
            dic[s] += 1
    return dic

cnt = 0
for i in range(N):
    dic = strcount(s_list[i])
    for j in range(i + 1, N):
        #dic = strcount(s_list[i])
        if dic == strcount(s_list[j]):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
anagram = [None]*N

ans = 0
for i in range(N):
    anagram[i] = "".join(sorted(input()))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [None]*N
for i in range(N):
    s[i] = 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:
N = int(input())
s = [None]*N
for i in range(N):
    s[i] = input()

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

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())
sc = [list(input()) for i in range(N)]
for i in sc:
    i.sort()
count = 0
for i in range(0 , len(sc)-1):
    for j in range(i+1,len(sc)):
        if sc[i] == sc[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(input()) for _ 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:
from collections import Counter
n = int(input())
S = []
r = -n
for i in range(n):
    s = Counter(input())
    S.append(s)
    r += S.count(s)
print(r)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
list_voc = [str(input()) for _ in range(n)]
list_mo = []
for i, s in enumerate(list_voc):
    list_n = list(s)
    list_n.sort()
    list_n = ''.join(list_n)
    list_mo.append(list_n)


set_mo = set(list_mo)
list_mo_s = list(set_mo)
ans = []
for s in list_mo_s:
    ans.append(list_mo.count(s))

ans_val = []

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


for s in ans:
    if s != 1:
        ans_val.append(cmb(s, 2))


print(sum(ans_val))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
moji = []
for i in range(n):
    s = sorted(list(input()))
    cnt += moji.count(s)
    moji.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(list(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 = [''.join(sorted(input())) for _ in range(N)]
t = set(s)

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

ans = 0
for t_i in t:
    ans += tousa(s.count(t_i))
print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for t_i in t:
    ans += tousa(s.count(t_i))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [list(input()) for _ in range(N)]
s_sort = [sorted(n) for n in s]
cnt = 0
cnt_list = []
for i in range(N):
  if cnt_list.count(s_sort[i]) == 1:
    pass
  else:
    count = s_sort.count(s_sort[i])
    cnt_list.append(s_sort[i])
    if count == 1:
      pass
    elif count > 1:
      cnt += int(count*(count-1)/2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
IN = [input() for _ in range(n)]
S = []
for i in IN:
    S.append(''.join(sorted(i)))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
IN = [input() for _ in range(n)]
S = []
for i in IN:
    S.append(''.join(sorted([s for s in i])))

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

Submission status: Time Limit Exceeded

Solution code:
# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
from itertools import combinations


def main():
    N = int(input())
    S = [sorted(input()) for _ in range(N)]
    ptn = list(combinations(S, 2))
    result = 0

    for p in ptn:
        result += all([p[0] == p[1]])
    print(result)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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


for _ in range(N):
    tmp=list(input())
    stmp=str(sorted(tmp))
    if((stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)

total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[]
cnt=dict()
for _ in range(N):
    tmp=list(input())
    stmp=sorted(tmp)
    if(( stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

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

cnt = 0
for t, u in combinations(s, 2):
    if Counter(t) == Counter(u):
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import itertools
A = []
t = 0
for i in range(n):
    A.append(sorted(list(input())))
for i in list(itertools.combinations(A,2)):
    a, b = i
    if a == b:
        t += 1
print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [0]*N
for i in range(0, N):
    s[i] = input()
t = []
c = 0
for i in range(0, N):
    s[i] = sorted(s[i])
    for j in range(0,len(t)):
        if s[i] == t[j][0]:
            c = c+t[j][1]
            t[j][1] = t[j][1]+1
            break
    else:
        t.append([s[i],1])
print (c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
read_=sys.stdin.buffer.readline

N=int(read_())
S=[Counter(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:
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())
l=[]
sum=0
for i in range(n):
  v=str(input())
  v=sorted(v)
  l.append(v)
l=sorted(l)
while len(l)!=0:
  k=l.count(l[0])
  if k==1:
    l.remove(l[0])
    continue
  else:
    sum+=(k*(k-1))//2
    for i in range(k):
      l.remove(l[0])
      i+=1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = list()
count = 0
for i in range(N):
  s.append(input())
  s[i] = sorted(s[i])
s.sort()
for i in range(N):
  for j in range(N):
    if s[i] == s[j] and i != j:
      count += 1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import collections
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = 0
r = collections.Counter(s)
for k, v in r.items():
    if v > 1:
        c += len(list(combinations(range(v), 2)))

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = "".join(s)
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = {}
cnt = 0
for _ in range(n):
    s = input()
    s = sorted(s)
    u = ""
    for i in range(len(s)):
      u += s[i]
    if u in S.keys():
        S[u] += 1
    else:
        S[u] = 1
for x in S.values():
    x = x-1
    cnt += x*(x+1)//2
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
  s[i].sort()

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())
list=[]
for i in range(N):
  s=input()
  s=sorted(s)
  list.append(s)
t=0
for i in range(N-1):
  for j in range(i+1,N):
    if list[i]==list[j]:
      t+=1
print(t)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# 最初はごちゃごちゃ考えていたが、文字列を１文字ずつリストにしてからソートして
# それをさらに文字列に戻してソートしたらおわり
n = int(input())
sort = [""]*n
for i in range(n):
    s = list(input())
    s.sort()
    sort[i] = str(s)
sort.sort()
#print(sort)
ans = 0
cnt = 0
for i in range(n-1):
    if sort[i+1] == sort[i]: cnt += 1
    else: 
        ans += cnt*(cnt+1)//2
        cnt = 0
print(ans+cnt*(cnt+1)//2)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

# input

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

# sort
for i in range(0,N):
    s[i] = sorted(s[i])
    
def Number_Each_Element(group):
    group = sorted(group)
    discrepancy = np.array([])
    
    for i in range(len(group)-1):
        if group[i] != group[i+1]:
            discrepancy = np.append(discrepancy,i)
    discrepancy = np.append(discrepancy,len(group)-1)
    
    
    result = np.ones(len(discrepancy))
    for i in range(len(result)):
        if i == 0:
            result[i] = int(discrepancy[i]+1)
        else:
            result[i] = int(discrepancy[i]-discrepancy[i-1])
            
            
    return result

result = Number_Each_Element(s)

count = 0
for i in result:
    count += i*(i-1)/2

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

# input

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

# sort
for i in range(0,N):
    s[i] = sorted(s[i])
    
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 numpy as np
import math

# input

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

lis=[collections.Counter(list(s[i])) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        if lis[i].items()==lis[j].items(): 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(input())
    
counts = [Counter(i) for i in s]
result = 0
for i in range(len(counts)):
  for j in range(i+1, len(counts), 1):
    if counts[i] == counts[j]:
      result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))
anagram_lst.sort()

count = 1
for i in range(n-1):
    anagram1 = anagram_lst[i]
    anagram2 = anagram_lst[i+1]
    if anagram1==anagram2:
        count +=1
        if i==n-2:
            number += addition(count-1)
    else:
        number += addition(count-1)
        count = 1

print(number)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))
    anagram_lst.sort()

count = 1
for i in range(n-1):
    anagram1 = anagram_lst[i]
    anagram2 = anagram_lst[i+1]
    if anagram1==anagram2:
        count +=1
        if i==n-2:
            number += addition(count-1)
    else:
        number += addition(count-1)
        count = 1

print(number)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))

used_lst = []
for i in range(n):
    count_lst = anagram_lst[i]
    count = anagram_lst.count(count_lst)
    if count_lst not in used_lst:
        number += addition(count-1)
        used_lst.append(count_lst)

print(number)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from scipy import misc


def main():

    n = int(input())

    words_list = []
    for _ in range(n):
        sorted_word = ''.join(sorted(input()))
        words_list.append(sorted_word)
    words_set = set(words_list)

    anagram_pair_count = 0
    for word in words_set:
        same_word_count = words_list.count(word)
        if same_word_count > 1:
            anagram_pair_count += misc.comb(same_word_count, 2, exact=True)

    print(anagram_pair_count)

    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8


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


def main():

    n = int(input())

    words_list = []
    for _ in range(n):
        sorted_word = ''.join(sorted(input()))
        words_list.append(sorted_word)
    words_set = set(words_list)

    anagram_pair_count = 0
    for word in words_set:
        same_word_count = words_list.count(word)
        if same_word_count > 1:
            anagram_pair_count += cmb(same_word_count, 2)

    print(anagram_pair_count)

    return 0


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools
from math import factorial


def combination_count(n, r):
    if (n - r) < 0:
        return 0
    return factorial(n) // (factorial(r) * factorial(n - r))

def main():

    n = int(input())
    
    words_list = []
    for _ in range(n):
        sorted_word = ''.join(sorted(input()))
        words_list.append(sorted_word)
    words_set = set(words_list)

    anagram_pair_count_all = 0
    for word in words_set:
        same_word_count = words_list.count(word)
        anagram_pair_count_all += combination_count(same_word_count, 2)

    print(anagram_pair_count_all)

    return 0
    
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8

def main():
    
  import math
  n = int(input())
  myset = set()
  mylist = list()
  mylist2 = list()
  
  for _ in range(n):
    sent = sorted(input())

    myset.add(''.join(sent))
    mylist.append(''.join(sent))
    
  for i in myset:
      a = mylist.count(i)
      if a >= 2:
          mylist2.append(math.factorial(a)//(math.factorial(a-2)*2))
      
      else:
          mylist2.append(0)
  
  print(sum(mylist2))
  
  return 0


if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for _ in range(n):
    x=list(input())
    x.sort()
    x="".join(x)
    s.append(x)
cnt=0
for _ in range(n):
    a=s.pop(-1)
    for i in s:
      if i==a:
        cnt += 1
    else:
        pass
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = []
scount = [1]
sinputlist = sorted(list(input()))
s = sinputlist[0]
for a in sinputlist[1:]:
    s += a
slist.append(s)
c = 0
for i in range(n-1):
    lastc = c
    sinputlist = sorted(list(input()))
    s = sinputlist[0]
    for a in sinputlist[1:]:
        s += a
    for j in range(len(slist)):
        if s == slist[j]:
            c += scount[j]
            scount[j] += 1
    if c == lastc:
        slist.append(s)
        scount.append(1)
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = []
sinputlist = sorted(list(input()))
s = sinputlist[0]
for a in sinputlist[1:]:
    s += a
slist.append(s)
c = 0
for i in range(n-1):
    lastc = c
    sinputlist = sorted(list(input()))
    s = sinputlist[0]
    for a in sinputlist[1:]:
        s += a
    for b in slist:
        if s == b:
            c += 1
    #if c == lastc:
    slist.append(s)
print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
l = [input() for i in range(n)]
cnt = 0

for x,y in itertools.combinations(l,2):
  
  lx = sorted(x)
  ly = sorted(y)
  if lx == ly:
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[list(input()) for _ in range(n)]
Ds=[]
cnt=0; c=0
for s in S:
    d={}
    for t in s:
        if t not in d.keys(): d[t]=1
        else: d[t]+=1
    Ds.append(d)

for i in range(n):
    for j in range(i+1,n):
        if i==j: continue
        for k in Ds[i].keys():
            if k not in Ds[j].keys():c=0; break
            if Ds[i][k]!=Ds[j][k]:c=0; break
            c=1
        if c==1: cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

ss.sort()

ans = 0
while len(ss) != 0:
    f = ss.pop(0)
    c = 1
    while len(ss) > 0:
        d = ss[0]
        if f == d:
            ss.pop(0)
            ans += c
            c += 1
        else:
            break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = [[""]]*n
for i in range(n):
    s = list(input())
    s.sort()
    ss[i] = s

def annagram(s1, s2):
    for i in range(10):
        if s1[i] != s2[i]:
            return False
    return True


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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

A = []
B = []
for i in range(n):
    s  = "".join(list(sorted(list(input())))) 
    if s not in A:
        A.append(s)
        B.append(1)
    else:
        B[A.index(s)] += 1
c = 0
for i in B:
    if i >= 2:
        c += int(i * (i - 1)/2)
print(c)

Submission status: Time Limit Exceeded

Solution code:
def sigma(n):
    return (n+1) * n//2 if n % 2 == 0 else sigma(n-1)+n

n = int(input())
Ss = [sorted(input()) for _ in range(n)]
Ss.sort()
src = []
ans = 0
for i in range(n):
    if(src == Ss[i]):
        continue
    else:
        src = [] 
    if not src:
        ans += sigma(Ss.count(Ss[i])-1)
        src = Ss[i]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
moji = []
moji_s = [[0 for i in range(26)] for j in range(n)]
for i in range(n):
    m = input()
    ans = dict(collections.Counter(m))
    moji.append(ans)
    for j in ans:
        moji_s[i][ord(j)-97] = ans[j]
#ここまででそれぞれの文字列の文字の出現回数を辞書型にまとめたものがリストに格納された
count = 0
count_ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        if moji_s[i]==moji_s[j]:
            count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
s=["".join(sorted(i)) for i in s]
cnt=0
for i in range(n):
    cnt+=s[i+1:].count(s[i])
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 = sorted(input())
    if s in S:
        ans += S.count(s)

    S.append(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = [str(sorted(input())) for _ in range(N)]
count = 0
for i in range(N):
  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
n = int(input())
d = []
s = [input() for _ in range(n)]
ans = 0
for x in s:
    d.append(collections.Counter(list(x)))

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

Submission status: Time Limit Exceeded

Solution code:
cnt = 0
n = int(input())
S = []
for i in range(n):
    s = list(input())
    s.sort()
    S.append(s)
    cnt += S.count(S[i])-1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools


n = int(input())
S = []
for i in range(n):
    s = list(input())
    s.sort()
    S.append(s)
cnt = 0
for v in itertools.combinations(S, 2):
    if v[0] == v[1]:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

n=int(input())
x=[]
cnt=0
for i in range(n):
  a=sorted(input())
  x.append(a)
  cnt+=x.count(a)-1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
x=[]
cnt=0
for i in range(n):
  a=sorted(input())
  x.append(a)
  cnt+=x.count(a)-1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ 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)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = []
count = 0
for i in range(n):
    x = sorted(input())
    ans.append(x)
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())
hantei_list = [1 for _ in range(n)]
moji_list = [str(input()) for _ in range(n)]
prime_number = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101]
for i in range(n):
  for j in range(10):
    hantei_list[i] *= prime_number[ord(moji_list[i][j])- ord('a')]

unique = set(hantei_list)

counter = 0
for i in unique:
  temp = hantei_list.count(i)
  counter += temp * (temp - 1) * 0.5 
print(int(counter))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []

for i in range(N):
  s.append(input())
ans = 0
for i in range(N-1):
  hikaku1 = list(s[i])
  hikaku1.sort()
  for j in range(i+1, N):
    hikaku2 = list(s[j])
    hikaku2.sort()
    if hikaku1 == hikaku2:
      ans += 1
print(ans)