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

li2 = []
for i in range(len(li)):
    li2.append(li.count(li[i]))

li3 = list(set(li2))

from fractions import Fraction

def comb(n, k):
    
    if n < 0 or k < 0:
        pdt = 0
    
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)
    
    return pdt.numerator
num = 0   
for i in range(len(li3)):
    num += comb(li3[i],2)

print(num)

Submission status: Time Limit Exceeded

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

sn = []
count = 0

for i in range(n):
  sn.append(sorted(Counter(list(input())).items()))


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

Submission status: Time Limit Exceeded

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

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

ans = 0

sorted(s)

l = len(s)

for ss in range(0, l):
    for sss in range(ss+1, l):

        if s[ss] == s[sss]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
# k,x = map(int,input().split())
s_l = []
for i in range(n):
        s_l.append(input())

for i in range(n):
        a = ''
        for x in sorted(s_l[i]):
                a += x
        s_l[i] = a

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

Submission status: Time Limit Exceeded

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

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

for i in range(len(ln)):
    for j in range(i+1,len(ln)):
        if ln[i] == ln[j]:
            ans += 1
            continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
dicts = {}
for _ in range(K):
    string = str(sorted(input()))
    if string in dicts:
        dicts[string] += 1
    else:
        dicts[string] = 1

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

answer = 0
for v in dicts.values():
    if v > 1:
        answer += calc_pairs(v)
    
print(answer)

Submission status: Time Limit Exceeded

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

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

def count_c(s):
    count_list = [0]*26
    for c in s:
        count_list[ab_dict[c]] += 1
    return count_list

sc_list = []
for s in s_list:
    sc_list.append(count_c(s))

ans = 0
for i,sc in enumerate(sc_list):
    for sc2 in sc_list[i+1:]:
        if sc == sc2:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# 3

N = int(input())
s = []
cnt = 0

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

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(' ', ''))
 
  global ana
  if get_counter(first_word) == get_counter(second_word):
    ana = ana + 1

ana = 0
N = int(input())
S = []
for _ in range(N):
  S.append(str(input()))

for i in range(N):
  for j in range(N):
    verify_anagrams(S[i],S[j])

Ans = int((ana - N)/2)
print(Ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
all = []
count = []
for i in range(N):
  count.append(collections.Counter(list(input())))
nsame = 0
for i in range(N):
  for j in range(i+1, N):
    if count[i] == count[j]:
      nsame = nsame + 1
print(nsame)

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

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

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

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

chars = []
for s in S:
    char_list = []
    for char in s:
        char_list.append(char)
    char_list.sort()
    chars.append(char_list)
#  print(chars)
ans = 0
done_list = []
for char in chars:
    #  print('char' , char)
    if char in done_list:
        continue

    cnt = chars.count(char)
    if cnt == 1:
        continue
    done_list.append(char)
    ans += combinations_count(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,*s=open(0).read().split()
s = ["".join(sorted(s_)) for s_ in s]
cnt = 0
for i in range(len(s)):
  cnt += (s.count(s[0])-1)
  s.pop(0)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
from collections import defaultdict

N=input()

fact= [1]
fact_tmp = 1
for i in range(1, N+1):
    fact_tmp *= i
    fact.append(fact_tmp) 
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n]/fact[r]/fact[n-r])

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

for i in C.values():
	ans+=ncr(i,2)

print ans

Submission status: Time Limit Exceeded

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

dics = []
for w in ws:
    d = {}
    for c in w:
        if c in d.keys():
            d[c] += 1
        else:
            d[c] = 1
    dics.append(d)

r = 0
for i in range(n):
    for j in range(n):
        if j <= i:
            continue
        if dics[i] == dics[j]:
            r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())

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

S=sorted(S)
total=0
for i in range(len(S)):
    key=S[i]
    for j in range(i+1,N):
        if key==S[j]:
            total+=1
        else:
            break

print(total)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter as counter

N = int(input())
char_counts = [counter(input()) for i in range(N)]
match_count = 0
for i, c in enumerate(char_counts):
  for j in range(i, N, 1):
    if i == j:
      continue
    if char_counts[j] == c:
      match_count += 1
print(match_count)

Submission status: Time Limit Exceeded

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

c = 0

def let_dic(s) :
    d = {}
    for i in [chr(k) for k in range(97, 97+26)] :
        d[i] = s.count(i)
    return d

ls_dic = []
for i in range(n) :
    ls_dic.append(let_dic(ls_str[i]))

for i in range(n-1) : # 0 to n-2
    for j in range(i+1,n) : # i+1 to n-1
        if ls_dic[i]==ls_dic[j] :
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for i in range(N):
    temp = input()
    val = [0 for k in range(26)]
    for j in range(10):
        val[ord(temp[j])-97] += 1
    S.append(val)

kind = [S[0]]
cnt = [1]
lenkind = 1
for i in range(1, N):
    flg = 0
    for j in range(lenkind):
        if S[i] == kind[j]:
            cnt[j] += 1
            flg = 1
            break
    if flg == 0:
        kind.append(S[i])
        cnt.append(1)
        lenkind += 1

ans = 0
for i in range(lenkind):
    temp = cnt[i]
    ans += (temp*(temp-1) // 2)
print(str(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
import fractions
import re
import math

from collections import Counter
 
def va(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
    return get_counter(first_word) == get_counter(second_word)
def resolve():
    N = int(input())
    S = list(input() for _ in range(N))
    count = 0
    for C in itertools.combinations(range(N),2):
        if va(S[C[0]],S[C[1]]) == True:
            count += 1
    print(count)

    
resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for i in range(N):
    S_tmp = str(input())
    S_tmp = list(S_tmp)
    S_tmp.sort()
    S.append("".join(S_tmp))

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
count = 0
for i in range(n):
    sli = sorted(list(input()))
    s = "".join(sli)
    if s in li:
        count += li.count(s)
    li.append(s)
print(count)

Submission status: Time Limit Exceeded

Solution code:
# C
from collections import Counter
 
def ana(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 = []*n
for i in range(n): s.append(input()) 

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

Submission status: Time Limit Exceeded

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

a = ["a" for i in range(N) for j in range(N-i-1) if S[i] == S[i+j+1]]
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
import collections
N=int(input())
s=[]
for _ in range(N):
    s.append(str(collections.Counter(sorted(list(input())))))

print(int(sum(list(map(lambda x: x*(x-1)/2*1, list(collections.Counter(s).values()))))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
S = [hash(''.join(sorted(input()))) for _ in range(n)]
T = set(S)
c = []

for i in T:
    c.append(S.count(i))
            
for j in c:
    ans += (j * (j-1) // 2)
print(ans)

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)
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())
words = [input() for _ in range(N)]
ans = 0
while True:
    if not words:
        break
    target = words.pop(0)
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_anagrams(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)

print(ans)

Submission status: Time Limit Exceeded

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

from collections import Counter

s_multisets = []
for i in range(N):
    s_multisets.append(Counter(s[i]))

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

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
S = [collections.Counter(list(input())) for _ in range(0, N)]
result = 0
for i, s in enumerate(S):
    for j in range(i + 1, len(S)):
        if s == S[j]:
            result += 1
print(result)

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 = []
ans = 0
cnt = 0
for i in range(n):
  s.append(str(input()))
  #print("append :",s[i])
  for j in range(cnt):
    #print("{} vs {}".format(s[i],s[j]))
    if verify_anagrams(s[i],s[j]):
      ans += 1
  cnt +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
chars = 'abcdefghijklmnopqrstuvwxyz'

for i in range(N):
    s = input()
    S.append(int(''.join([str(s.count(a)) for a in chars])))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

count = 0

n = int(input())

word_list = []
words = []

for i in range(n):
    word_list.append(input())

for i in range(n):
    c = collections.Counter(word_list[i])
    words.append(sorted(list(c.items())))

l = list(range(n))
d = list(itertools.combinations(l, 2))

for i, j in d:
    if words[i] == words[j]:
        count += 1


print(count)

Submission status: Time Limit Exceeded

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

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

count = 0
for j in range(n-1):                                                                                                                                                                                        
    for k in range(j+1, n):                                                                                                                                                                                   
        if C[j].items() == C[k].items():                                                                                                                                                                    
            count += 1                                                                                                                                                                                      

print(count)

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)
lst =[]
N = int(input())
for i in range(N):
    s = input() 
    lst.append(s)
c=0
for i in range(N-1):
    for j in range(i + 1, N):
        flg = verify_anagrams(lst[i], lst[j])
        if flg == True:
            c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
import copy

n = int(input())
#k, x = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#s = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#dp = [[0 for _ in range(2)] for _ in range(13)]
s = [input() for i in range(n)]

for i in range(n):
    moji = list(map(lambda x:x, s[i]))
    moji.sort()
    s[i] = moji

s.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:
def f(x):
    return ord(x) - ord('a')


N = int(input())
cnts = [[0] * 26 for _ in range(N)]

for i in range(N):
    for c in input():
        cnts[i][f(c)] += 1

res = 0
for i in range(N):
    for j in range(i + 1, N):
        chk = 1
        for k in range(26):
            if cnts[i][k] != cnts[j][k]:
                chk = 0
                break
        res += chk
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0

A = [["".join(sorted(input()))] for _ in range(n)]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
li = []
ans = 0
N = int(input())
for i in range(N):
    x = Counter(input())
    for j in li:
        if x == j:
            ans += 1
    li.append(x)

print(ans)

Submission status: Time Limit Exceeded

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

t=['']*n

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

cnt=0

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

print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
strs = sorted( strs )
for i in range( n ) :
	bFound = False
	for j in range( i+1, n ) :
		if strs[i] != strs[j] :
			break
		if strs[i] == strs[j] :
			count += 1
			bFound = True

print( count )

Submission status: Time Limit Exceeded

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

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

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

A = []
for i in range(N):
    a = input()
    a_counter = Counter(a).most_common()
    a_counter.sort(key = lambda x: x[1])
    a_counter.sort(key = lambda x: x[0])
    A.append(a_counter)
    
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())
a = [sorted(list(input())) for i in range(N)]
b = 0
for i in a:
 b = b + a.count(i) - 1
print(int(b / 2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

a = 0
for i in range(len(s)-1):
    for j in range(i+1, len(s)):
        if s[i] == s[j]: a = a+1
        else: break
print(a)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
  t=list(input())
  t.sort()
  l.append("".join(t))
l.sort()
length=len(l)
count=0
for i in range(length):
  a=0
  for j in range(i+1,length):
    if l[i]==l[j]:
      a=1
      count+=1
    if not l[i]==l[j] and a==1:
      break
print(count)

Submission status: Time Limit Exceeded

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

cnt = [0 for _ in range(N)]
for i in range(N-1):
    cnt_i = 0
    for j in range(i+1, N):
        if (cnt[j] != 0):
            continue
        if (s[i] == s[j]):
            cnt_i += 1
            cnt[j] = cnt_i

print(sum(cnt))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
s=[0 for _ in range(N)]
count=0
for i in range(N):
    s[i]=input()
for t in range(N):
    for i in range(N):
        if Counter(s[i])==Counter(s[t]):
            count+=1
print(int((count-N)/2))

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools


def p_c():
    n = int(input())
    l = []
    ans = 0

    for _ in range(n):
        l.append(collections.Counter(input()))

    for i in list(itertools.combinations(l, 2)):
        if i[0] == i[1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_c()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations

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

cs = [Counter(x) for x in s]
ccs = combinations(cs, 2)

ans = 0
for i in ccs:
    if i[0]==i[1]:
        ans +=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_li=[input() for i in range(n)]
ans = 0
for i in range(n):
  s=list(s_li[i])
  ss=sorted(s)
  for j in range(i+1,n):
    t = list(s_li[j])
    tt = sorted(t)
    if ss == tt:
      ans+= 1
print(ans)

Submission status: Time Limit Exceeded

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

ana = []
for i in range(n):
  alpha = {}
  for j in range(10):
    if alpha.get(str[i][j]) == None:
      alpha[str[i][j]] = 1
    else:
      alpha[str[i][j]] += 1
  ana.append(sorted(alpha.items(), key=lambda x:x[0]))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline


def main():
    n = int(input())
    s = [None] * n
    for i in range(n):
        s[i] = str(input()).replace("\n", "")

    ans = [None] * n
    index = 0
    for i in s:
        count_word = dict()
        sorted_word = list()
        for j in i:
            if not j in sorted_word:
                count_word[j] = i.count(j)
                sorted_word.append(j)

        ans[index] = count_word
        index += 1

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

    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
num = []
count = 0
for i in range(N):
    S.append(input())
    num.append(1)
    for j in range(S[i].count('a')):
        num[i] *= 103
    for j in range(S[i].count('b')):
        num[i] *= 107
    for j in range(S[i].count('c')):
        num[i] *= 109
    for j in range(S[i].count('d')):
        num[i] *= 113
    for j in range(S[i].count('e')):
        num[i] *= 127
    for j in range(S[i].count('f')):
        num[i] *= 2
    for j in range(S[i].count('1')):
        num[i] *= 3
    for j in range(S[i].count('h')):
        num[i] *= 5
    for j in range(S[i].count('i')):
        num[i] *= 7
    for j in range(S[i].count('j')):
        num[i] *= 11
    for j in range(S[i].count('k')):
        num[i] *= 13
    for j in range(S[i].count('l')):
        num[i] *= 17
    for j in range(S[i].count('m')):
        num[i] *= 19
    for j in range(S[i].count('n')):
        num[i] *= 23
    for j in range(S[i].count('o')):
        num[i] *= 29
    for j in range(S[i].count('p')):
        num[i] *= 31
    for j in range(S[i].count('q')):
        num[i] *= 37
    for j in range(S[i].count('r')):
        num[i] *= 41
    for j in range(S[i].count('s')):
        num[i] *= 43
    for j in range(S[i].count('t')):
        num[i] *= 47
    for j in range(S[i].count('u')):
        num[i] *= 73
    for j in range(S[i].count('v')):
        num[i] *= 79
    for j in range(S[i].count('w')):
        num[i] *= 83
    for j in range(S[i].count('x')):
        num[i] *= 89
    for j in range(S[i].count('y')):
        num[i] *= 97
    for j in range(S[i].count('z')):
        num[i] *= 101

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

print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = []
for _ in range(n):
    sl.append(input())
rl=[[0 for _ in range(26)] for _ in range(n)]
for i in range(n):
    for c in sl[i]:
        a=ord(c)-ord('a')
        rl[i][a]+=1
rslt=0
for i in range(n-1):
    for j in range(i+1,n):
        if rl[i] == rl[j]: rslt+=1
print(rslt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

my_list = [None] * N

for i in range(N):
    s_i = input()
    my_dict = {}
    for j in range(10):
        if s_i[j] in my_dict:
            my_dict[s_i[j]] += 1
        else:
            my_dict[s_i[j]] = 1
    my_dict = sorted(my_dict.items())
    my_list[i] = my_dict

sum = 0

for i in range(N):
    num = 0
    for j in range(i + 1, N):
        if my_list[i] == my_list[j]:
            num += 1
    sum += num

print(sum)

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

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

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#  counts = []
#  ex = [chr(ord('a') + i) for i in range(26)]
#  for s in S:
#      cnt = [0 for _ in range(26)]
#      for char in set(s):
#          cnt[ex.index(char)] = s.count(char)
#      counts.append(cnt)
#  #  print(counts)
#  done_list = []
#  ans = 0
#  for cnt in counts:
#      if cnt in done_list:
#          continue
    
#      # nC2 を計算
#      c = counts.count(cnt)
#      if c == 1:
#          continue
#      a = combinations_count(c, 2)
#      ans += a
#      done_list.append(cnt)

chars = []
for s in S:
    char_list = []
    for char in s:
        char_list.append(char)
    chars.append(sorted(char_list))
#  print(chars)
ans = 0
done_list = []
for char in chars:
    #  print('char' , char)
    if char in done_list:
        continue

    cnt = chars.count(char)
    if cnt == 1:
        continue
    done_list.append(char)
    ans += combinations_count(cnt, 2)
#  new_chars = []
#  for s in S:
#      tmp = sorted(list(set(s)))
#      chars = ''
#      for t in tmp:
#          chars = chars + s.count(t) * t
#      new_chars.append(chars)

#  tmp = list(set(new_chars))
#  ans = 0
#  for t in tmp:
#      cnt = new_chars.count(t)
#      if cnt == 1:
#          continue
#      ans += combinations_count(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dics = [0] * N
for i in range(N):
    s = input()
    count = 0
    dic = {}
    for k in list(s):
        v = dic.get(k, None)
        if v is not None:
            dic[k] = v + 1
        else:
            dic[k] = 1
    dics[i] = dic

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if dics[i] == dics[k]:
            result += 1

print(result)

Submission status: Time Limit Exceeded

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

while len(ss) != 0:
    target = ss[0]
    del ss[0]
    for s in ss:
        if sorted(s) == sorted(target):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

char = [chr(97+i) for i in range(26)]

r = 0

def getCount(s):
    return [s.count(c) for c in char]
    
for i in range(n):
    base = getCount(l[i])
    
    for j in range(i+1, n):
        target = getCount(l[j])
        anagram = True
        for a, b in zip(base, target):
            if not (a == b):
              anagram = False
              break
        if anagram:
            r += 1

print(r)

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))
s=sorted(s)
for j in range(N-1):
    for k in range(j+1,N):
        if s[j]==s[k]:
            cnt+=1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
all = []
count = []
for i in range(N):
  tmp = list(input())
  all.append(tmp.copy())
  count.append(collections.Counter(tmp))
nsame = 0
for i in range(N):
  for j in range(i+1, N):
    if count[i] == count[j]:
      nsame = nsame + 1
print(nsame)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lis=[]
ans=[]
for i in range(n):
    lis.append(input())
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=lis[i][j]
    ans[i].sort()

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

print(a)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())

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

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

print(total)