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

count = 0
for i in range(n):
    for j in range(i+1, n):
        char_i = [0 for _ in range(26)]
        char_j = [0 for _ in range(26)]
        for c in s[i]:
            char_i[ord(c) - 97] += 1
        for c in s[j]:
            char_j[ord(c) - 97] += 1
        if char_i == char_j:
            count += 1

print(count)

Submission status: Time Limit Exceeded

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

num_char = [[0 for _ in range(26)] for _ in range(n)]
for i in range(n):
    for c in s[i]:
        num_char[i][ord(c) - 97] += 1

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
s = [None] + [list(input()) for _ in range(N)]

count = [None]*(N+1)

answer = 0
for i in range(1,N+1):
    count[i] = Counter(s[i])
    answer += count[:i].count(count[i])

print(answer)

Submission status: Time Limit Exceeded

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

from collections import defaultdict
from itertools import combinations

N = int(input())
H = defaultdict(list)

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

ret = 0
for v in H.values():
    ret += len(list(combinations(v, 2)))
print(ret)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
ans=[]
cnt=0
for _ in range(N):
    str_list=input()
    dic={}
    for i in range(10):
        if str_list[i] in dic:
            dic[str_list[i]]+=1
        else:
            dic[str_list[i]]=1
    ans.append(dic)
while len(ans)>1: 
    cnt+=ans.count(ans.pop(0))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=['' for i in range(N)]
for i in range(N):
    S[i]=sorted(input())
S.sort()
c=0
while S!=[]:
    cs=S.count(S[0])
    c=c+cs*(cs-1)//2
    del S[0:cs]
print(c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=['' for i in range(N)]
for i in range(N):
    S[i]=sorted(input())
S.sort()
c=0
for i in range(N):
    for j in range(N-i-1):
        if S[i]==S[j+i+1]:
            c=c+1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [''.join(sorted(input())) for i in range(n)]
b = []
ans = 0
for i in range(n) :
    x = a[i]
    if x in b :
        ans += b.count(x)
        b.append(x)
    else :
        b.append(x)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [sorted(input()) for i in range(n)]
b = []
ans = 0
for i in range(n) :
    x = ''.join(a[i])
    if x in b :
        ans += b.count(x)
        b.append(x)
    else :
        b.append(x)
print(ans)

Submission status: Time Limit Exceeded

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

import numpy as np

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

a_ascii = ord('a')
bins_of_char = np.zeros((N, 26),dtype=np.int)
num_of_anagram = 0

for i in range(N):
    S.append(input())

for i in range(N):
    for char in map(ord, S[i]):
        bins_of_char[i, char-a_ascii] += 1

for i in range(0, N-1):
    for j in range(i+1, N):
        if np.all(bins_of_char[i] == bins_of_char[j]):
            num_of_anagram += 1

print(num_of_anagram)

Submission status: Time Limit Exceeded

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

import numpy as np

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

a_ascii = ord('a')
bins_of_char = np.zeros((N, 26),dtype=np.int)
num_of_anagram = 0

for i in range(N):
    S.append(input())

for i in range(N):
    for char in S[i]:
        char_num = ord(char) - a_ascii
        bins_of_char[i, char_num] += 1

for i in range(0, N-1):
    for j in range(i+1, N):
        if np.all(bins_of_char[i] == bins_of_char[j]):
            num_of_anagram += 1

print(num_of_anagram)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
array = []
for i in range(N):
    s = input()
    dict = {}
    for j in range(len(s)):
        if s[j] not in dict:
            dict[s[j]] = 1
        else:
            dict[s[j]] += 1
    array.append(dict)

d = 0
for i in range(N):
    c=0
    for j in range(N):
        if i < j:
            if array[i] == array[j] and array[i] != 0:
                c += 1
                array[j] = 0
    if c != 0:
        d += int((c+1)*c/2)
print(d)

Submission status: Time Limit Exceeded

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

count=0

ss=[]
tt=[]

for i in range(N-1):
    for j in range(N-i-1):
        ss=sorted(s[i])
        tt=sorted(s[i+j+1])
        if ss==tt:
            count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
 
        _fact = [0] * (maxNum + 1)
        _fact[0] = _fact[1] = 1


        if divider != 0:
            _inv = [0] * (maxNum + 1)
            _finv = [0] * (maxNum + 1)
            _inv[0] = _inv[1] = _finv[0] = _finv[1] = 1
        else:
            _inv = []
            _finv = []

        for i in range(2, maxNum + 1):
            _fact[i] = _fact[i - 1] * i;
            if divider != 0:
                _fact[i] %= _divider
                _inv[i] = _divider - _inv[_divider % i] * (_divider // i) % _divider
                _finv[i] = _finv[i - 1] * _inv[i] % _divider

        self._fact = _fact
        self._inv = _inv
        self._finv = _finv

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
    cmb = Combination(max(di.values()), 0)

    ans = 0
    for num in di.values():
        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
s = [''.join(sorted(input())) for i in range(n)]
a=set(s)
c=0

for i in a:
    b=s.count(i)
    if b>1:
        c+=(b*(b-1))//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
s = [''.join(sorted(input())) for i in range(n)]
a=set(s)
c=0

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
        self._fact = [0] * (self._maxNum + 1)
        self._fact[0] = self._fact[1] = 1

        if self._divider != 0:
            self._inv = [0] * (self._maxNum + 1)
            self._finv = [0] * (self._maxNum + 1)
            self._inv[0] = self._inv[1] = self._finv[0] = self._finv[1] = 1

        for i in range(2, self._maxNum + 1):
            self._fact[i] = self._fact[i - 1] * i;
            if self._divider != 0:
                self._fact[i] %= self._divider
                self._inv[i] = self._divider - self._inv[self._divider % i] * (self._divider // i) % self._divider
                self._finv[i] = self._finv[i - 1] * self._inv[i] % self._divider

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())
    S = [input().strip() for i in range(N)]

    di = Counter()
    for s in S:
        s = ''.join(sorted(list(s)))
        di[s] += 1
    
    cmb = Combination(N, 0)
    ans = 0
    for num in di.values():
        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
        self._fact = [0] * (self._maxNum + 1)
        self._fact[0] = self._fact[1] = 1

        if self._divider != 0:
            self._inv = [0] * (self._maxNum + 1)
            self._finv = [0] * (self._maxNum + 1)
            self._inv[0] = self._inv[1] = self._finv[0] = self._finv[1] = 1

        for i in range(2, self._maxNum + 1):
            self._fact[i] = self._fact[i - 1] * i;
            if self._divider != 0:
                self._fact[i] %= self._divider
                self._inv[i] = self._divider - self._inv[self._divider % i] * (self._divider // i) % self._divider
                self._finv[i] = self._finv[i - 1] * self._inv[i] % self._divider

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())

    di = Counter()
    for i in range(N):
        s = ''.join(sorted(input().strip()))
        di[s] += 1
    
    cmb = Combination(N, 0)

    ans = 0
    for num in di.values():
        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
class Combination:
    _maxNum = 0
    _divider = 0
    _fact = []
    _inv = []
    _finv = []

    def __init__(self, maxNum, divider):
        self._maxNum = maxNum
        self._divider = divider
        self._fact = [0] * (self._maxNum + 1)
        self._fact[0] = self._fact[1] = 1

        if self._divider != 0:
            self._inv = [0] * (self._maxNum + 1)
            self._finv = [0] * (self._maxNum + 1)
            self._inv[0] = self._inv[1] = self._finv[0] = self._finv[1] = 1

        for i in range(2, self._maxNum + 1):
            self._fact[i] = self._fact[i - 1] * i;
            if self._divider != 0:
                self._fact[i] %= self._divider
                self._inv[i] = self._divider - self._inv[self._divider % i] * (self._divider // i) % self._divider
                self._finv[i] = self._finv[i - 1] * self._inv[i] % self._divider

    def nPk(self, n, k):
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            return 0
        return(self._fact[n] // self._fact[n - k])

    def nCk(self, n, k):
        ans = 0
        if(k > self._maxNum) or (n > self._maxNum) or (k > n) or (k < 0) or (n < 0):
            ans = 0
        elif self._divider == 0:
            ans = self.nPk(n, k)
            ans //= self._fact[k]
        else:
            ans = self._fact[n] * (self._finv[k] * self._finv[n - k] % self._divider) % self._divider

        return ans

def ABC137C_GreenBin():
    N = int(input().strip())

    di = Counter()
    for i in range(N):
        sl = sorted(input().strip())
        s = ""
        for c in sl:
            s += c    

        di[s] += 1
    
    cmb = Combination(N, 0)

    ans = 0
    for num in di.values():
        ans += cmb.nCk(num, 2)

    print(ans)


def main():
    ABC137C_GreenBin()

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

List=[''.join(sorted(input())) for i in range(N)]
List.sort()
List.extend("1")
cnt = 0

for i in range(N):
  a = List[i]
  b = List[i+1]
  if a != b:
    c = List.count(a)
    cnt = cnt + c * (c-1) / 2

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(sorted(input()))
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
N = int(input())
ans = 0
dict = defaultdict(int)
for i in range(N):
  s = list(input())
  s.sort()
  s = str(s)
  dict[s]+=1

for v in dict.values():
  if v >= 2:
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
dict = {}
for i in range(N):
  s = list(input())
  s.sort()
  s = str(s)
  if s in dict:
    dict[s] += 1
  else:
    dict[s] = 1

for v in dict.values():
  if v >= 2:
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
dict = {}
for i in range(N):
  s = input()
  s = list(s)
  s.sort()
  s = str(s)
  if s in dict:
    dict[s] += 1
  else:
    dict[s] = 1

for v in dict.values():
  if v >= 2:
    ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

dicts = [{} for _ in range(N)]
for i in range(N):
    for j in range(10):
        c = S[i][j]
        dicts[i][c] = dicts[i].get(c, 0) + 1

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

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=sorted([''.join(sorted(input())) for _ in range(n)])
cnt=0
print(sum([s.count(x)*(s.count(x)-1)//2 if s.count(x)>1 else 0 for x in set(s)]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[sorted(input()) for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if s[i]==s[j]:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
cnt=0
for i in range(n):
  for j in range(n):
    if i>=j:
      continue
    if sorted(s[i])==sorted(s[j]):
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
s = [input() for i in range(int(input()))]
c = [Counter(i) for i in s]
a = 0
for i in range(len(c)):
    for j in range(i+1, len(c)):
        if c[i] == c[j]:
            a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
	N = int(input())
	List = [str(input()) for i in range(N)]
	List_pre = []
	List_pre2 = []
	ans = 0
	for i in range(N):
		List_pre = list(List[i])
		# print(List_pre)
		List_pre.sort()
		List_pre = ''.join(List_pre)
		List_pre2.append(List_pre)
		# print(List_pre2)

		c = List_pre2.count(List_pre)
		# print("c is {}".format(c))
		ans = ans + (c-1)
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
	# start from 23:30
	import math
	def combinations_count(n, r):
		return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

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

	List_sort = []
	
	for i in range(N):
		List_pre = list(List[i])
		List_pre.sort()
		List_pre = ''.join(List_pre)
		# print(List_pre)
		List_sort.append(List_pre)
	# print(List_sort)

	List_unique = list(set(List_sort))
	# print(List_unique)

	List_ans = []

	for i in range(len(List_unique)):
		# print(i)
		c = List_sort.count(List_unique[i])
		if c <= 1:
			continue
		# print(c)
		else:
			List_ans.append(combinations_count(c,2))

	print(sum(List_ans))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(N):
    ans += s[i+1:].count(s[i])

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(N):
    string = list(input())
    string.sort()
    s.append("".join(string))

for i in range(N):
    tmp = s[i+1:]
    ans += tmp.count(s[i])

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=["".join(sorted(list(input()))) for i in range(N)]
ss = set(s)
cnt = 0
for i in ss:
  B = s.count(i)
  cnt += int(B * (B-1) /2)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from math import factorial
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
n=int(input())
s=[0]*n
dic={}
group={}
ans=0
dic2=[0]*n
for i in range(n):
    s[i]=sorted(input())
    dic[i]=str(Counter(s[i]))
    dic2[i]=dic[i]
group=Counter(dic2)

for i in list(group):
    if group[i]==1:
        continue
    ans+=cmb(group[i],2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(list(input())) for i in range(N)]
from itertools import permutations, combinations,combinations_with_replacement,product
L = combinations(range(N), 2)   #nCr
cnt = 0
for i in L:
  if s[i[0]]==s[i[1]]:
    cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=[sorted(list(input())) for i in range(N)]
t=[]
from collections import Counter

for i in s:
  a=Counter(i)
  t.append(a.most_common())

from itertools import permutations, combinations,combinations_with_replacement,product
L = combinations(range(N), 2)   #nCr
cnt = 0
for i in L:
  if t[i[0]]==t[i[1]]:
    cnt +=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# たぶんTLE
N = int(input())
S = tuple(''.join(sorted(list(input()))) for i in range(N))
ans = 0
for i in list(set(S)):
    m = S.count(i)
    ans += m*(m-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def ccc(n):
    #c(n,2)
    result = (n * (n-1))//2
    return result

def calculate(arr):
    if len(arr) == 0:
        return 0

    if len(arr) == 1:
        return 0

    criteron = arr[0]
    res = [0]

    nextarr = []

    for i in range(1,len(arr)):
        if tellIsTheSame(criteron,arr[i]):
            res.append(i)
        else:
            nextarr.append(arr[i])

    return ccc(len(res)) + calculate(nextarr)

def tellIsTheSame(s1,s2):
    s1 = list(s1)
    s2 = list(s2)

    s1.sort()
    s2.sort()

    length = len(s1)

    for i in range(length):
        if s1[i] != s2[i]:
            return False

    return True


arr = []

N = int(input())
for i in range(N):
    arr.append(input())


result = calculate(arr)
print(result)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
count=0
for i in range(N):
  s="".join(sorted(input()))
  count +=S.count(s)
  S +=[s]
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
count=0
for i in range(N):
  s=str(input())
  s_list=sorted(list(s))
  s=''.join(s_list)
  count +=S.count(s)
  S +=[s]
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
for i in range(N):
  s=str(input())
  s_list=sorted(list(s))
  S +=[s_list]

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

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":3.3,"y":2.3,"z":1.3}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)
ss = sorted(s)

a = 0 # a; pre ans

for i in range(n):
    for j in range(1, n - i):
        while ss[i] == ss[i + j]:
            a += 1
       

print(a)

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":3.3,"y":2.3,"z":1.3}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

a = 0 # a; pre ans

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":89,"y":97,"z":1.5}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

a = 0 # a; pre ans

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":89,"y":97,"z":101}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

a = 0 # a; pre ans

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":89,"y":97,"z":101}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

ss = sorted(s)

a = 0 # a; pre ans

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
alp = {"a":2, "b":3,"c":5,"d":7,"e":11,"f":13,"g":17,"h":19,"i":23,"j":29,
       "k":31,"l":37,"m":41,"n":43,"o":47,"p":53,"q":59,"r":61,"s":67,"t":71,
       "u":73,"v":79,"w":83,"x":89,"y":97,"z":101}

n = int(input())

s = []

for i in range(n):
    tss= str(input()) # tss; temporary str s
    ts = 1
    for j in range(10):
      ts *= alp[tss[j]] # ts; temporary s
    s.append(ts)

a = 0 # a; pre ans

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

print(a)

Submission status: Time Limit Exceeded

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



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

for i in range(n):
    cou.append(Counter(s[i]))

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
dic={}
for _ in range(n):
    s=input()
    s=sorted(s)
    s=''.join(s)
    if not s in dic.keys():
      dic[s]=1
    else: dic[s]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
dic={}
for s1 in s:
    s=sorted(s1)
    s=''.join(s)
    if not s in dic.keys():
      dic[s]=1
    else: dic[s]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
dic={}
for i in range(n):
    lst=sorted(list(s[i]))
    a=''
    for k in lst:
        a+=k
    if not a in dic.keys():
      dic[a]=1
    else: dic[a]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
for i in range(n):
    lst=sorted(list(s[i]))
    for j in range(i+1,n):
        lst1=sorted(list(s[j]))
        if lst==lst1:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
for i in range(n):
    lst=list(s[i])
    for j in range(i+1,n):
        lst1=list(s[j])
        for k in lst:
            for l in lst1:
                if k==l:
                    lst1.remove(l)
                    break
        if len(lst1)==0:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
ans=0
for i in range(n):
  for j in range(i+1,n):
    if s[i].count('a')!=s[j].count('a'):
        continue
    if s[i].count('b')!=s[j].count('b'):
        continue
    if s[i].count('c')!=s[j].count('c'):
        continue
    if s[i].count('d')!=s[j].count('d'):
        continue
    if s[i].count('e')!=s[j].count('e'):
        continue
    if s[i].count('f')!=s[j].count('f'):
        continue
    if s[i].count('g')!=s[j].count('g'):
        continue
    if s[i].count('h')!=s[j].count('h'):
        continue
    if s[i].count('i')!=s[j].count('i'):
        continue
    if s[i].count('j')!=s[j].count('j'):
        continue
    if s[i].count('k')!=s[j].count('k'):
        continue
    if s[i].count('l')!=s[j].count('l'):
        continue
    if s[i].count('m')!=s[j].count('m'):
        continue
    if s[i].count('n')!=s[j].count('n'):
        continue
    if s[i].count('o')!=s[j].count('o'):
        continue
    if s[i].count('p')!=s[j].count('p'):
        continue
    if s[i].count('q')!=s[j].count('q'):
        continue
    if s[i].count('r')!=s[j].count('r'):
        continue
    if s[i].count('s')!=s[j].count('s'):
        continue
    if s[i].count('t')!=s[j].count('t'):
        continue
    if s[i].count('u')!=s[j].count('u'):
        continue
    if s[i].count('v')!=s[j].count('v'):
        continue
    if s[i].count('w')!=s[j].count('w'):
        continue
    if s[i].count('x')!=s[j].count('x'):
        continue
    if s[i].count('y')!=s[j].count('y'):
        continue
    if s[i].count('z')!=s[j].count('z'):
        continue
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
c_list = []
ans = 0

for i in range(n):
  c = Counter(input())
  if c in c_list:
  	ans += c_list.count(c) 
  c_list.append(c)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
c_list = []
ans = 0

for i in range(n):
  c = Counter(input())
  ans += c_list.count(c)
  c_list.append(c)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
t = [input() for i in range(n)]
c_list = []
ans = 0

for x in t:
  c = Counter(x)
  ans += c_list.count(c)
  c_list.append(c)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
import itertools
li = []
for i in range (n):
    li.append(sorted(list(input())))
li.sort()

def comb(x,y):
    d = itertools.combinations(x,y)
    return len(list(d))

cnt = 0
a = []
for i in range(n-1):
    if li[i] == li[i+1]:
        a.append(i+1)
        if i == n-2:
            a.append("1")
            cnt += comb(a,2)
        
    else: 
        a.append("1")
        cnt += comb(a,2)
        a = []
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
l_list=[]

for _ in range(n):
  l=sorted(input())
  l_list.append(l)

count=0

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