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 = [None]*n
ans = 0

for i in range(n):
    s = input()
    s_s = ''.join(sorted(s))
    S[i] = s_s
S.sort()
for i in range(n-1):
    f = True
    F = True
    t = 1
    while F:
        for j in range(10):
            if S[i][j] != S[i+t][j]:
                f = False
                F = False
                break
        if f:
            ans += 1
            t += 1
            if t+i >= n:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [None]*n
ans = 0

for i in range(n):
    s = list(input())
    s.sort()
    s_s = ''.join(s)
    S[i] = s_s
S.sort()
#print(S)
for i in range(n-1):
    f = True
    F = True
    t = 1
    while F:
        for j in range(10):
            if S[i][j] != S[i+t][j]:
                f = False
                F = False
                break
        if f:
            ans += 1
            t += 1
            if t+i >= n:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(sorted(input()) for i in range(n))
p = 0
for i in range(n-1):
    for j in range(i+1,n):
        if s[i] == s[j]:
            p += 1

print(p)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
print(sum(s[i]==s[j] for i in range(n) for j in range(i+1, n)))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
a=[Counter(list(input()))for _ in range(n)]
ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[sorted(list(str(input())))for _ in range(n)]
ans = 0

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

Submission status: Time Limit Exceeded

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

cc = [sorted(Counter(x).most_common()) for x in a]
ans = 0
for i in range(N):
  for j in range(i + 1, N):
    if cc[i] == cc[j]:
      ans += 1
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

N=int(input())
s=[""]*N
count=0
for i in range(N):
  s[i]=input()
for i in range(N):
  for j in range(N):
    if(i!=j and collections.Counter(s[i])==collections.Counter(s[j])):
      count+=1
print(int(count/2))

Submission status: Time Limit Exceeded

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

# In[12]:


import collections


# In[10]:


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


# In[18]:


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

Submission status: Time Limit Exceeded

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

# In[10]:


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


# In[11]:


ans = 0
for i in range(N-1):
    myset = set(s[i])
    for j in range(i+1,N):
        for x in myset:
            if s[i].count(x) != s[j].count(x):
                break
        else:
            ans += 1
print(ans)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = []
for _ in range(N):
  L.append("".join(sorted(input())))
R = set(L)
c = 0
for r in R:
  t = L.count(r)
  c += t*(t-1)//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys
from io import StringIO
import unittest

from collections import Counter

def resolve():
    n = int(input())
    l = [Counter(list(input())) for _ in range(n)]
    cnt = 0

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

    print(cnt)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
acornistnt
peanutbomb
constraint"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
oneplustwo
ninemodsix"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa"""
        output = """4"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Time Limit Exceeded

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

SSS = set(SS)

for i in SSS:
    A = SS.count(i)
    count += (A*(A-1)) // 2

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [sorted(list(input())) for i in range(N)]
num = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[0]*n
for i in range(n):
  s[i]=sorted(input())
s.sort()
#print(s)
ans=0
for j in range(1,n):
  cnt=1
  while s[j]==s[j-cnt] and j-cnt>=0:
    cnt+=1
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

l = []
c = 0

for i in range(N):
    text = "".join(sorted(list(input())))
    l.append(text)
    l = sorted(l)
    
for j in range(N):
    for k in range(j+1,N):
        if l[j] == l[k]:
            c += 1
        else:
            break

print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
s = [list(input()) for S in range(n)]
cnt = 0
for i in range(n):
	s[i].sort()
duplicated_data = [tuple(d) for d in s]
unique_data = set(duplicated_data)
s_set = [list(d) for d in unique_data]
for j in range(len(s_set)):
	if s.count(s_set[j]) >= 2:
		k = s.count(s_set[j])
		cnt += math.factorial(k)//(math.factorial(k-2)*math.factorial(2))
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#<C>
from collections import Counter
import itertools
N = int(input())
lan = [Counter(list(input())) for n in range(N)]
#print(lan)
ans = 0
for l in itertools.combinations(lan, 2):
    if l[0] == l[1]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools

n = int(input())
S = [''.join(sorted(input())) for _ in range(n)]
d = [len(list(itertools.combinations(range(v),2))) for v in collections.Counter(S).values()]
print(sum(d))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [input() for _ in range(n)]
cnt = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        if ''.join(sorted(S[i])) == ''.join(sorted(S[j])):
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    n = int(input())
    s = [sorted(input()) for _ in range(n)]
    cnt = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if s[i] == s[j]:
                cnt += 1
    print(cnt)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

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

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**7 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    while True:
        if h >= mod :
            h = 0
        if hs[h][0] == 0:
            hs[h][0] += 1
            hs[h][1] += s
            break
        if hs[h][1] == s:
            hs[h][0] += 1
            break
        h += 1

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

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

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**5 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    while True:
        if h >= mod :
            h = 0
        if hs[h][0] == 0:
            hs[h][0] += 1
            hs[h][1] += s
            break
        if hs[h][1] == s:
            hs[h][0] += 1
            break
        h += 1

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

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

n = int(input())
sn = [input().strip('\n') for _ in range(n)]

mod = 10**5 + 7
hs = [[0, ''] for _ in range(mod)]

def hypo(s, Mod):
    h_num = 1
    for i in s:
        h_num = h_num * ord(i) % Mod
    return h_num

for s in sn:
    s = ''.join(sorted(s))
    h = hypo(s, mod)
    if hs[h][0] > 0:
        i = 0
        while True:
            if h + i >= mod :
                h = 0
                i = 0
            if hs[h+i][1] == s:
                hs[h+i][0] += 1
                break
            i += 1
    else:
        hs[h][0] += 1
        hs[h][1] += s

ans = 0
for j, t in hs:
    if j >= 2:
        ans += j * (j-1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i in range(n):
    s[i] = [s[i][j] for j in range(10)]
    s[i] = collections.Counter(s[i])

count = 0

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

count = (count - n)//2

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
c = 0

for i in range(n):
    s.append(sorted(input()))
    if len(s) >= 2:
        c += s[0:i].count(s[-1])

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = []
c = 0

for i in range(n):
    s.append(sorted(input()))
    if len(s) >= 2:
        for j in range(i):
            if s[j] == s[i]:
                c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
l=[]
v=[]

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in l:
        ans+=v[l.index(sorted_s)]
        v[l.index(sorted_s)]+=1
    else:
        l.append(sorted_s)
        v.append(1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
L=[]
V=[]
LV=[]

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in L:
        ind=L.index(sorted_s)
        V[ind]+=1
    else:
        L.append(sorted_s)
        V.append(1)

ans=0

for v in V:
    ans+=v*(v-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
L=[]
V=[]
LV=[]

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    c=sorted(Counter(si).elements())
    if c in L:
        ind=L.index(c)
        V[ind]+=1
    else:
        L.append(c)
        V.append(1)

ans=0

for v in V:
    ans+=v*(v-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
L=[]
V=[]

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    c=sorted(Counter(si).elements())
    v=L.count(c)
    if v==0:
        L.append(c)
        V.append(1)
    else:
        ind=L.index(c)
        V[ind]+=1


ans=0

for v in V:
    ans+=v*(v-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
L=[]
V=[]

for i in range(N):
    si=input()
    ci=Counter(si)
    c=sorted(ci.elements())
    v=L.count(c)
    if v==0:
        L.append(c)
        V.append(1)
    else:
        ind=L.index(c)
        V[ind]+=1


ans=0

for v in V:
    ans+=v*(v-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

for i in range(N):
    si=input()
    ci=Counter(si)
    c=sorted(ci.elements())
    L.append(c)


ans=0

for i in range(N):
    for j in range(1,N-i):
        # print('i:{0} j:{1} L{2}:{3} L{4}:{5} TF:{6}'.format(i,j,i,L[i],i+j,L[i+j],L[i]==L[i+j]))
        if L[i]==L[i+j]:
            ans+=1
        else:
            pass
# print(L)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N=int(input())
L=[]
for i in range(N):
    si=input()
    ci=Counter(si)
    L.append(ci)


ans=0

for i in range(N):
    for j in range(1,N-i):
        # print('i:{0} j:{1} L{2}:{3} L{4}:{5} TF:{6}'.format(i,j,i,L[i],i+j,L[i+j],L[i]==L[i+j]))
        if L[i]==L[i+j]:
            ans+=1
        else:
            pass

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
moji=[]
for x in range(n):
  a=sorted(input())
  a=''.join(a)
  moji.append(a)
  
aa=list(set(moji))
ans=0

for y in range(len(aa)):
  b=aa[y]
  s=moji.count(b)
  c=(s-1)*s/2
  ans+=c
  
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = []
    for _ in range(N):
        S.append(''.join(sorted(list(input()))))
    cnt = 0
    for i in range(N-1):
        for j in range(i+1,N):
            if S[i] == S[j]:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

s = [input() for _ in range(n)]

for i in range(n):
    s[i] = sorted(s[i])
    s[i] = "".join(s[i])

s = sorted(s)

c = []
for j in range(n):
    if j == 0 :
        c.append(s.count(s[0]))
    else :
        c.append(s.count(s[j]))
        if s[j] == s[j-1] :
            c[j] = 0

ans = 0
for k in range(n):
    ans += c[k]*(c[k]-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = ''.join(sorted(input()))
    for j in ls:
        if j == s:
            ans +=1
    ls.append(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = input()
    ls2 = []
    for i in range(10):
        ls2.append(s[i])
    ls3 = sorted(ls2)
    for j in ls:
        if j == ls3:
            ans +=1
    ls.append(ls3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans = 0
ls = []
for _ in range(n):
    s = input()
    ls2 = []
    for i in range(10):
        ls2.append(s[i])
    ls3 = ''.join(sorted(ls2))
    for j in ls:
        if j == ls3:
            ans +=1
    ls.append(ls3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    table = [''.join(sorted(list(input()))) for _ in range(N)]
    sort_table = list(set(list(table)))
    ans = 0
    for i in sort_table:
        n = table.count(i)
        if n <= 1:
            continue
        x = (n * (n - 1)) // 2
        ans += x

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math


def main():
    N = int(input())
    table = [''.join(sorted(list(input()))) for _ in range(N)]
    sort_table = list(set(list(table)))
    ans = 0
    for i in sort_table:
        n = table.count(i)
        if n <= 1:
            continue
        x = math.factorial(n) / (2 * math.factorial(n - 2))
        ans += x

    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lst = [0] * n
for i in range(n):
  s = input()
  for j in s:
    lst[i] += (12 ** (ord(j) - ord('a') + 1))
res = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if lst[i] == lst[j]:
      res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
diclst = [{} for i in range(n)]
for i in range(n):
  s = input()
  for j in s:
    diclst[i].setdefault(j, 0)
    diclst[i][j] += 1
res = 0
for i in range(n - 1):
  for j in range(i + 1, n):
    if diclst[i] == diclst[j]:
      res += 1
print(res)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [sorted(input()) for i in range(N) ]
counter = 0
for i in range(N):
    for j in range(i+1,N):
        for k in range(10):
            if S[i][k]!=S[j][k]:
                break
            if k == 9:
                counter +=1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s_list = [list(input()) for _ in range(n)]

cnt = 0
[ls.sort() for ls in s_list]
perm = itertools.permutations(list(range(1, n + 1)), 2)
for p, q in perm:
    if p > q:
        if s_list[p-1] == s_list[q-1]:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
l = [k for k in range(n)]

count = []
for i in range(n)[::-1]:
    count.append(Counter(s[i]))

ans = 0
for j in itertools.combinations(l, 2):
    if count[j[0]] == count[j[1]]:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n=int(input())
a=[list(input()) for _ in range(n)]
count=0
for i in range(n):
  for j in range(i+1,n):
    if Counter(a[i])==Counter(a[j]):
      count+=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())
s = [input() for s in range(N)]
l = []
for i in range(0,N-1):
  for j in range(i+1,N):
    l.append(verify_anagrams(s[i],s[j]))

count = 0
for i in range(0,len(l)):
  if(l[i] == True):
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[input() for _ in range(n)]
alp=[chr(ord('a')+i) for i in range(26)]
sc=[[0] for _ in range(n)]
for i in range(n):
  for j in alp:
    sc[i].append(s[i].count(j))
cnt=0

for i in range(n):
  cnt+=sc.count(sc[0])-1
  sc.pop(0)
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(i+1,n):
    for k in s[i]:
      if s[j].count(k)!=s[i].count(k):
        break
    else:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = [list(input()) for i in range(n)]
for i in range(n):
  S[i].sort()

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
n = int(input())
S = [list(input()) for i in range(n)]

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if set(S[i]) != set(S[j]):
      ans += 0
    else:
      if tuple(S[j]) in permutations(S[i]):
        ans += 1
      else:
        ans += 0
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())

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

ans = 0

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

count=0
for k,v in enumerate(s): 
  for i in range(k+1, len(s)):
     count += 1 if v == s[i] else 0 

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=["".join(sorted(input())) for _ in range(n)]
c=0
for i in range(n):
  for j in range(i+1,n):
    if s[i]==s[j]:
      c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

s=[]
for i in range(n):
  read=list(input())
  read.sort()
  s.append(read)

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
C = []
for i in range(N):
    C.append("".join(sorted(input())))
B = set(C)
ans = 0
for j in B:
    t = C.count(j)
    if t > 1:
        ans += int(t*(t-1)/2 )
# 1->0, 2->1, 3->3, 4->6, 5->10 :: nC2
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]
cnt=0
for i in range(n):
  s=input()
  s=sorted(s)
  a.append(s)
  if s not in b:
    b.append(s)
for i in b:
  x=a.count(i)
  if x>0:
    cnt+=x*(x-1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
n = int(input())
S = [input() for i in range(n)]
ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    if  tuple(S[i]) in list(permutations(S[j])):
      ans += 1
    else:
      pass
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

def check_equal(a_dict, b_dict):
    result = True
    for k_a, v_a in a_dict.items():
        if k_a not in b_dict:
            result = False
            break
        if a_dict[k_a] != b_dict[k_a]:
            result = False
            break
    
    return result


if __name__ == "__main__":    
    N = int(input())
    count_list = []

    for i in range(N):
        sentence = input()
        c = dict(collections.Counter(sentence))
        count_list.append(c)

    total = 0
    for i in range(N):
        for j in range(i+1, N):
            total += check_equal(count_list[i], count_list[j])

    print(total)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
s = []
for i in range(N):
  q = sorted(input())
  s.append(q)
s.sort()
 
 
ans = 0
 
for m in range(N):

  k=0
  for i in range(m+1,N):
    if collections.Counter(s[m]) == collections.Counter(s[m+1+k]):
      ans += 1
      k += 1
    else:
      break
    
print(ans)

Submission status: Time Limit Exceeded

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


ans = 0
for m in range(N):
  for n in range(m+1,N):
    if collections.Counter(s[m]) == collections.Counter(s[n]):
      ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [0]*N
ans = 0

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

for i in range(N-1) :
    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
import itertools

N = int(input())
moji_lis = list()
 
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)

for i in range(N):
    moji_lis.append(input())
    
p = itertools.combinations(moji_lis, 2)
ans = 0
for j in p:
    if verify_anagrams(j[0], j[1]):
        ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N=int(input())
s=[]
count=0
for _ in range(N):
    s.append(str(input()))
for i in itertools.combinations(s,2):
    if sorted(i[0])==sorted(i[1]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [sorted(input()) for i in range(n)]
    cnt = 0
    s.sort()
    sb = []
    while s:
        sa = s.pop()
        cnt += s.count(sa) 
        if sa == sb:
            cnt + 1
        sb = sa
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [sorted(input()) for i in range(n)]
    cnt = 0

    while s:
        sa = s.pop()
        cnt += s.count(sa) 
    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [input() for i in range(n)]
    a = [[0] * 26 for _ in range(n)] 
    al = 'abcdefghijklmnopqrstuvwxyz'
    cnt = 0

    for i in range(n):
        for j in s[i]:
            a[i][al.index(j)] += 1 


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

    print(cnt)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for i in range(n)]
a = [[0] * 26 for _ in range(n)] 
al = 'abcdefghijklmnopqrstuvwxyz'
cnt = 0

for i in range(n):
    for j in s[i]:
        a[i][al.index(j)] += 1 


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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
ans = 0
for i in range(N):
    a = list(s[i][:])
    a.sort()
    for j in range(i+1,N):
        b = list(s[j][:])
        b.sort()
        if ''.join(a)==''.join(b):ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def dictstr(s):
    d = {}
    for i in range(10):
        if s[i] in d:
            d[s[i]] += 1
        else:
            d[s[i]] = 1
    return d

stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
s = stdin[1:]
ans = 0
for i in range(N):
    for j in range(i+1,N):
        d = dictstr(s[i])
        flag = True
        for k in range(10):
            if s[j][k] in d:
                d[s[j][k]] -= 1
                if d[s[j][k]]<0:
                    flag = False
                    break
            else:
                flag = False
                break
        if flag:ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
n = int(input())
a = [0]*n
b = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for j in range(n):
    t = list(input())
    t.sort()
    m = " ".join(t)
    a[j] = m
c = collections.Counter(a)
for k in range(len(c)):
    if c.most_common()[k][1] > 1:
        b += combinations_count(c.most_common()[k][1], 2)
    else:
        continue
print(b)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S={}
SS=[]
answer=0
for _ in range(N):
    s=input()
    s=sorted(s)
    s=str(s)
    if s in SS:
        answer+=S[s]
        S[s] += 1
    else:
        SS.append(s)
        S[s]=1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = []
    ans = 0
    
    for _ in range(n):
        ss = ''.join(sorted(input()))
        s.append(ss)
    
    for i in range(n):
        for j in range(i+1, n):
            if s[i] == s[j]:
                ans += 1
            
    print(ans)
       
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import collections


def main():
    n = int(input())
    s = [input() for _ in range(n)]
    d = []
    ans = 0
    for ss in s:
        c = collections.Counter(ss)
        d.append(c)
    for i in range(n):
        for j in range(i + 1, n):
            if d[i] == d[j]:
                ans += 1              
    print(ans)  
        
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

N = int(input())
A = {}
for i in range(N):
    S = list(input())
    S.sort()
    S = ''.join(S)
    A[S] = A.get(S, 0) + 1

ans = 0
for i in A.values():
    if i > 1:
        iL = [j for j in range(i)]
        ans += len(list(itertools.combinations(iL, 2)))
        
print(ans)