Problem:


Score : 300 points

Problem Statement

We will call a string obtained by arranging the characters contained in a string a in some order, an anagram of a.

For example, greenbin is an anagram of beginner. As seen here, when the same character occurs multiple times, that character must be used that number of times.

Given are N strings s_1, s_2, \ldots, s_N. Each of these strings has a length of 10 and consists of lowercase English characters. Additionally, all of these strings are distinct. Find the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

s_1, s_2, \ldots, s_N are all distinct.

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

Print the number of pairs of integers i, j (1 \leq i < j \leq N) such that s_i is an anagram of s_j.

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

s_1 = acornistnt is an anagram of s_3 = constraint. There are no other pairs i, j such that s_i is an anagram of s_j, so the answer is 1.

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

If there is no pair i, j such that s_i is an anagram of s_j, print 0.

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

Note that the answer may not fit into a 32-bit integer type, though we cannot put such a case here.



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
N = int(input().strip())

ss = []
counts_id = []
counts = []
answer = 0

chars = [x for x in "abcdefghijklmnopqrstuvwxyz"]
num = len(chars)

for i in range(N):
  ss.append(input().strip())
  _count = [0 for _ in range(num)]
  for _s in ss[i]:
    _count[chars.index(_s)] += 1
  
  flag = True
  if i == 0:
    counts_id = [_count]
    counts = [0]
  else:
    for k, id in enumerate(counts_id):
      if id == _count:
        counts[k] += 1
        answer += counts[k]
        flag = False
        break
    if flag:
      counts_id.append(_count)
      counts.append(0)

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import math
N = int(input())
my_list = [None] * N
for i in range(N):
    s_i = input()
    my_dict = {}
    for j in range(10):
        if s_i[j] in my_dict:
            my_dict[s_i[j]] += 1
        else:
            my_dict[s_i[j]] = 1
    my_list[i] = my_dict
sum = 0
trash = []
for i in range(N - 1):
    if i in trash:
        continue
    num = 0
    a = 0
    for j in range(i + 1, N):
        if my_list[i] == my_list[j]:
            num += 1
            trash.append(j)
    for j in range(1, num + 1):
        a += j
    sum += a
print(sum)

Submission status: Time Limit Exceeded

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


print(int(sum(ccr)))

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

ls = list(map(sorted,lst))
k=0
ans=0
for i in range(N):
  for j in range(k,N):
    if i !=j and ls[i]==ls[j]:
      ans +=1
  k+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
n=int(input())
strl=[list(input()) for i in range(n)]

count=0
#il=np.arange(n)
for i in range(n) :
  sal=strl[i]
  jl=list(range(i+1,n))
  for j in jl :
    flag=True
    sbl=strl[j]
    sal.sort()
    sbl.sort()
    if sal==sbl:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return len(result)


n=int(input())
a=[list(input()) for i in range(n)]
count=0
a=list(itertools.combinations(a,2))
for i in range(len(a)):
    if list_difference(a[i][0],a[i][1])==0:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
L = []
C = 0
for i in range(N):
  L.append(input())
for j in range(N):
  for k in range(N):
    if k > j:
      if collections.Counter(L[j]) == collections.Counter(L[k]):
        C += 1
print(C)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
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())
S = []
count = []
ans = []
for i in range(n):
    s = list(str(input()))
    #print(s)
    #print(sorted(s))
    s = sorted(s)
    if i == 0:
        S.append(s)
        count.append(0)
        ans.append(0)
        continue
    if s in S:
        #print(S,s)
        #print(S.index(s))
        count[S.index(s)] += 1
        ans[S.index(s)] += count[S.index(s)]
        #count += 1
        #S.append(s)
    else:
        S.append(s)
        count.append(0)
        ans.append(0)
#print(count)
    
print(sum(ans))

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)]
#list[0][1]=1
#print(list)

hash=[]
for i in range(0,26):
	hash.append([])

for i in range(0,n):
	tmp=input()
	hoge=0
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1
		hoge+=ord(tmp[j])-ord("a")
	hoge=hoge%26
	hash[hoge].append(i)
#print(hash)

sum=0

for i in range(0,26):
	for j in range(0,len(hash[i])-1):
		for k in range(j+1,len(hash[i])):
			#print(i)
			#print(hash[i][j])
			#print(hash[i][k])
			for m in range(0,26):
				if(list[hash[i][j]][m]!=list[hash[i][k]][m]):
					break
				elif(m==25):
					sum+=1


#for i in range(0,n-1):
#	for j in range(i+1,n):
#		for k in range(0,26):
#			if(list[i][k]!=list[j][k]):
#				break
#			elif(k==25):
#				sum+=1

print(sum)

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

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(s[i])
    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:
N = int(input())
alphabet = "abcdefghijklmnopqrstuvwxyz"

from collections import defaultdict
d = defaultdict(int)
for i in range(N):
    s = input()
    num = 0
    for i,a in enumerate(alphabet):
        if s.count(a) == 10:
            continue #アナグラムはない
        num += s.count(a)*10**i
    d[num] += 1

ans = 0

for key in d.keys():
    ans += d[key]*(d[key]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k=sorted([x for x in input()])
    if k in L:
        obj["".join(k)]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))

Submission status: Time Limit Exceeded

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


def is_anagram(s_i, s_j):
    for k in range(10):
        if s_i[k] != s_j[k]:
            return False
    return True


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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

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

seq = list(itertools.combinations(dic, 2))

count = 0
for n in range(len(seq)):
  if(seq[n][0]==seq[n][1]):
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

ss = set(s)
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:
num = int(input())
char=[] #appendのために宣言が必要
while True:
    try:
        char.append(list(input()))

    except:
        break
new_char=[]
cnt=0
for i in range(num):
	new_char.append(sorted(char[i]))
for x in range(num):
    for y in range(num):
        if new_char[x]==new_char[y] and x!=y:
            cnt = cnt+1
print(cnt//2)

Submission status: Time Limit Exceeded

Solution code:
def so(s):
    s_ = []
    for i in s:
        s_.append(i)
    return s_

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

for i in range(n):
    s[i] = so(s[i])
    s[i].sort()
for i in range(n - 1):
    for j in range(i + 1, n):
        if s[i] == s[j]:
            x = x + 1
print(x)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(input()) for _ in range(N)]
cnt = 0
for i in range(N):
    cnt += s.count(s[i]) - 1
    s[i] = "C{}".format(i)
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
n = int(input())
aL = [list(set(Counter(input()).most_common())) for i in range(n)]
count = 0

for i in range(n-1):
    if aL[i] != "":  
      for j in range(i+1, n):
          if aL[i] == aL[j]:
            tmp = aL.count(aL[i])
            if tmp == 2:
              count += 1
            else:
              count += (tmp-1)*(tmp-2)//2
            aL = ["" if k == aL[i] else i for k in aL]
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = []
n_list = []
ana = 0
for i in range(n):
    s = sorted(input())
    #print(s)
    if len(s_list) > 0:
        for num, s_i in enumerate(s_list):
            is_exist = False
            if s_i == s:
                n_list[num] += 1
                ana += n_list[num]
                is_exist = True
                break
        if not is_exist:
            s_list.append(s)
            n_list.append(0)
    else:
        s_list.append(s)
        n_list.append(0)

print(int(ana))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


N = int(input())
s_list = [Counter(list(input())) for _ in range(N)]
count = 0
skip_n = []
for i in range(N):
  if i in skip_n:
    continue

  tmp_count = 0
  for j in range(i + 1, N):
    if j in skip_n:
      continue

    if s_list[i] == s_list[j]:
      tmp_count += 1
      skip_n.append(j)
  count += int((tmp_count+1)*tmp_count/2)
print(count)

Submission status: Time Limit Exceeded

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

mylist = []
for s in l:
    s_list = [ c for c in s]
    mylist.append("".join(sorted(s_list)))

myset = set(mylist)
mylist2 = list(myset)

ans=0
for i in range(len(mylist2)):
    count = mylist.count(mylist2[i])
    mylist3 = list(range(count))
    ans += sum(mylist3)
    mylist.remove(mylist2[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())

strs = [[] for i in range(num)]
for i in range(num):
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
shorten_strs = list(set(new_strs))

cnt = 0

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

for str in shorten_strs:
    nums = new_strs.count(str)
    if nums >= 2:
        cnt += comb_count(nums, 2)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  s.sort()
  S.append(s)
S.sort()
S.append(["z" for i in range(11)])
cont=0
for i in range(n-1):
  t=1
  while S[i]==S[i+t]:
    cont+=1
    t+=1
print(cont)

Submission status: Time Limit Exceeded

Solution code:
N = int(input()) #1行目のNを取得する
s = [input() for i in range(N)] #複数行の数値の入力を取得
# print(s) #出力：['s_1', 's_2', 's_3', 's_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
	# print(word_dict[num])

match_num = 0
max = 0

for i in range(N - 1):
	for j in range(i + 1, N):
		# print(str(i) + ":" + str(j))
		if(all(word_dict[i][key] == word_dict[j][key] for key in dic)):
			match_num = match_num + 1
	if max < match_num:
		max = match_num

print(max)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
sort = []
for i in range(N):
    sort.append(''.join(sorted(input())) )
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        count += (sort[i] == sort[j])
print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

def judge(Si_list, Sj):
    for i in range(10):
        if Si_list[i] in Sj:
            Sj = Sj.replace(Si_list[i],"",1)

        else:
            return 0
    return 1


# 標準入力
N = int(input())

str_list = [input() for i in range(N)]

count = 0
for i in range(0,len(str_list)):
    Si_list = list(str_list[i])
    for j in range (i+1, len(str_list)):
        count = count + judge(Si_list, str_list[j])
  
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()
    str=''.join(sorted(str))
    stl.append(str)

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

    
print(count)

Submission status: Time Limit Exceeded

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

    strs = []
    for _ in range(N):
        str = [ci for ci in input()]
        str.sort()
        t = ''.join(str)
        strs.append(t)

    count = 0
    for i, si in enumerate(strs):
        for sj in strs[i+1:]:
            if si == sj:
                count += 1
    print(count)


main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

n = int(input())
s = [ input() for i in range(n)]
count = 0
x = [sorted(i) for i in s]
_x = sorted(x)

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ls = []
l = [0 for i in range(n)]
for i in range(n):
  ls.append(input())
for i in range(n):
  for j in range(10):
    alpha = ord(ls[i][j]) - ord("a")
    l[i]+=10**alpha
ans = 0
for i in range(n):
  for j in range(i+1,n):
    if l[i] == l[j]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

#c = 0
out = 0
for c in range(N-1):
#while c < N-1:
    for i in range(c, N-1):
        s_l = set(s[c])
        s_r = set(s[i+1])
        if(s_l != s_r):
            continue
        s_l_li = list(s_l)
        for j in range(len(s_l_li)):
            if(s[c].count(s_l_li[j]) != s[i+1].count(s_l_li[j])):
                break
            if j == (len(s_l_li)-1):
                out += 1
#    c += 1
print(out)

Submission status: Time Limit Exceeded

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

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x

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

nums = []
for w in ws:
    v = [0] * 52
    for c in w:
        if "Z" < c:
            v[ord(c) - ord("a")] += 1
        else:
            v[ord(c) - ord("A") + 26] += 1
    nums.append(v)

ans = 0
found = []
for i in range(n):
    if i in found:
        continue
    r = 0
    for j in range((i+1),n):
        if j in found:
            continue
        v = 1
        for k in range(52):
            if nums[i][k] != nums[j][k]:
                v = 0
                break
        if v != 0:
            r += v
            found.append(j)
    ans += (r + 1) * r // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
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())
s_list = []
ans = 0
for _ in range(N):
    s_list.append(''.join(sorted(list(input()))))
c = collections.Counter(s_list)
l = len(c.most_common())
for i in range(l):
    m = c.most_common()[i][1]
    if m > 1:
        ans += cmb(m, 2)
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C
N = int(input())
words = []
anagram = 0

for i in range(N):
    tmp = input()
    words.append(tmp)
    
for i in range(N):
    for j in range(N):
        if words[i] == words[j]:
            continue
        if sorted(words[i]) == sorted(words[j]):
            anagram +=1

anagram /= 2
print(int(anagram))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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


alphabet = set('abcdefghijklmnopqrstuvwxyz')
s_list = [''.join([str(s_i[a]) for a in alphabet]) for s_i in s]

count = 0
i = 0

for x in s_list:
  i += 1
  temp = s_list[i:]
  hoge = s[i:]
  for y in temp:
    if y == x:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
flag=0
n=int(input())
list1=[]

for i in range(n):
    list1.append(input())
for i in range(n):
    for j in range(n):
        if i<j:
            if verify_anagrams(list1[i], list1[j]):
                flag=flag+1
print(flag)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import itertools

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

seq = list(itertools.combinations(range(n), 2))

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

Submission status: Time Limit Exceeded

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
T = []
for i in range(N):
  S.append(str(input()))
for j in range(N):
  T.append(''.join(sorted(S[j])))
A = [[e, T.count(e)] for e in set(T) if T.count(e)>1]
def ans(m):
  return m*(m+1)/2
X = 0
for i in range(len(A)):
  X += ans(A[i][1]-1)
print(int(X))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

F    = [None] * (N+1)
F[0] = 1

for i in range(1, N+1):
    F[i] = F[i-1] * i

S = [''.join(sorted(list(input()))) for i in range(N)]

print(sum([F[i] // F[i-2] // 2 for i in Counter(S).values()]))

Submission status: Time Limit Exceeded

Solution code:
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()
ans = a[0]
count=0
for i in range(0,N):
    ans = a[i]
    for j in range(i+1,N):
        if ans == a[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
syu = set()
lis = []
for i in range(n):
  w = str(input())
  kusa = list(w)
  kusa.sort()
  lis.append(tuple(kusa))
  syu = syu|{tuple(kusa)}
counter = 0
for d in syu:
  m = lis.count(d)
  counter += m*(m-1)//2
print(counter)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

c=0
line=[]

for i in range(n):
    string = list(input())
    string = [[a,string.count(a)] for a in set(string)]
    c+=line.count(string)
    line.append(string)

print(c)

Submission status: Time Limit Exceeded

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

mylist = []
for s in l:
    s_list = [ c for c in s]
    mylist.append("".join(sorted(s_list)))

myset = set(mylist)
mylist2 = list(myset)

ans=0
for i in range(len(mylist2)):
    count = mylist.count(mylist2[i])
    mylist3 = list(range(count))
    ans += sum(mylist3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
    
n = int(input())
S = []
for i in range(n):
    s = list(str(input()))
    #print(s)
    #print(sorted(s))
    s = sorted(s)
    #s = "".join(s)
    S.append(s)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
abc = [chr(i) for i in range(97, 97+26)]
ss = []
ct = []
ans = 0

for i in range(N):
    s = input()
    cnt = [0]*26
    for j in s:
        cnt[abc.index(j)] += 1
    if not cnt in ss:
        ss.append(cnt)
        ct.append(1)
    else:
        ct[ss.index(cnt)] += 1

for i in range(len(ct)):
    if ct[i] > 1:
        ans += int((ct[i] * (ct[i] - 1))/2)


print(ans)

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 < 2: return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def is_anagram(s_1, s_2):

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

"""
N=5
S=['abaaaaaaaa',
'oneplustwo',
'aaaaaaaaba',
'twoplusone',
'aaaabaaaaa']
"""

"""
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) == True:
            ans += 1
"""




ans = 0
while True:
    if len(S) == 0: break
    new_S = []
    s_1_anagram = 0
    s_1 = S[0]
    for s_2 in S[1:]:
        if is_anagram(s_1, s_2) == True:
            s_1_anagram += 1
        else:
            new_S.append(s_2)
    

    ans += combinations_count(s_1_anagram+1, 2)
    S = list(new_S)
    

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_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:
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[list(input()) for a in range(N)]
[thing.sort() for thing in strings]
sorteds=["".join(thing) for thing in strings]
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:
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=[]

for i in range(n):
    list1.append(input())
for i in range(n):
    for j in range(n):
        if i>j:
            if verify_anagrams(list1[i], list1[j]):
                flag=flag+1
print(flag)

Submission status: Time Limit Exceeded

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

    
    for i in sl:
        i.sort()
        
    st = tuple(sl)
    
    for i in range(len(st)-1):
        for j in range(i+1,len(st)):
            if sl[i] == sl[j]:
                ans += 1

    print(ans)

if __name__ == '__main__':
    main()

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):
    cur_same = 0
    if s_n[i] == -1:
        continue
    for j in range(i+1,n):
        if s_n[i] == s_n[j]:
            cur_same += 1
            cnt += 1*cur_same
            s_n[j] = -1

print(cnt)

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 = [list(input().split()[0]) for _ in range(n)]
cnt = defaultdict(int)
for i in range(n):
  s[i].sort()
  cnt["".join(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())
sort = []
for i in range(N):
    sort.append(''.join(sorted(input())) )
count = 0
for i in range(N-1):
    for j in range(i+1,N):
        if(sort[i] == sort[j]):
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from operator import mul
from functools import reduce
    
n = int(input())
S = []
for i in range(n):
    s = list(str(input()))
    #print(s)
    #print(sorted(s))
    s = sorted(s)
    #s = "".join(s)
    S.append(s)

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

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+1,H):
            if S[j] == S[i]:
                result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

count = 0
for i in ran:
    for k in ran:
        if i < k and S[i] == S[k]:
            count += 1

print(count)

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):
        s_i = set(lis[i])
        s_j = set(lis[j])
        if s_i == s_j:
            same = True
            for k in range(10):
                if 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 numpy as np

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

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

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

S_ = set(S)

a = [math.factorial(S.count(i)) // (math.factorial(S.count(i) - 2) * math.factorial(2)) for i in S_ if not S.count(i) == 1]

print(int(sum(a)))

Submission status: Time Limit Exceeded

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

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

print(count)