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:
from itertools import permutations, combinations
n = int(input())
s = []
for _ in range(n):
  s.append(input())

ilist = []
for a in range(len(s)):
  ilist.append(list(s[a]))
  a += 1
#print(ilist)
li = list(combinations(ilist, 2))
trial = len(li)#何回比較するか求める
ans = 0 #answer
for b in range(len(li)):
  li[b][0].sort()
  li[b][1].sort()
  if(li[b][0] == li[b][1]):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import math

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

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

[s[i].sort() for i in range(len(s))]

cnt = 0
for i in s:
    for j in s:
       if i == j:
        cnt += 1
cnt = (cnt - N)//2

# c = collections.Counter(s)
s = [' '.join(s[i]) for i in range(len(s))]
mycounter = Counter(s)
mycounter = list(mycounter.values())

mycounter = [mycounter[i] for i in range(len(mycounter)) if mycounter[i] > 1]
mycounter = [combinations_count(mycounter[i], 2) for i in range(len(mycounter))]


print(sum(mycounter))

Submission status: Time Limit Exceeded

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

su=[]
for i in s:
    shu=sorted(list(i))
    su.append("".join(shu))


count=0
while len(su)>0:
  j=su[0]
  del su[0]
  c=su.count(j)+1
  count+=c*(c-1)/2
  su=[i for i in su if i!=j]
  
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
s = [input() for i in range(N)]
count = 0
for i in range(N):
    for a in range(i+1,N):
        if sorted(s[i]) == sorted(s[a]):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
slist=[]
ans=0
for s in range(N):
	slist+=[input()]
def ana(n,m):
	x=list(n)
	y=list(m)
	x.sort()
	y.sort()

	if x==y:return 1
	else:return 0

for p in range(N):
	for q in range(p+1,N):
		ans+=ana(slist[p],slist[q])
		
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    for d in range(N-1-i):
        j = i + d + 1
        s1 = [c for c in slist[i]]
        s2 = [c for c in slist[j]]
        flag = True
        for k in range(10):
            if s1.count(s1[k]) != s2.count(s1[k]):
                flag = False
        if flag:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
a = sys.stdin.readlines()

n = int(a[0])
ans = 0
now = 1

for i in a[1:n+1]:
    for j in a[now+1:n+1]:
        if sorted(i) == sorted(j):
            ans += 1
    now = now + 1

print(ans)

Submission status: Time Limit Exceeded

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

counter = 0
check = 0

for i in range(N-1):
    for j in range(i+1, N):
        n1 = [0] * 26
        n2 = [0] * 26
        check = 0
        for l in range(26):
            for c in str[i]:
                if ord(c) == ord('a') + l: n1[l] += 1
            for c in str[j]:
                if ord(c) == ord('a') + l: n2[l] += 1
        for k in range(26):
            if n1[k] != n2[k]: check=1
        if check==0: counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = [''.join(sorted(input())) for _ in range(n)]
s_set = set(s_list)
cnt = 0
for s in s_set:
    cnt += sum(range(s_list.count(s)))
print(cnt)

Submission status: Time Limit Exceeded

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

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

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from collections import Counter
import math

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

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

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

ans = 0
# n! で間に合わない
#for si, sj in combinations(cs, 2):
#    if si == sj:
#        ans += 1

# for i in range(len(cs)):
#     for j in range(i+1, len(cs)):
#         if cs[i] == cs[j]:

tmp = cs
# fromix = 1
while len(tmp) != 0:
    del_ix = []
    check = tmp[0]

    num = 0
    for acc in range(len(tmp)-1, 0, -1):
        if check == tmp[acc]:
            num += 1
            del_ix.append(acc)

    del_ix.append(0)
    # calc
    # print("for check:", check)
    # print("found:", num)
    if num == 0:
        pass
    elif num == 1:
        ans += 1
    else:
        ans += (math.factorial(num+1)//math.factorial(num+1-2))//math.factorial(2)

    # remove
    for l in del_ix:
        # print(l)
        # print(tmp)
        del tmp[l]

# print("ans")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
num = []
num_list = []
count_list = []
num_list_counter = 0
count = 0

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

    if num_list_counter == 0:
        num_list.append(num)
        count_list.append(1)
        num_list_counter += 1
    else:
        judge = 0
        for j in range(num_list_counter):
            if num_list[j] == num:
                judge = 1
                count += count_list[j]
                count_list[j] += 1
        if judge == 0:
            num_list_counter += 1
            num_list.append(num)
            count_list.append(1)

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
a = []
import collections
for i in range(len(s)):
    a.append(collections.Counter(s[i]))
count = 0
for i in range(len(a)):
    for j in range(len(a)):
        if i<j and a[i] == a[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def f(si, sj):
    for i in range(10):
        if si.count(sj[i]) != sj.count(sj[i]):
            return 0
    return 1
n = int(input())
s = [input() for i in range(n)]
x = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        x = x + f(s[i], s[j])
print(x)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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



ans = 0
i = 0
j = 1
cnt = 0
while i < N:
    cnt = 0

    if matched[i] == True:
        if i >= N-1:
            break
        
        i += 1
        j = i+1
        continue

    si = Counter(s[i])
    while j <= N-1:

        if matched[j] == True:
            j += 1

            continue


        sj = Counter(s[j])
        if si == sj:
            matched[i] = True
            matched[j] = True
            cnt += 1
        j += 1
    
    if cnt != 0:
        ans += cmb(cnt+1,2)

    if i == N-2:
        break

    i += 1
    j = i+1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
my_list = [None] * N
for i in range(N):
    s_i = sorted(list(input()))
    my_list[i] = s_i
sum = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if my_list[i] == my_list[j]:
            sum += 1
print(sum)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
A=[]
for I in range(n):
  moji=list(input())
  moji.sort()
  moji=''.join(moji)
  A.append(moji)
N=0
for i in range(n):
  a=A[i]
  for s in range(i+1,n,1):
    b=A[s]
    if a==b:
      N+=1
print(N)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
t = [str(input()) for i in range(N)]
for i in range(N):
    t[i] = list(t[i])
from collections import Counter
for i in range(N):
    t[i] = Counter(list(t[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:
import collections

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

# set_s_l = set(s_l)
# if len(s_l) == len(set_s_l):
#         print(0)
# else:
#         l = []
#         for val in set_s_l:
#                 l.append(s_l.count(val))
#         for i in l:
#                 if i > 1:
#                         if i == 2:
#                                 cnt += 1
#                         elif i == 3:
#                                 cnt +=i
#                         else:
#                                 cnt += c(i,2)
#         print(cnt)
set_s_l = set(s_l)
if len(s_l) == len(set_s_l):
        print(0)
else:
        for i in range(n):
                for j in range(1,n-i):
                        if s_l[i] == s_l[i+j]:
                                cnt += 1
        print(cnt)
# 0 1 2 3 4
#     2

Submission status: Time Limit Exceeded

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

N = int(input())
s_list = []
s_dup = []
for i in range(N):
    s_in = sorted(list(input()))
    if s_in not in s_list:
        s_list.append(sorted(s_in))
        s_dup.append(0)
    else:
        idx = s_list.index(s_in)
        s_dup[idx] += 1
count = 0
for value in s_dup:
    if value >= 1:
        count += value * (value+1) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[]
A=0

for i in range(N):
  d=''.join(sorted(str(input())))
  if d in L:
    A+=L.count(d)
  L.append(d)

print(A)

Submission status: Time Limit Exceeded

Solution code:
import collections

result=0
H = int(input())
S = []
for _ in range(H):
    S.append(collections.Counter(tuple(input())))  

for j in range(H):
    for i in range(j,H):
        if not i == j:
            if S[j] == S[i]:
                result += 1

print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(''.join(sorted(input())))
for i in range(n):
    for j in range(n):
        if i<j:
            if s[i]==s[j]:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import math

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

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

S_ = S[:]
S_ = set(S_)

c = 0

for i in S_:
    a = S.count(i)
    if a == 1 :
        continue
    ans = combinations_count(a, 2)
    c += int(ans)

print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

s = []
check = []
ans = 0
# for x in range(N):
#     for c in input():
#         s[x].append(c)

for _ in range(N):
    s.append(input())
for x in s:
    check.append(Counter(x))

while check:
    cc = check.pop(0)
    ans += check.count(cc)


print(ans)

Submission status: Time Limit Exceeded

Solution code:

def create_count_dic(text):
    count_dic = {}
    for t in text:
        if t in count_dic:
            count_dic[t] += 1
        else:
            count_dic[t] = 1
    return count_dic

def is_anagram(text1, text2):
    text1_dic = create_count_dic(text1)
    text2_dic = create_count_dic(text2)
    if text1_dic == text2_dic:
        return True
    else:
        return False

N = int(input())
S = [input() for x in range(N)]
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

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

alp=[chr(_) for _ in range(97,97+26)]
res=[0]
res2=[0]
ans=0

for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    tmp2=0
    for z in range(len(res)):
        if aa==res[z]:
            tmp2+=res2[z]
            res2[z]+=1
    if tmp2==0:
        res.append(aa)
        res2.append(1)
    ans+=tmp2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
  SS = str(input())
  m = list(SS)
  m.sort()
  s.append(m)
s.sort()
ans = 0
for i in range(len(s)-1):
  for j in range(i+1,len(s)):
    if(s[i][0]==s[j][0]):
      if(s[i][1]==s[j][1]):
        if(s[i][2]==s[j][2]):
          if(s[i][3]==s[j][3]):
            if(s[i][4]==s[j][4]):
              if(s[i][5]==s[j][5]):
                if(s[i][6]==s[j][6]):
                  if(s[i][7]==s[j][7]):
                    if(s[i][8]==s[j][8]):
                      if(s[i][9]==s[j][9]):
                        ans += 1
                      else:
                        break
                    else:
                      break
                  else:
                    break
                else:
                  break
              else:
                break
            else:
              break
          else:
            break
        else:
          break
      else:
        break
    else:
      break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = [sorted(list(input())) for i in range(N)]
count = []
while len(s)>0:
    c = 0
    cc = []
    for i in range(0,len(s)):
        if s[0]==s[i]:
            c += 1
            cc.append(i)
    count.append(c)
    if len(cc)==0: cc.append(0)
    for i in cc[::-1]:
        del s[i]

ans = 0

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

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    ls = []
    count = 0
    for i in range(n):
        inp = count_letter(input())

        for item in ls:
            if all(inp[key] == item.get(key) for key in inp):
                count += 1
        ls.append(inp)
    print(count)


def count_letter(string):
    count = {}
    for i in string:
        if count.get(i) is None:
            count[i] = 1
        else:
            count[i] += 1
    return count


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

n=int(input())
string_list=[]

for _ in range(n):
	rel = sorted(list(input()))
	string_list.append(''.join(rel))
    
string_distinct = set(string_list)
idx = 0
for item in string_distinct:
	s_count = string_list.count(item)
	if s_count > 1:
		idx += factorial(s_count) // factorial(2) // factorial(s_count - 2)
print(idx)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

ans = 0
N = int(input())

S = list()
for n in range(N):
  S.append(sorted(Counter(input()).items(), key=lambda x:x[0]))

ans = sum([S[i]==S[j] for (i, j) in combinations(range(N), 2)])
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
a = sys.stdin.readlines()



n = int(a[0])
ans = 0
now = 1

for i in a[1:n+1]:
    for j in a[now+1:n+1]:
        if sorted(i) == sorted(j):
            ans += 1
    now = now + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

def main():
    n = int(input())
    c = []
    count = 0
    lists =[]

    for num in range(n):
        c.append(''.join(sorted(input())))

    for i in c:
        if i in lists:
            count = count + lists.count(i)
            lists.append(i)
        else:
            lists.append(i)

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:


import math
import itertools


def str_sort(s):
    return ''.join(sorted(s))
    
def combinations_count(n, r):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def is_anagram(s_1, s_2, d):
    if d[s_1] != d[s_2]: return False

    for c in set(s_1):
        char_count_1 = s_1.count(c)
        char_count_2 = s_2.count(c)
        if char_count_1 != char_count_2:
            return False

    return True

def make_char_num_dict(S):
    d={}
    for s in S:
        d[s] = len(set(s))
    return d 




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


d = make_char_num_dict(S)

"""
s_list = list(itertools.combinations(S, 2))
ans = 0
for s_l in s_list:
    s_1 = s_l[0]
    s_2 = s_l[1]

    if is_anagram(s_1, s_2, d) == True:
        ans += 1

print(ans)
"""


ans = 0
for i in range(len(S)):
    s_1 = S[i]
    for j in range(i+1, len(S)):
        s_2 = S[j]
        if is_anagram(s_1, s_2, d) == True:
            ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
  s[i] = ''.join(map(str, sorted(s[i])))

s = sorted(s)

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
for i in range(n):
  w = str(input())
  kusa = list(w)
  kusa.sort()
  lis.append(kusa)
counter = 0
while len(lis):
  d=lis[0]
  m = lis.count(d)
  counter += (m*(m-1))//2
  for i in range(m):
    lis.remove(d)
print(counter)

Submission status: Time Limit Exceeded

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

import bisect

N = int(input())
s = []
for i in range(N):
    c = input()
    c = list(c)
    c.sort()
    bisect.insort_left(s,c)

count = 0
while len(s) > 0:
    point = bisect.bisect_left(s, s[-1])
    a = len(s) - point
    b = a * (a - 1) / 2
    count += int(b)
    s = s[:point]

print(count)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce
 
def nCr(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

def conv(st):
    res = [0]*26
    for s in st:
        res[ord(s)-ord('a')] += 1
    return ''.join(map(str,res))

N = int(input())
S = [conv(input()) for _ in range(N)]
setS = set(S)
res = 0
for s in setS:
    cnt = S.count(s)
    if cnt > 1:
        res += nCr(cnt, 2)
print(res)

Submission status: Time Limit Exceeded

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

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

total=int((count-N)/2)
  
  
print(total)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
word_list = []
ans = 0
condition = True

for i in range(0, n):
  word_list.append(sorted(list(input())))
  
while condition:
  c = word_list.count(word_list[0])
  ans += int(c * (c-1)/2)
  word_list = [i for i in word_list if word_list[0] != i]
  if len(word_list) <= 1:
    condition = False

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N   =   int(input())

counter     =   0


A = []

for i in range(26):
    A.append([])




for i in range(N):
    S   =   input()
    S   = list(S)
    S.sort()
    point   =   ord(S[0]) - ord('a')

    for j in range(len(A[point])):
        if(A[point][j] == S):
            counter += 1
            continue
    A[point].append(S)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

n = int(input())
lists = [str(input()) for i in range(n)]

lists2 = ["".join(sorted(i)) for i in lists]
l = collections.Counter(lists2)
c = l.values()

list3 = [itertools.combinations(range(i),2) for i in c]

print(len([e for inner_list in list3 for e in inner_list]))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 10 21:22:42 2019

@author: doppe
"""
import copy
import math


def isAnagram(dict, str2):
    dictCopy = copy.copy(dict)
    for c2 in str2:
        if (c2 in dictCopy):
            dictCopy[c2] -= 1
            if (dictCopy[c2] < 0):
                return False
        else:
            return False
    return True
 
def makeDict(str1):
    dict = {}
    for c in str1:
        if (c in dict):
            dict[c] += 1
        else:
            dict[c] = 1
    return dict

A = int(input())
S = []
for i in range (0, A):
    S.append(input())

ans = 0
groupList = []
groupDict = {}
for i in range(0, len(S)):
    if (i in groupList):
        continue
    dict = makeDict(S[i])
    for j in range(i + 1, len(S)):
        if (j in groupList):
            continue
        if (isAnagram(dict, S[j])):
            groupList.append(j)
            if (S[i] in groupDict):
                groupDict[S[i]] += 1
            else:
                groupDict[S[i]] = 2

for v in groupDict.values():
    ans += (v * (v - 1)) / 2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
str = input()
N = int(str.split()[0])
d = []
for i in range(N) :
	s = str = input()
	dict = {}
	for j in range(26):
		dict[j] = 0
	for j in range(10) :
		k = ord(s[j]) - ord("a")
		dict[k] = dict[k] + 1
	d.append(dict)
	
E = 0
while(len(d) != 0) :
	deli = []
	for i in range(1, len(d)) :
		f = 0
		for j in range(26):
			if (d[0][j] != d[i][j]) :
				f = 1
				break
		if (f != 1) :
			deli.append(i)
	a = 0
	while(len(deli) != 0) :
		d.pop(deli[0] - a)
		deli.pop(0)
		a = a + 1
	if (len(d) != 0) :
		if (a != 0) :
			E = E + (a + 1) * a / 2
		d.pop(0)
print(int(E))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
# 文字列内の文字を辞書順ソート
strings = [''.join(sorted(list(input()))) for i in range(n)]
# 重複文字列（＝元の文字列はアナグラムで一致する）と重複度の辞書
dictionaries = [[e, strings.count(e)] for e in set(strings)]
sum = 0
for d in dictionaries :
    q = d[1]
    sum += int(q * (q-1) / 2)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
def f(si, sj):
    for i in range(10):
        if si.count(sj[i]) != sj.count(sj[i]):
            return 0
    return 1
n = int(input())
s = [input() for i in range(n)]
x = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        x = x + f(s[i], s[j])
print(x)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))

c = collections.Counter(L)

for i in c.values():    
    ans += len(list(itertools.combinations(range(i), 2)))

print(int(ans))

Submission status: Time Limit Exceeded

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

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

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 i in range(N):
    s.append(sorted(input()))

c = [s[i+1:].count(elm) for i, elm in enumerate(s)]
    

print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
dicts = []
dicts.append([collections.Counter(input()), 1])
for i in range(1,n):
    get = collections.Counter(input())
    for k, v in enumerate(dicts):
        if v[0] == get:
            dicts[k][1] += 1
            break
    else:
        dicts.append([get, 1])

kotae = 0
for d in dicts:
    kotae += (d[1]*(d[1]-1)) // 2

print(kotae)

Submission status: Time Limit Exceeded

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

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

#print(s)

s_list = [[] for _ in range(n)]
for i in range(n):
    #listに格納
    for j in range(10):
        s_list[i].append(s[i][j])
    #ソートをかける
    s_list[i].sort()

count = 0

#s_listの要素（リスト）について、
#他の要素と同一のものがあるかチェック
for i in range(n):
    for j in range(i+1, n):
        c = (s_list[i] == s_list[j])
        if c == True:
           count += 1
           
print(count)

#重複を削除して要素数カウント

Submission status: Time Limit Exceeded

Solution code:
import collections

N = int(input())
s = []
count_s = []
for _ in range(N):
    s.append(input())
    count_s.append(collections.Counter(s[_]))

duplication = 0
output = 0

for i in range(N):

    for j in range(duplication, N):
        if i != j:
            if count_s[i] == count_s[j]:
                output += 1
    duplication += 1

print(output)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(str(input()) for i in range(n))
gou = []
count = 0
for g in range(len(li)):
    lis = []
    for k in range(len(li[g])):
        lis.append(li[g][k])
    lis.sort()
    gou.append(lis)
for p in range(len(gou)):
    for u in range(len(gou)):
        if gou[p] == gou[u] and p!=u:
            count += 1
print(count//2)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
ans = 0
s = []
N = int(input())
for i in range(N):
	tmp = []
	string = input()
	for st in string:
		tmp.append(st)
	s.append(tmp)
 
for m in range(len(s)):
	for n in range(len(s)):
		if Counter(s[n])==Counter(s[m]) and s[m] != s[n]:
			ans+=1
print(int(ans/2))

Submission status: Time Limit Exceeded

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

for _ in range(N):
  s.append(str(input()))
  
cnt = 0
for i in range(N):
  delete = []
  s1 = s.pop()
  s1list = list(s1)
  same = 1
  
  for j in range(len(s)-1, -1, -1):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      delete.append(s2)
      same += 1
  if same != 1:
    cnt += same * (same - 1) / 2
  for x in delete:
    s.remove(x)
  if not s:
    break
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
def C():
    N = int(input())

    literals = []

    for i in range(N):
        word_vec = [0]*26
        word = input()
        for char in word:
            word_vec[ord(char) - 97] += 1
        literals.append(word_vec)

    answer = 0
    for i in range(N):
        target = literals.pop()
        answer += literals.count(target)

    print(answer)

if __name__ == '__main__':
  C()

Submission status: Time Limit Exceeded

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

## a-zの文字が各文字列でそれぞれ何度出てくるか数える
## 26要素を持つリストが複数できて、リストの中身の完全一致回数を求める

AtoZlist = [chr(i) for i in range(97,97+26)]
countlist = []
for l in range(N):
    countlist.append([])

for i in AtoZlist:
    for k in S:
        ci = k.count(i)
        countk = S.index(k)
        countlist[countk].append(ci)

answer = 0
for x in range(N):
    for y in range(x+1,N):
        if countlist[x] == countlist[y]:
            answer += 1

print(answer)