Problem:


Score : 300 points

Problem Statement

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

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

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

Constraints

2 \leq N \leq 10^5

s_i is a string of length 10.

Each character in s_i is a lowercase English letter.

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

Input

Input is given from Standard Input in the following format:

N
s_1
s_2
:
s_N

Output

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

Sample Input 1

3
acornistnt
peanutbomb
constraint

Sample Output 1

1

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

Sample Input 2

2
oneplustwo
ninemodsix

Sample Output 2

0

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

Sample Input 3

5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

Sample Output 3

4

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



Sample input:
3
acornistnt
peanutbomb
constraint


Sample output:
1

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def check(s1, s2, i, j, memo):
    if memo[i] == memo[j] and memo[i] != -1:
        return 1
    elif memo[i] != memo[j] and memo[j] != -1:
        return 0

    if s1 == s2:
        if memo[i] == -1:
            memo[i] = i
            memo[j] = i
        elif memo[j] == -1:
            memo[j] = memo[i]
        return 1

    else:
        return 0


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

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

    ans = 0
    memo = [-1 for i in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            ans += check(S[i], S[j], i, j, memo)

    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
equal=0
ans=0
s=[list(input()) for _ in range(N)]
s10 = [i for i in range(10)]
i=0
t=['x' for i in range(N)]
for i in range(N):
    s10 = [x for x in range(10)]
    ti = [['xx',0] for x in range(10)]
    for j in range(10):
        if j in s10:
            ti[j][0]=s[i][j]
            ti[j][1]=1
            for k in range(j+1,10):
                if s[i][j]==s[i][k]:
                    ti[j][1]=ti[j][1]+1
                    s10.remove(k)
                else:
                    pass

        else:
            pass
        j=j+1
    ti = [[ti[a][0],ti[a][1]] for a in range(10) if not ti[a][1]==0]
    t[i] =ti
    i+=1
for i in range(N):
    for j in range(i+1,N):
        equal=0
        if len(t[i])==len(t[j]):
            for k1 in range(len(t[i])):
                if t[j][k1] in t[i]:
                    k1+=1
                    equal+=1
                else:
                    pass
            if equal == len(t[i]):
                 ans+=1
                 j+=1
        else:
            continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def check(s1, s2, i, j, memo):
    if memo[i] == memo[j] and memo[i] != -1:
        return 1
    elif memo[i] != memo[j] and memo[j] != -1:
        return 0

    s1_cnt = Counter(s1)
    s2_cnt = Counter(s2)

    if s1_cnt == s2_cnt:
        if memo[i] == -1:
            memo[i] = i
            memo[j] = i
        elif memo[j] == -1:
            memo[j] = memo[i]
        return 1

    else:
        return 0



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

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

    ans = 0
    memo = [-1 for i in range(N)]
    for i in range(N):
        for j in range(i+1, N):
            ans += check(S[i], S[j], i, j, memo)

    print(ans)


main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def check(s1, s2):
    s1_cnt = Counter(s1)
    s2_cnt = Counter(s2)
    if s1_cnt == s2_cnt:
        return 1
    else:
        return 0


N = int(input())

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
equal=0
ans=0
s=[list(input()) for _ in range(N)]
s10 = [i for i in range(10)]
i=0
t=['x' for i in range(N)]
for i in range(N):
    s10 = [x for x in range(10)]
    ti = [['xx',0] for x in range(10)]
    for j in range(10):
        if j in s10:
            ti[j][0]=s[i][j]
            ti[j][1]=1
            for k in range(j+1,10):
                if s[i][j]==s[i][k]:
                    ti[j][1]=ti[j][1]+1
                    s10.remove(k)
                else:
                    pass

        else:
            pass
        j=j+1
    ti = [[ti[a][0],ti[a][1]] for a in range(10) if not ti[a][1]==0]
    t[i] =ti
    i+=1
for i in range(N):
    for j in range(i+1,N):
        equal=0
        if len(t[i])==len(t[j]):
            for k1 in range(len(t[i])):
                for k2 in range(len(t[i])):
                    if t[i][k1]==t[j][k2]:
                        equal+=1
        if equal==len(t[i]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = []

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    y2 = [j for j, e in enumerate(ans_exa) if e == y1]
    ans_sum = ans_sum + int(len(y2))
    ans_exa.append(y1)

print(ans_sum)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
new_a = []

for k in range(n):
    a.append(str(input()))
    new_a.append( ''.join(list(sorted(a[k]))))

new_a.sort()

b = 0

for k in range(n-1):
    for m in range(k+1, n):
        if(new_a[k] == new_a[m]):
            b = b + 1

print(b)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
new_a = []

for k in range(n):
    a.append(str(input()))

for k in range(n):
    new_a.append( ''.join(list(sorted(a[k]))))

new_a.sort()

b = 0

for k in range(n-1):
    for m in range(k+1, n):
        if(new_a[k] == new_a[m]):
            b = b + 1

print(b)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
dic = {}
cnt = 0

for i in range(N):
	s = str(sorted(input()))
	if (s in dic):
		cnt += dic[s]
		dic[s] += 1
	else:
		dic[s] = 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

N = int(input())

result = 0
store = []
for _ in range(N):
    d = defaultdict(int)
    s = input()
    for c in set(s):
        d[c] += s.count(c)
    result += store.count(d)
    store.append(d)
print(result)

Submission status: Time Limit Exceeded

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

N = int(input())
Xd = [input() for _ in range(N)]
X = [list(c) for c in Xd] 
tmp = [[0]] * N
cnt = 0

for i in range(N):
	tmp[i] = collections.Counter(X[i]).most_common()
	tmp[i].sort()

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(input())
"""
def func(seq):
    seen = []
    list2 = [x for x in seq if x not in seen and not seen.append(x)]
    return len(list2)
"""
count = 0
list1 = []
for i in range(n):
    list1.append(Counter(s[i]))
for i in range(n-1):
    for j in range(i+1,n):
        if list1[i] == list1[j] and i != j:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    s.sort()
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                break
    print(ans)


def SortString(text):
    n = len(text)
    textList = [""] * n
    for i in range(len(text)):
        textList[i] = text[i]
    return "".join(sorted(textList))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                continue
    print(ans)


def SortString(text):
    n = len(text)
    textList = [""] * n
    for i in range(len(text)):
        textList[i] = text[i]
    return "".join(sorted(textList))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [""] * n
    ans = 0
    for i in range(n):
        s[i] = SortString(input())
    for i in range(n - 1):
        for j in range(i + 1, n):
            if s[i] == s[j]:
                ans += 1
            else:
                continue
    print(ans)


def SortString(text):
    textList = []
    for i in range(len(text)):
        textList.append(text[i])
    return "".join(sorted(textList))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

n = int(input())
moji = [list(map(str,input())) for index in range(n)]
count = int(0)

for index in range(n):
  moji[index].sort()

for index in range(n):
  for index2 in range(index+1,n):
    if moji[index]==moji[index2]:
      count+=1

print(count)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(N):
        if s[i] == s[j]:
            cnt += 1
 
print((cnt - N)//2)

Submission status: Time Limit Exceeded

Solution code:
import sys, math, fractions, itertools, collections


def solve(N: int, s: "List[str]"):
    S = []
    for ss in s:
        ss = sorted(ss)
        S.append(''.join(ss))
    c = collections.Counter(S).values()
    s = 0
    for cc in c:
        s += len(list(itertools.combinations(range(cc), 2)))
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections


def solve(N: int, s: "List[str]"):
    S = []
    for ss in s:
        ss = sorted(ss)
        S.append(''.join(ss))
    c = collections.Counter(S).values()
    s = 0
    for cc in c:
        s += len(list(itertools.combinations(range(cc), 2)))
    print(s)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
char_num = int(input())
char_length = 10
chars = []
for i in range(char_num):
    chars.append(input())


class CharArrange:
    def __init__(self, char):
        self.char = char

    def char_run(self):
        list_char = self.str2ord_list(self.char)
        for pos in range(1, len(list_char)):
            self.insert_sort(list_char, pos, list_char[pos])
        self.char = self.ordList2Str(list_char)

    def order_run(self, chars):
        for i, char in enumerate(chars):
            chars[i] = self.ord_list2ord_concat(self.str2ord_list(char))
        for pos in range(len(chars)):
            self.insert_sort(chars, pos, chars[pos])
        self.ord_chars = chars

    def str2ord_list(self, char):
        return list(map(ord, char))

    def ordList2Str(self, ordList):
        return ''.join(list(map(chr, ordList)))

    def ord_list2ord_concat(self, ord_list):
        self.ord_concat = ''
        for ord_num in ord_list:
            self.ord_concat += str(ord_num)
        return int(self.ord_concat)

    def insert_sort(self, A, pos, value):
        i = pos - 1
        while (i >= 0 and A[i] > value):
            A[i+1] = A[i]
            i = i - 1
        A[i+1] = value
        return A


for i, char in enumerate(chars):
    CA = CharArrange(char)
    CA.char_run()
    chars[i] = CA.char
CA.order_run(chars)
ord_chars = CA.ord_chars

counter = 0
for i in range(len(ord_chars) - 1):
    k = i + 1
    while (ord_chars[i] == ord_chars[k]):
        counter += 1
        if k == len(ord_chars) - 1:
            break
        else:
            k += 1
print(counter)

Submission status: Time Limit Exceeded

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

s = 0
for i in range(n-1):
  for k in range(i+1,n):
    if l[i] == l[k]:
      s +=1
 
print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s= [input() for i in range(N)]
s=list(map(sorted,s))
ans=0
dp = list(range(N))

for i in range(N):
        for k in range(i+1,N):
                if dp[i] == dp[k]:
                        ans += 1
                else:
                        if s[i] == s[k]:
                                ans += 1
                                dp[k]=min(dp[i],dp[k])
                                dp[i]=dp[k]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

c = 0
for i in range(n):
	for l in range(i+1,n):
		if ss[i] == ss[l]:
			c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
s = [ raw_input() for  _ in range(n) ]
x = [ ''.join(sorted(i)) for i in s ]
_x = sorted(x)
count = 0
for i in range(n-1):
    tmp = _x[i]
    for j in range(i+1,n):
        if tmp == _x[j]:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

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

x = [ "".join(sorted(i)) for i in s ]
_x = sorted(x)
count = 0
for i in xrange(n-1):
    tmp = _x[i]
    for j in xrange(i+1,n):
        if tmp == _x[j]:
            count += 1
        else:
            break

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for i in range(N):
    tmp = list(input())
    tmp.sort()
    S.append(tmp)
cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
dic = [''.join(sorted(i)) for i in s]
key = [i for i in set(dic)]
cnt = 0
cnt = [str(dic.count(i)-1) for i in key]
ad = [int(int(a) * (int(a)+1)/2) for a in cnt]
print(sum(ad))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
dic = [''.join(sorted(i)) for i in s]
key = [i for i in set(dic)]
cnt = 0
for i in key:
    a = dic.count(i)-1
    cnt += (a * (a+1))/2
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
ss = [sorted(i) for i in s]
dic = [''.join(i) for i in ss]
key = [i for i in set(dic)]
cnt = 0
for i in key:
    a = dic.count(i)-1
    cnt += (a * (a+1))/2
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

arr=[]

for i in range(n):
	z = [str(x) for x in input()]
	z.sort()
	#print(z)
	arr.append(z)

cnt = 0
#print(arr)

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

d = {}
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    if a in d:
        d[a]+=1
    else:
        d[a] = 1
ans = 0
for i in d:
    ans += len(list(itertools.combinations(range(d[i]), 2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
ss = [sorted(s[i]) for i in range(n)]
dic = [''.join(ss[i]) for i in range(n)]
key = [i for i in set(dic)]
cnt = 0
for i in key:
    a = dic.count(i)-1
    cnt += (a * (a+1))/2
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
C=[]
A=[]
B=[]
ans=0
for i in range(N):
  a=str(input())
  C.append(a)
for i in C:
  ab=[j for j in i]
  ab.sort()
  aaa="".join(ab)
  #print(aaa)
  if aaa in A:
    i=A.index(aaa)
    ans+=B[i]
    B[i]+=1
  else:
    A.append(aaa)
    B.append(1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

s_list.sort()
sorted_list = []
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    sorted_list.append(a)
    
C = collections.Counter(sorted_list)
ans = 0
for i in C:
    ans += len(list(itertools.combinations(range(C[i]), 2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

sorted_list = []
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l2.sort()
    a = ""
    for i in l2:
        a += i
    sorted_list.append(a)
    
C = collections.Counter(sorted_list)
ans = 0
for i in C:
    ans += len(list(itertools.combinations(range(C[i]), 2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
B=[]
ans=0
for i in range(N):
  a=str(input())
  aa=[]
  for i in a:
    aa.append(i)
  aa.sort()
  aaa=str("0123456789")
  for i in range(len(aa)):
    aaa=aaa.replace(str(i),aa[i])
  if aaa in A:
    i=A.index(aaa)
    ans+=B[i]
    B[i]+=1
  else:
    A.append(aaa)
    B.append(1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def judge(a,b):
  tmp=[0]*10
  res = 1
  for i in range(10):
    for j in range(10):
      if a[i] == b[j] and tmp[j] == 0:
        tmp[j] = 1
        break
  for i in range(10):
    if tmp[i] == 0:
      res = 0
  if res == 1:
    return 1
  else:
    return 0

tmp = input()
n = int(tmp)
s = [""] * 100000
for i in range(n):
  s[i] = input()

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

#s_list.sort()
l = []
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l.append(l2)
    
for i in l:
    i.sort()

l3 = []
for i in l:
    s = ""
    for j in i:
        s += j
    l3.append(s)
    
C = collections.Counter(l3)
ans = 0
for i in C:
    ans += len(list(itertools.combinations(range(C[i]), 2)))
print(ans)

Submission status: Time Limit Exceeded

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


def alpha2num(c):
    return ord(c) - ord('A') + 1 - 33


sx = []
for i in range(n):
    tmp = [alpha2num(j) for j in s[i]]
    tmp.sort()
    sx.append(tmp)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(N):
    s[i] = list(s[i])
    s[i].sort()
count = 0
for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

for i in string_list:
    temp.append(sorted(i))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

print(sum(c))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
for i in range(N):
    s[i] = list(s[i])
    s[i].sort()
count = 0
for i in range(N):
    for j in range(i + 1, N):
        if s[i] == s[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

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

s_list.sort()
l = []
for s in s_list:
    l2 = []
    for i in range(len(s)):
        l2.append(s[i])
    l.append(l2)
    
for i in l:
    i.sort()

l3 = []
for i in l:
    s = ""
    for j in i:
        s += j
    l3.append(s)
    
C = collections.Counter(l3)
ans = 0
for i in C:
    ans += len(list(itertools.combinations(range(C[i]), 2)))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
# from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += len(list(itertools.combinations(range(v), 2)))
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
a = int(input())
t = [input() for i in range(a)]
cnt = 0
for i in range(a):
    lst1 = list(t[i])
    for j in range(i+1,a):
        lst2 = list(t[j])
        if sorted(lst1) == sorted(lst2):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
words_list = []
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  words_list.append(''.join(ss))
count = 0
for i in range(len(words_list)):
  for j in range(i+1, len(words_list)):
    if words_list[i] == words_list[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
new = []

for i in range(num):
    a = list(input())
    a.sort()
    narr = ''.join(a)
    new.append(narr)

k = 0

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

print(k)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input()) 
t = [input() for i in range(n)]
c = 0
for i in range(n-1):
  trg_cnt = Counter(t[i])
  ath = t[i+1:]
  for a, j in enumerate( ath):
    tmp = Counter(j)
    if trg_cnt == tmp:
      c += 1
      del ath[a]
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [sorted(input()) for i in range(N)]
count = 0
li = []
for i in a:
    if i in li:
        count+=li.count(i)
    li.append(i)

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
N = int(input())
S = [''.join(sorted(list(str(input())))) for i in range(N)]

countDict = defaultdict(int)
for s in S:
    countDict[s] += 1


def makeTable(N):
    fac = [1 for i in range(N)]
    for i in range(2, N):
        fac[i] = fac[i - 1] * i
    return fac


fac = makeTable(N+1)


def binomialCoefficient(N, r):
    if N < r:
        return 0
    else:
        return fac[N] // (fac[r] * fac[N - r])


ans = 0
for v in countDict.values():
    if v >= 2:
        ans += binomialCoefficient(v, 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
import collections 
S = [collections.Counter(input()) for i in range(N)]
counter = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i] == S[j]:
            counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input()) 
t = [input() for i in range(n)]
c = 0
for i, trg in enumerate(t):
  trg_cnt = Counter(trg)
  ath = t[i+1:]
  for j in ath:
    tmp = Counter(j)
    if trg_cnt == tmp:
      c += 1
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [input() for i in range(N)]
li = []
count = 0
for i in range(N):
    li.append(sorted(a[i]))
for i in range(N):
    for k in range(1+i,N):
        if li[i] == li[k]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
a = [input() for i in range(N)]
li = []
count = 0
for i in a:
    li.append(collections.Counter(i))
for i in range(N):
    for k in range(1+i,N):
        if li[i] == li[k]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

l = []
count = 0
for i in range(N):
    # 比較がしやすいようにソートしたものを追加
    s = sorted(input())
    for j in range(i):
        if l[j] == s:
            count += 1
    l.append(s)

print(count)

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(len(s)):
    for j in range(i + 1, len(s)):
        if s[i] == s[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for i in range(n):
  s[i] = list(s[i])
  s[i].sort()
for j in range(n):
  for k in range(n):
    if j<k and s[j] == s[k]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#input N
N = int(input())

#define a list as a variable s:
s = list()

#input N words
for i in range(N):
    s.append(''.join(sorted(input())))

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

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []
dictList = []
for i in range(N):
    d = {}
    # 受け取った文字列を辞書型に{文字: 数}
    s.append(input())
    for c in s[i]:
        if c in d:
            d[c] += 1
        else:
            d[c] = 1
    # 比較がしやすいようにソートしたものを追加
    dictList.append(sorted(d.items()))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
slist = []
for _ in range(N):
    slist.append(dict(Counter(input())))

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

Submission status: Time Limit Exceeded

Solution code:
def f_c():

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

    c = 0
    for _ in range(n):
        si = s.pop()
        if si in s:
            c += s.count(si)
    print(c)

if __name__ == "__main__":
    f_c()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

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

preCount = 0
count = 0
for i in range(n):
	if i not in l:
		l.append(i)
		for j in range(i+1,n):
			if j not in l:
				if verify_anagrams(s[i],s[j]):
					l.append(j)
					preCount += 1
		if preCount != 0:
			count += cmb(preCount+1,2)
			preCount = 0

print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
def anahist(str1):
    dic = {}
    while str1 != '':
        s = str1[0]
        dic[s] = str1.count(s)
        str1 = str1.replace(s,'')
    return dic

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


N = int(input())
lsdic = []
ii = 0
for i in range(N):
    s1 = str(input())
    dic1 = anahist(s1)
    lsdic.append(dic1)
countls = []
while lsdic != []:
    dic2 = lsdic[0]
    countls.append(lsdic.count(dic2))
    while dic2 in lsdic:
        lsdic.remove(dic2)

count = 0
for i in countls:
    if i == 1:
        count += 0
    else:
        count += combinations_count(i, 2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l=[]
for i in range(n):
    l.append(input())
# print(l)
c=0
for i in range(n-1):
    for j in range(i+1,n):
        if(sorted(l[i])==sorted(l[j])):
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
#lis = list(set(s))
lis = list(map(list, set(map(tuple, s))))
#print(lis)
c = 0
for i in lis:
    indexes = [k for k, x in enumerate(s) if x == i]
    #print(i,indexes)
    k = len(indexes)-1
    #print(k)
    c += sum(range(0,k+1))
print(c)