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 create_anagram_dic(val):
  dic = {}
  for s in val:
    if s not in dic:
      dic[s] = 0
    dic[s] += 1
  
  return dic

def is_anagram(val, dic):
  for k, v in dic.items():
    if val.count(k) != v:
      return False
  return True

N = int(input())

s = list()
for i in range(0, N):
  val = str(input())
  s.append(val)
  
result_dic = {}
result_dic[s[0]] = 1

for i in range(1, len(s)):
  is_contain = False
  for k in result_dic.keys():
    dic = create_anagram_dic(k)
    if is_anagram(s[i], dic):
      result_dic[k] += 1
      is_contain = True
      break
  if not is_contain:
    result_dic[s[i]] = 1

result_count = 0
for val in result_dic.values():
  result_count += val * (val - 1) // 2

print(result_count)

Submission status: Time Limit Exceeded

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

    str_pattern_list = []
    str_pattern_count = []
    matched_count = 0
    for i in range(loop_count):
        string = ''.join(sorted(input()))

        if string in str_pattern_list:
            str_pattern_count[str_pattern_list.index(string)] += 1
            matched_count += str_pattern_count[str_pattern_list.index(string)]
        else:
            str_pattern_list.append(string)
            str_pattern_count.append(0)

    print(matched_count)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def makedic(str1):
    dic = {}
    for s in str1:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    #print(dic)
    return dic

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

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

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
l_d = []
count = 0
for _ in list(range(N)):
  a = str(input())
  x = collections.Counter(a)
  count += l_d.count(x)
  l_d.append(x)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
l = list(str(input()) for _ in range(n))
d = [{} for _ in range(n)]

for m, a in enumerate(l):
    for p in range(10):
        d[m][a[p]] = a.count(a[p])
cnt = 0
dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]
A=["a","b","c","d","e","f","g","h"]
r=[0,4,5]

for i in d:
    pp=[i==k for k in d]
    kk = [x for x, _ in enumerate(pp) if _]
    d = dellist(d, kk)
    cnt += (len(kk)-1)*len(kk)/2
# for i, j in enumerate(d):
#     for k in range(i+1, len(d)):
#         if j == d[k]:
#             cnt += 1

print(int(cnt))

Submission status: Time Limit Exceeded

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

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}
word_dict = {}

for num in range(N):
	word_dict[num] = {k: v for (k, v) in dic.items()}

	for moji in s[num]:
		word_dict[num][moji] = word_dict[num][moji] + 1

match_num = 0

for i in range(N - 1):
	for j in range(i + 1, N):
		if(all(word_dict[i][key] == word_dict[j][key] for key in dic)):
			match_num = match_num + 1

print(match_num)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

# input
n = int(stdin.readline().rstrip())
s = ["".join(sorted(list(str(input()))) ) for _ in range(n)]
"""
for _ in range(n):
    raw = 
    raw.sort()
    s.append("".join(raw))
"""
c = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        if s[i] == s[j]:
            c += 1
print(c)

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 s:
	for n in s:
		if Counter(n)==Counter(m) and m != n:
			ans+=1
	s.remove(n)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    count = 0
    lists =[]
    count_dict = {}

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in lists:
            if input_data not in count_dict.keys():
                count_dict[input_data] = 1
            count = count + count_dict[input_data]
            count_dict[input_data] += 1
        else:
            lists.append(input_data)

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
list = []
counter = 0
for i in range(n):
    list.append([c for c in raw_input()])
for j in range(n):
    for k in range(j+1,n):
        if sorted(list[j]) == sorted(list[k]):
            counter +=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

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

ss = set(s)
count = 0
for u in ss:
    al = s.count(u)
    # s.remove
    count += comb(al, 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[]
n=[]
for i in range(N):
    k="".join(sorted(list(input())))
    if k in s:
        n[s.index(k)]+=1
    else:
        s.append(k)
        n.append(1)
c=0
for i in n:
    c += i*(i-1)

print(c//2)

Submission status: Time Limit Exceeded

Solution code:
a=int(input())
f=["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"]
g=[]
for p in range (0,a):
    b=input()
    h=[0,0,0,0,0,0,0,0,0,0,0,0,0,
       0,0,0,0,0,0,0,0,0,0,0,0,0]
    for q in range (0,10):
        c=b[q]
        for r in range (0,26):
            if c==f[r]:
                h[r]+=1
    g.append(h)

i=tuple(g)


x=0
for s in range (0,a):
    for t in range (s,a-1):
        g=list(i)
        k=g.pop(s)
        l=g[t]
        if k==l:
            x+=1
    g=list(i)
print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = []
countlist = []
for i in range(N):
    t = list(input())
    for j in range(len(slist)):
        s = slist[j]
        flag = True
        for k in range(10):
            if s.count(s[k]) != t.count(s[k]):
                flag = False
        if flag:
            countlist[j] += 1
            break
    slist.append(t)
    countlist.append(1)
ans = 0
for i in countlist:
    if i > 1:
        ans += int(i*(i-1)/2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
cnt = 0
h = []
x = 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:
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]))
flag = [0] * N
cnt = 0
for i in range(N-1):
    if flag[i] ==1:
        continue
    else:
        tmp_cnt = 0
        for j in range(i+1,N):
            if t[i]==t[j]:
                tmp_cnt += 1
                flag[j] = 1
        cnt += ((tmp_cnt)*(tmp_cnt+1))/2
print(int(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())
strings=[list(str(input())) for a in range(N)]
sorteds=[]
for thing in strings:
    thing.sort()
    sorteds.append("".join(thing))
sums=0
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)

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 = ["".join(sorted(input())) for i in range(N)]

S_ = set(S)

a = [combinations_count(S.count(i), 2) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))

Submission status: Time Limit Exceeded

Solution code:
import copy
s = []
N = int(input())
for i in range(N):
    s.append([i for i in input()])
count = 0
for i in s:
    for j in s:
        if i == j:
            continue
        origin = copy.copy(j)
        for c in i:
            try:
                index = origin.index(c)
            except ValueError:
                continue
            origin.pop(index)
        if len(origin) == 0:
            count += 1

print(count // 2)

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)
  if c!=0:
    count+=c*(c+1)/2
    for i in range(c):
      su.remove(j)
      
print(int(count))

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))
while len(s)>0:
    cnt+=s.count(s.pop(0))
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))

def change_dict(string):
	dic = {}
	for ch in set(string):
		dic[ch] = string.count(ch)
	return dic

n = int(input())
st = []
for i in range(n):
	st.append(change_dict(input()))
ans = 0

lst = []
for i in st:
	if (st.count(i)>=2) and (not(i in lst)):
		ans += combinations_count(st.count(i),2)
		lst.append(i)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
countr = []
liss = []
s = [0] * N
for i in range(N):
  s[i] = input()

for ss in s:
  a = collections.Counter(ss)
  if a in liss:
    ind = liss.index(a)
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)


ans = 0
for cc in countr:
  ans = ans + (cc * (cc - 1) / 2)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = [tuple(sorted(input())) for _ in range(N)]
scnt = [slist[:i].count(slist[i]) for i in reversed(range(N))]

print(sum(int(_) for _ in scnt))

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s_n = [] * n
for i in range(n):
    s = input()
    s_n.append(collections.Counter(s))

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

print(count)

Submission status: Time Limit Exceeded

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

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[0].get(key) for key in inp):
                item[1] += 1
        ls.append([inp, 0])
    print(sum(map(lambda x: x[1], ls)))


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())
words=[]
for i in range(n):
  words.append(sorted(input()))

def group(idxs):
  idxs_n=[]
  idxs_r=[idxs[0],]
  for i in range(1,len(idxs)):
    if words[idxs[0]]==words[idxs[i]]:
      idxs_r.append(idxs[i])
  m=len(idxs_r)
  pairs=m*(m-1)/2
  
  for idx in idxs:
    if idx not in idxs_r:
      idxs_n.append(idx)
  
  return idxs_n,pairs

match=0
idxs=[int(i) for i in range(n)]

while len(idxs)>0:
  idxs,pairs=group(idxs)
  match+=int(pairs)

print(match)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lst = [input() for i in range(N)]
si = [[0]*26 for i in range(N)]
#print(ord("a")-97)
k = 0
for i in range(N):
  for j in lst[i]:
    si[i][ord(j)-97] += 1
# print(si)
ans = 0
for i in range(N):
  for j in range(k,N):
    if si[i]==si[j] and i != j:
      ans +=1
  k+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
s = [sorted(input()) for i in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if s[i] == s[j]:
            ans += 1
ans = int((ans - len(s)) / 2)
print(ans)

Submission status: Time Limit Exceeded

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

counters = []
count_dict = {}
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    
    c = collections.Counter(text)
    name = str(c)
    if c in counters:
        count_dict[name] += 1
        
        
    else:
        count_dict[name] = 1
        counters.append(c)

anss = []
for v in count_dict.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)

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

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

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

N = int(input())
s = [""] * N
ans = 0

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

dup = [combinations_count(s.count(x), 2) for x in set(s) if s.count(x) > 1]
ans += sum(dup)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def comb(n, r):
    return len(list(itertools.combinations(range(n), r)))

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

ss = set(s)
count = 0
for u in ss:
    al = s.count(u)
    s.remove(u)
    count += comb(al, 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

num=int(input())
stl=[]

count=0

for i in range(num):
    str=input()
    stll=list(str)
    stll.sort()
    str=''.join(stll)        
    stl.append(str)

duplicate=[x for x in set(stl) if stl.count(x) > 1]
if duplicate:
    for dup in duplicate:
        n=stl.count(dup)
        count=count+factorial(n) // factorial(2) // factorial(n - 2)

    
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()
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:
n=int(input())
l=[]
s,a=[],[]
flag=0
for i in range(n):
 l.append(input())
for i in range(n-1):
 s=list(l[i])
 s.sort()
 for j in range(i+1,(i)+(n-i)):
  a=list(l[j])
  a.sort()
  flag+=1
  if s != a:
   flag-=1
print(flag)

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))))
count = 0
for i in c:
    if a.count(i)==1:
        continue
    if a.count(i) > 2:
        count += factorial(a.count(i)) // (factorial(a.count(i) - 2) * factorial(2))
    else:
        count += 1

print(count)

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

for ss in range(len(ilist)):
  ilist[ss].sort()

li = list(combinations(ilist, 2))
ans = 0

for b in range(len(li)):
  if(li[b][0] == li[b][1]):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

d = []
for c in s:
    d.append(sorted(list(c)))

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  a=list(s1)
  b=list(s2)
  a.sort()
  b.sort()
  if a==b:
    return True
  else:
    return False
  
cnt=0
for i in range(len(sn)-1):
  m=1
  if not sn[i]:continue
  for ii in range(i+1,len(sn)):
    if sn[ii] and check(sn[i],sn[ii]):
      cnt+=m
      m+=1
      sn[ii]=None

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)

    return get_counter(first_word) == get_counter(second_word)


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

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

print(count)

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 = ["".join(sorted(input())) for i in range(N)]

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

a = [combinations_count(S.count(i), 2) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))

Submission status: Time Limit Exceeded

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


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(sorted(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
            if s[i] == s[k]:
                count += 1
    return count


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import copy
import math
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)
input = sys.stdin.readline
N = int(input())
ans_list=["test"]
ans_num=[1]
ans = 0
for i in range(N):
    chk = input().strip()
    for j in range(len(ans_list)):
        if verify_anagrams(ans_list[j],chk):
            ans+= ans_num[j]
            ans_num[j] +=1
            break
        if j == len(ans_list)-1:
            ans_list.append(chk)
            ans_num.append(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):
    n1 = [0] * 26
    for l in range(26):
        for c in str[i]:
            if ord(c) == ord('a') + l: n1[l] += 1

    for j in range(i+1, N):
        n2 = [0] * 26
        check = 0
        for l in range(26):
            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
                break
        if check==0: counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
r = [0]*10**5
res = 0

num = 0

for i in range(n):
    an = list(input())
    an.sort()
    an = "".join(map(str, an))
    #print(an)
    if an not in l:
        l.append(an)
        num += 1
    r[l.index(an)] += 1

z = 0
r = r[:num]
#print(r)
for i in range(1,max(r)+1):
    #print(j)
    z += i-1
    if i in r:
        res += z*r.count(i)
else:
    print(res)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
s = [[collections.Counter(input())] for _ in range(N)]
ans = 0
for i in range(N):
    ans += s[:i].count(s[i])

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.upper().replace(' ', ''))

    return get_counter(first_word) == get_counter(second_word)


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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from operator import mul
from functools import reduce

def combination(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())
s = [''.join(sorted(input())) for _ in range(n)]
ans = 0
for anagram in set(s):
    count = s.count(anagram)
    if count > 1:
        ans += combination(count, 2)
print(ans)

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:
    result += len(list(combinations([""] * cnt[c], 2)))
print(result)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
lis = []
for i in range(n):
    s = input()
    s_lis = [s[j] for j in range(10)]
    lis.append(s_lis)
for i in range(n-1):
    for j in range(i+1,n):
        same = True
        for k in range(10):
            if lis[i][k] in lis[j]  and lis[i].count(lis[i][k]) == lis[j].count(lis[i][k]):
                continue
            else:
                same = False
                break
        if same == True:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline().strip())
list = []
ans = 0
for x in range(n):
  list.append(sorted(sys.stdin.readline().strip()))
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:
from collections import Counter
n=int(input())
l=[]
dfs=[]
ans=[0]*n
for i in range(n):
    s=input()
    m=len(dfs)
    ss=Counter(s)
    for j in range(m):
        if l[j]==ss:
            ans[j]+=1
            break
    l.append(ss)
    dfs.append(i)
    ans[i]+=1
k=len(ans)
answer=0
for i in range(k):
    answer+=ans[i]*(ans[i]-1)//2
    
print(answer)

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
    s.sort()
    for i in range(0, N - 1):
        if s[i] != s[i+1]:
            continue
        for j in range(i + 1, N):
            if s[i] == s[j]:
                result += 1
            else:
                break
    print(result)
    
if __name__ == "__main__":
    C_GreenBin()

Submission status: Time Limit Exceeded

Solution code:
import sys

N = int(input())
L = []
for i in range(N):
    L.append(sorted(sys.stdin.readline().strip()))

Sum = 0
for i in range(N-1):
    for j in range(i+1, N):
        if L[i] == L[j]:
            Sum += 1

print(Sum)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
li=[input() for i in range(N)]
count=0
from collections import Counter

dic=[Counter(s.upper().replace(' ', '')) for s in li]
#print(dic)
for i in range(N):
  for j in range(i):
    if i != j:
      if dic[i]==dic[j]:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
#[int(i) for i in input().split()]
#import math

n = int(input())
s = []
cnt = 0
for i in range(n):
    m = input()
    m = sorted(m)
    s.append(m)
dic = {}
#print(s)
ls = []
ls1 = []
for i in range(n):
    if s[i] not in ls:
        ls.append(s[i])
        ls1.append(s.count(s[i])-1)

for i in ls1:
    cnt += ((i)*(i+1))//2
print(cnt)

"""
n = int(input())
cnt = 0
["a","b","c","d","e"]
for i in range(n):

print(math.factorial(4))
"""

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    count = 0
    lists =[]
    count_dict = {}

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in lists:
            if input_data not in count_dict.keys():
                count_dict[input_data] = 1
            count = count + count_dict[input_data]
            count_dict[input_data] = count_dict[input_data] + 1
        else:
            lists.append(input_data)

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = []
A = []
from collections import Counter
import string
for _ in range(N):
    S.append(input())
L=[]
sum_=[0]*N
for (j,s) in enumerate(S):
  for (i,letter) in enumerate(string.ascii_lowercase):
  	sum_[j] += 2**i*Counter(s)[letter]
  
ANS=Counter(sum_)
ans=0
for i in ANS.values():
  ans += int(i*(i-1)/2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
countr = []
liss = []
for i in range(N):
  s = input()
  a = collections.Counter(s)
  if a in liss:
    ind = liss.index(a)
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)

ans = 0
for cc in countr:
  ans = ans + (cc * (cc - 1) / 2)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from sys import stdin
def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

def cmb(n,r):
    if n==r: return 1
    if n<r: return 0
    else: return fun(n) // (fun(r)*fun(n-r))




n = int(input())

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

ans = 0
for i in set(ss):
    ans += cmb(ss.count(i), 2)
print(ans)

Submission status: Time Limit Exceeded

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

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

counter     =   0


A = []

count_list  =   []

frag = 0

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

    for j in range(len(A)):
        if(A[j] == S):
            count_list[j] += 1
            counter += count_list[j]
            frag = 1
            break 
    if(frag == 0):
        A.append(S)
        count_list.append(0)

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
l_d = []
count = 0
for _ in list(range(N)):
  x = {}
  a = str(input())
  for i in list(range(len(a))):
    if a[i] not in x:
      x[a[i]] = 1
    else:
      x[a[i]] += 1
  count += l_d.count(x)
  l_d.append(x)
print(count)

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()
  word_lst[i]=''.join(word_lst[i])

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())
A=[]
for I in range(n):
  moji=list(input())
  moji.sort()
  moji=''.join(moji)
  A.append(moji)
A.sort()
N=0
for i in range(n):
  a=A[i]
  for s in range(i+1,n):
    b=A[s]
    if a==b:
      N+=1
    else:
      break
print(N)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
sl = []
cnt = 0

for i in range(N):
	new = "".join(sorted(list(input())))
	
	for j in sl:
		if new == j:
			cnt+=1
			
	sl.append(new)
	
print(cnt)

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)
  count+=c*(c+1)/2
  for i in range(c):
    su.remove(j)
  
print(int(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):
    check.append(Counter(input()))

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


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
Si = [input() for _ in range(N)]

count = 0
for i in range(0, N):
    C1 = Counter(Si[i])
    for j in range(i+1, N):
        if C1 == Counter(Si[j]):
            count += 1
        else:
            pass
print(int(count))