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:
def ToAscii( str_, digit ) :
	num = 0
	for i in range( digit ) :
		num += 100**(i) * ( ord( str_[i] )-96 )
	return num

n = int( input() )

judge_nums = []
for i in range( n ):
	judge_num = 10**27 # 一桁目はフェイク
	str_list = list( input() )
	for s in str_list :
		judge_num += 10**(ord( s )-97)
	judge_nums.append( judge_num )
judge_nums = sorted( judge_nums )


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

print( count )

Submission status: Time Limit Exceeded

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

ll=sorted(l)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
words = [Counter(input()) for _ in range(N)]
ans = 0
counters = []
counters_counts = []
for counter in words:
    try:
        idx = counters.index(counter)
        counters_counts[idx] += 1
    except ValueError:
        counters.append(counter)
        counters_counts.append(1)

for count in counters_counts:
    ans += int((count * (count-1)) / 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s_list = [str(input()) for i in range(n)]
    s_list_sorted = [ "".join(sorted(s)) for s in s_list]
    cnt = 0 
    for i in range(len(s_list_sorted)):
        s1 = s_list_sorted[i]
        for s2 in s_list_sorted[i+1:]:
            if s1 == s2:
                cnt += 1
    print(cnt)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = [''.join(sorted(list(input()))) for i in range(n)]


cnt = 0
for i in range(len(s)):
    d = collections.Counter()
    d.update(s[i+1:])
    cnt += d[s[i]]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = input()
n = int(n)
count = 0
word = []

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

for i in range(n - 1):    
    master = list(word[i])
    for j in range(i + 1, n):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while l < len(target):
                try:
                    if master[k] == target[l]:
                        target.pop(l)
                        break
                    l += 1
                except:
                    break
        if len(target) == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s_list=[]
u_list=[]
for i in range(n):
  s_elem=''.join(sorted(list(input())))
  s_list.append(s_elem)
  if s_list.count(s_elem) > 1:
    u_list.append(s_elem)

unq_list=list(set(u_list))
count=0

for j in range(len(unq_list)):
  match_n=s_list.count(unq_list[j])
  count+=sum(range(1, match_n))

print(count)

Submission status: Time Limit Exceeded

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

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

    pairs = 0
    sorted_num = list()
    for i in range(n):
        if i in sorted_num:
            continue
        count = 0
        for j in range(i + 1, n):
            if ans[i] == ans[j]:
                sorted_num.append(j)
                count += 1
        if count >= 2:
            pairs += int(count * (count - 1) / 2) + count
        else:
            pairs += count

    print(pairs)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    ls = []
    count = 0
    for i in range(n):
        inp = count_letter(input())
        count += ls.count(inp)
        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:
N = int(input()) 
s = [input() for i in range(N)]
LIS=[]
for i in range(N):
  LIS.append(sorted(s[i]))
n=0
for j in range(N):
  for h in range(j+1,N):
    if LIS[j]==LIS[h]:
      n+=1
    else:
      pass
print(n)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

a = []
for i in range(len(s)):
    a.append("".join(map(str, sorted(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:
N = int(input())
s = [sorted(input()) for i in range(N)]
count = 0
for n in range(N):
    for nn in range(n + 1, N):
        if s[n] == s[nn]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# C問題
n = int(input())
s = [input() for _ in range(n)]
# 文字列そのものをアルファベット順に並び替え
s = ["".join(sorted(a)) for a in s]


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

print(count)

Submission status: Time Limit Exceeded

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

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


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

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

# print(s)

ans = 0
cnt = 0
for i in range(n-1):
    if i == n-2 and s[i] == s[i+1]:
        cnt += 1
        ans += len(list(itertools.combinations(range(cnt+1), 2)))
    if s[i] == s[i+1]:
        cnt += 1
    else:
        ans += len(list(itertools.combinations(range(cnt+1), 2)))
        cnt = 0
print(ans)

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 functools import lru_cache

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]
    
num = 0   
for i in range(len(li3)):
    if li3[i] >= 2:
        num += cmb(li3[i],2)

print(num)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]

from scipy.misc import comb
print(sum([comb(anagrams.count(word), 2, exact=True)\
          for word in set(anagrams)]))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n   = input()
dic = {chr(j):i for i,j in enumerate(range(97, 97+26))}
input_list = []
count = 0
for i in range(int(n)):
    input_vec   = np.zeros(26)
    for j in input():
        input_vec[dic[j]] += 1
    for text in input_list:
        if ((text - input_vec)**2).sum()==0:
            count += 1
    input_list +=[input_vec]
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

tmp = []
counter = 0
for i in range(N):
    new_str = ''.join(sorted(str(input())))
    
    if i != 0:
        counter += tmp.count(new_str)
    tmp.append(new_str)

#new_str_list = [i for i in new_str = ''.join(list(sorted(str(input()))))]
#print(new_str_list)

    #for j in range(i):
    #    if str(new_str) == str(tmp[j]):
    #        counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
ans = 0
for i in range(n):
    s = input()
    key = []
    val = []
    for j in range(10):
        cnt = 1
        if s[j] not in key and j < 9:
            for k in range(j+1,10):
                if s[j] == s[k]:
                    cnt += 1
            key.append(s[j])
            val.append(cnt)
        elif j == 9:
            if s[j] not in key:
                key.append(s[j])
                val.append(cnt)
    d = dict(zip(key, val))
    lis.append(d)
    if n > 0:
        for l in range(len(lis)-1):
            if lis[-1] == lis[l]:
                ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = []
b = []

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

for i in range(n):
	temp = list(a[i])
	temp.sort()
	b.append(temp)

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = input()
n = int(n)
count = 0
word = []

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

for i in range(n - 1):    
    master = list(word[i])
    for j in range(i + 1, n):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while True:
                try:
                    if master[k] == target[l]:
                        target.pop(l)
                        break
                    l += 1
                except:
                    break
        if len(target) == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def init_dict():
    global dic
    dic = {
        "a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0
    }

def countchar(st: str):
    global dic
    global anls
    cp = dic.copy()
    for i in range(10):
        cp[st[i]] += 1
    anls.append(cp)

def search(ls:list):
    global ans
    for i in range(len(ls)-1):
        if ls[i] == ls[len(ls)-1]:
            ans += 1

def main():
    global dic
    global anls
    global ans
    n = int(input())
    dic = {
        "a":0,"b":0,"c":0,"d":0,"e":0,"f":0,"g":0,"h":0,"i":0,"j":0,"k":0,"l":0,"m":0,"n":0,"o":0,"p":0,"q":0,"r":0,"s":0,"t":0,"u":0,"v":0,"w":0,"x":0,"y":0,"z":0
    }
    anls = []
    ans = 0

    for i in range(n):
        s = input()
        init_dict()
        countchar(s)
        search(anls)
    
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def factorial(i):
    ans = 1
    for j in range(1,i+1):
        ans *= j
    return ans
N = int(input())
A = [input() for i in range(N)]
a = []
for i in A:
    b = list(i)
    b.sort()
    a.append(b)

a.sort()
c = list(map(list, set(map(tuple, a))))
d=[]
for i in c:
    d.append(a.count(i))
count=0
for i in d:
    if i ==1:
        continue
    if i>2:
        count += factorial(i) // (factorial(i - 2) * factorial(2))
    elif i ==2:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- config: utg-8 -*-

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

sort_list = []

for i in s:
	str_sort_list = sorted(i)
	new_str = ''.join(str_sort_list)
	sort_list.append(new_str)

count = 0
for i in range(n):
  for j in range(n-i):
    if sort_list[i] == sort_list[j+i] and i!=j+i:
      count += 1

print(count)

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

result = 0
word_list = {}

for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    for this_word in word_list:
        if this_word == input_word:
            word_list[this_word] += 1
            result += word_list[this_word]
            flag = 0
            break
    if flag:
        word_list[input_word] = 0

print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl = sorted([''.join(sorted(input())) for _ in [0]*n])
count = 0
while len(sl)>1:
  i = 1
  flag = True
  while flag:
    if sl[-1] == sl[-(i+1)]:
      i += 1
      if i == len(sl):
        flag=False
    else:
      flag = False
  if i>1:
    count += i*(i-1)//2
  sl = sl[:-i]
  flag=True
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

#list = [[0 for i in range(26)] for j in range(n)]
fuga = [[0 for i in range(10)] for j in range(n)]
#list[0][1]=1
#print(list)


for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		fuga[i][j]=ord(tmp[j])
	fuga[i].sort()

sum=0
for i in range(0,n-1):
	for j in range(i+1,n):
		for k in range(0,10):
			if(fuga[i][k]!=fuga[j][k]):
				break
			elif(k==9):
				sum+=1
#print(fuga)
print(sum)

#print(list)
#print(list[0][:])

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
dic = [input() for i in range(num)]

sdic = []
ans = 0
for i in range(num):
    dic[i] = "".join(sorted(dic[i]))
while len(dic) > 0:
    now = dic[0]
    cnt = dic.count(now)
    ans += int((cnt * (cnt - 1)) / 2)
    for i in range(cnt):
        dic.remove(now)
print(ans)

Submission status: Time Limit Exceeded

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

hoge = 0
for i in range(N):
    hoge += sum([1 if x==ls[i] else 0 for x in ls[i:len(ls)]]) - 1

print(hoge)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[input() for i in range(N)]
a=0
b=N-1
for i in range(b):
    c=N-i-1
    t=s[i]
    u=list(t)
    u.sort()
    for j in range(c):
        v=s[i+j+1]
        w=list(v)
        w.sort()
        for k in range(10):
            if u[k]!=w[k]:
                break
            else:
                if k<9:
                    continue
                else:
                    a=a+1
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(list(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())
s_li = []
for i in range(n):
    s = input()
    s_i = {}
    for j in range(10):
        s_i[s[j]] = 0
    for j in range(10):
        s_i[s[j]] += 1
    buf = ""
    for k, v in sorted(s_i.items()):
        buf += str(k) + str(v)
    s_li.append(buf)

ans = 0

for i in range(n):
    for j in reversed(range(n)):
        if i >= j :
            break
        if s_li[i] == s_li[j]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
n=int(input())
string=[]
ang=0
charcou=[[0]*26 for i in [1]*n]
for c in range(n):
    string.append(input())
    for d in range(10):
        charcou[c][ord(string[c][d])-97]+=1

for c in range(n):
    for d in range(c+1,n):
        if charcou[c]==charcou[d]:
            ang+=1
print(ang)

Submission status: Time Limit Exceeded

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

c=0

for i in set(s):
    n=s.count(i)
    if n>1:
        c += (n*(n-1)//2)

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

chars = []
cnt = 0

for _ in range(n):
  chars.append(''.join(sorted(list(input()))))
  
chars.sort()
for i in range(n):
  cnt += chars[i+1:].count(chars[i])
  
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
strl=[input() for i in range(n)]
"""
def anagram(sa,sb) :
  flag=True
  sal=list(sa)
  sbl=list(sb)
  sal.sort()
  sbl.sort()
  if sal==sbl:
    return True
  else :
    return False
  
  for i in range(10) :
    if sal[i] in sbl :
      sbl.remove(sal[i])
    else :
      flag=False
      break

  """
  #return flag
   
#print(anagram("peanutbomb","constraint"))    
count=0
for i in range(n) :
  jl=list(range(i+1,n))
  for j in jl :
    flag=True
    sal=list(strl[i])
    sbl=list(strl[j])
    sal.sort()
    sbl.sort()
    if sal==sbl:
      count+=1
print(count)

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

u=sorted(t)

cnt=0

for i in range(n-1):    
	for j in range(i+1,n):
		if u[i]!=u[j]:
			break
		else:
			cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys,math
# k,x = map(int,input().split())
N = int(input())
s = []
ans = [0] * N
for i in range(N):
    tmp = input()
    li_tmp = list(tmp)
    s_tmp = sorted(li_tmp)
    st = "".join(s_tmp)
    s.append(st)

a = []
a.append(s[N-1])
for i in range(N-2,-1,-1):
    for j in range(i+1,N):
        if s[i] == s[j]:
            ans[i] += ans[j] + 1
            break
print(sum(ans))

Submission status: Time Limit Exceeded

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

for j in range(len(s)):
    for k in s[j]:
        tmp[j][k] += 1
        
ans = 0
for i in range(0,len(s)):
    for j in range(i+1,len(s)):
        if(tmp[i]==tmp[j]):
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = list(str(input()) for i in range(n))
gou = []
for g in range(len(li)):
    lis = []
    moji = ""
    for k in range(len(li[g])):
        lis.append(li[g][k])
    lis.sort()
    for m in range(len(lis)):
        moji += lis[m]
    gou.append(moji)
v = list(set(gou))
cou = 0
for y in range(len(v)):
    num = gou.count(v[y])
    cou += num*(num-1)//2
print(cou)

Submission status: Time Limit Exceeded

Solution code:
def green_bin(n,s):
    count = 0
    x = [sorted(i) for i in s]

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

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

    print(green_bin(n,s))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
word = []
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

def str_sort(str):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(str)
for _ in range(N):
    word.append(str_sort(input()))


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

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
buf = []
for x in range(N):
    buf.append(input())
    
def strchange(txt):
    x = sorted(list(txt))
    return ''.join(x)

str_list = [strchange(x) for x in buf]
uni_list = set([strchange(x) for x in buf])

combi = 0
for uni in uni_list:
    n = str_list.count(uni)
    if n != 1: combi += int((math.factorial(n))/(math.factorial(2)*math.factorial(n-2)))
        
print(combi)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

ss = [input() for _ in range(n)]
sd = []

for s in ss:
    d = {}
    for c in s:
        if c in d:
            d[c] += 1
        else:
            d[c] = 1
    sd.append(d)

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

Submission status: Time Limit Exceeded

Solution code:
def C_GreenBin():
    N = int(input())
    s = []
    for x in range(N):
        s.append(sorted(input()))
    result = 0
    for i in range(0, N - 1):
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            if i == k:
                continue

            first = s[i]
            second = s[k]
            if anagram(first, second) == True:
                count += 1
    return count


# def anagram(a, b):
#     for i in a:
#         if i in b:
#             a.replace(i, '')
#         else:
#             return False
#     return True

def anagram(a, b):
    a = ''.join(sorted(a))
    b = ''.join(sorted(b))
    return a == b


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())
s = [""]*N
a =[[0]*26 for i in range(N)]
b =[""]*N

cn =ord("a")

for i in range(N):
    s[i] = list(input())
    for j in range(26):
        a[i][j] = s[i].count(chr(cn+j))
    b[i] ="".join(str(a[i]))

b.sort()
c = 0
ans =0

for i in range(N-1):
    if b[i]==b[i+1]:
        c +=1
    else:
        if c !=0:
            ans=ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
            c = 0


if c !=0:
    ans = ans + math.factorial(c+1)/(math.factorial(2)*math.factorial(c+1-2))
    

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
s=[]
answer=0
for i in range(n):
  t=Counter(input())
  s.append(t)
for j in range(n):
  if len(s)==0:
    break
  else:
    h=s[0]
    g=s.count(h)
    if g>1:
      answer+=g*(g-1)//2
    for k in range(g):
      s.remove(h)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
 
sys.setrecursionlimit(10 ** 9)
 
 
def main():
    N = INT()
    S = [INPUT() for _ in range(N)]
    check = []
    alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    count = 0

    for i in range(N):
        check.append([0] * 26)
        for j in range(10):
            for k in range(26):
                if S[i][j] == alphabet[k]:
                    check[i][k] += 1

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

    print(count)
 
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
s = []
anagram_list = []
for _ in range(N):
    s.append(input())
    anagram_list.append([''.join(v) for v in itertools.permutations(s[_])])

duplication = 0
output = 0

for i in range(N):

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

print(output)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

for i in s:
    sl.append(list(i))
    
for i in sl:
    i.sort() #sort() methodは　元を変える
    
for i in range(len(sl)-1):
    for j in range(i+1,len(sl)):
        if sl[i] == sl[j]:
            ans += 1
            
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
count = 0
for i in range(n):
    s1 = list(input())
    s1.sort()
    s1 = "".join(s1)
    s.append(s1)
s2 = list(set(s))
if len(s) == len(s2):
    print("0")
else:
    for i in range(len(s2)):
        k =  s.count(s2[i])
        if k != 1:
            count = count + int(k*(k-1)/2)
    print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

word_list = {}
for i in range(n):
    input_word = "".join(sorted(input()))
    flag = 1
    for this_word in word_list:
        if this_word == input_word:
            word_list[this_word] += 1
            flag = 0
            break
    if flag:
        word_list[input_word] = 0

result = 0
for index in word_list:
    cnt = word_list[index]
    result += int(cnt*(cnt+1)/2)
print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from itertools import combinations
import sys
input = sys.stdin.readline

n = int(input())
s = [input().split()[0] for _ in range(n)]
cnt = defaultdict(int)
for i in range(n):
    cnt["".join(sorted(s[i]))] += 1
result = 0
for c in cnt:
    for i in combinations([""] * cnt[c], 2):
        result += 1
print(result)

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:
#coding: utf-8
amount = int(input())
strings = list(map(str, [input() for i in range(amount)]))
sum = 0

for i in range(len(strings)):
	# print(strings[i])
	abc = list(strings[i])
	abc.sort()
	strings[i] = ''.join(abc)
	# print(strings[i])

for j in range(len(strings)):
	for k in range(j+1,len(strings)):
		if strings[j] == strings[k]:
			sum = sum+1

print(sum)

Submission status: Time Limit Exceeded

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

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

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

for i in range(n - 1):    
    master = list(word[i])
    for j in range(i + 1, n):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while True:
                try:
                    if master[k] == target[l]:
                        target.pop(l)
                    l += 1
                except:
                    break
        if len(target) == 0:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[list(input()) for _ in range(n)]
for i in s:
    i.sort()
s=["".join(i) for i in s]
count=0
for i,string in enumerate(s):
    l=s[i+1:]
    count+=l.count(string)
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)
flag=0
n=int(input())
list1=[]
check_list=[]
for i in range(n):
    list1.append(input())
for i in range(n):
    for j in range(n):
        if (i!=j)and(list1[j] not in check_list):
            if verify_anagrams(list1[i], list1[j]):
                check_list.append(list1[i])
                flag=flag+1
print(flag)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
b = [''.join(sorted(input())) for i in range(n)]
c = list(set(b))
d = len(c)
cnt = [b.count(c[i]) for i in range(d) if b.count(c[i]) >1]
ans = 0
for i in cnt:
  ans += int(i*(i-1)/2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lis = []
for i in range(n):
  word = str(input())
  lis.append({letter:word.count(letter) for letter in word})
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:
N = int(input())
s = []

for i in range(N):
  hoge = input()
  s.append("".join(sorted(hoge)))

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