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:
import sys, collections, math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
uq = []
chk = {}
for x in sys.stdin.readlines():
    x = x.rstrip()
    tmp = collections.Counter(sorted(x))
    h = ''
    for i in tmp:
        h += i + str(tmp[i])
    if h not in uq:
        uq.append(h)
    else:
        if h not in chk:
            chk.setdefault(h, 1)
        chk[h] += 1
ans = 0
for x in chk:
    ans += combinations_count(chk[x], 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
Y = set()
c = 0
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  u = t[0]+t[1]+t[2]+t[3]+t[4]+t[5]+t[6]+t[7]+t[8]+t[9]
  if u in Y:
    c += S.count(u)
  S.append(u)
  Y.add(u)

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S =[]
c = 0
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  for j in range(i):
    if S[j] == t:
      c += 1
  S.append(t)

print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S =[]
for i in range(N):
  s = input()
  t = [s[0],s[1],s[2],s[3],s[4],s[5],s[6],s[7],s[8],s[9]]
  t.sort()
  S.append(t)

c = 0
for i in range(N-1):
  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):
    a = list(input())
    a.sort()
    s.append(''.join(a))

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

for i in range(n):
    a = list(s[i])
    a.sort()
    s[i] = ''.join(a)

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

s_sorted = list(map(''.join, list(map(sorted, s))))

cnt = 0
while(s_sorted):
    k = s_sorted.pop(0)
    tmp_key = [i for i, x in enumerate(s_sorted) if x == k]
    cnt += sum(range(len(tmp_key) + 1))
    while(tmp_key):
        k = s_sorted.pop(tmp_key.pop())

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
slst = [input() for _ in range(n)]
cnt = 0
for j in range(1,n):
    for i in range(j-1):
        lst_1 = list(slst[i])
        lst_2 = list(slst[j])
        count_1 = Counter(lst_1)
        count_2 = Counter(lst_2)
        so1 = sorted(count_1.items())
        so2 = sorted(count_2.items())
        for k,l in zip(so1,so2):
            if  k != l:
                break
        else:
          cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

s2 = list(set(s))
ans = 0

for i in s2:
    j = s.count(i)
    ans += j * (j-1)//2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [[' '.join(sorted(i)) for i in input().split()] for _ in range(N)]
count = 0
for i in range(len(s)):
  for j in range(i+1, len(s)):
    if s[i][0] == s[j][0]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections


def resolve():
    N = int(input())
    s = [input() for _ in range(N)]
    ans = 0
    for tmp in itertools.combinations(s, 2):
        d1 = collections.defaultdict(int)
        d2 = collections.defaultdict(int)
        for ch in tmp[0]:
            d1[ch] += 1
        for ch in tmp[1]:
            d2[ch] += 1
        if d1 == d2:
            ans += 1
    print(ans)


resolve()

Submission status: Time Limit Exceeded

Solution code:
import collections
n=int(input())
l=[input() for i in range(n)]
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    ans+=collections.Counter(l[i])==collections.Counter(l[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import Counter
n, *lst = sys.stdin.read().split()
n = int(n)
c = []
for i in lst:
  tmpc = Counter(i)
  tmpc = ''.join(str(tmpc[chr(key)]) if chr(key) in tmpc else str(0) for key in range(97, 124))
  c.append(tmpc)

c = Counter(c)
res = 0
for key in c:
  res += c[key] * (c[key] - 1) // 2
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
S = []
for i in range(N):
    S.append(Counter(list(str(input()))))

counter = 0
for i in range(N):
    for j in range(i+1, N):
        if S[i]==S[j]:
            counter += 1
        else:
            continue

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = [0] * n
c = [0] * n
count = 0
for i in range(n):
    s[i] = input()
    c[i] = collections.Counter(s[i])
    for j in range(i):
        if c[i] == c[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = [0] * n
c = [0] * n
count = 0
for i in range(n):
    s[i] = input()
    c[i] = collections.Counter(s[i])
for i in range(n):
    for j in range(i+1,n):
        if c[i] == c[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[0]*n
count=0
for i in range(0,n):
  temp=str(input())
  temp=sorted(list(temp))
  temp="".join(temp)
  s[i]=temp
  count=count+s.count(s[i])-1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[0]*n
count=0
for i in range(0,n):
  temp=str(input())
  temp=sorted(list(temp))
  temp="".join(temp)
  s[i]=temp
  for j in range(0,i):
    if s[i]==s[j]:
      count=count+1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
	s=list(input())
	s.sort()
	s=''.join(s)
	dic[s]+=1
	ans=0
	for (k,v) in dic.items():
		ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

s2 = set(s)
cnt = [0] * len(s2)
for i in s2:
    cnt.append(s.count(i))

ans = 0
for k in range(len(cnt)):
    ans += (cnt[k])*(cnt[k]-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

s2 = set(s)
cnt = [0] * len(s2)
for i in s2:
    cnt.append(s.count(i))

ans = 0
for k in range(len(cnt)):
    l = list(range(0,cnt[k]))
    ans += sum(l)
print(ans)

Submission status: Time Limit Exceeded

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

s2 = set(s)
cnt = []
for i in s2:
    cnt.append(s.count(i))

ans = 0
for k in range(len(cnt)):
    l = list(range(0,cnt[k]))
    ans += sum(l)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

counter = []
for i in range(N):
    counter.append(Counter(s[i]))

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

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
	s=list(input())
	s.sort()
	s=''.join(s)
	if s not in dic.keys():
		dic[s]=1
	else:
		dic[s]+=1
	ans=0
	for (k,v) in dic.items():
		ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
dic={}
for _ in range(n):
	s=list(input())
	s.sort()
	s=''.join(s)
	if s not in dic.keys():
		dic[s]=1
	else:
		dic[s]+=1
	ans=0
	for (k,v) in dic.items():
		ans += v*(v-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = []
count = 0
f = 1
for i in range(n):
    a = input()
    li.append("".join(sorted(a)))
li.sort()
for i in range(n-1):
    if li[0] == li[1]:
        f += 1
        del li[0]
    else:
        count += (f*(f-1))//2
        f = 1
        del li[0]
count += (f*(f-1))//2
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

l_2 = set(l)
ans = 0
k = l.count
for j in l_2:
    i = k(j)
    ans += int((i*(i-1))/2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

l_2 = set(l)
ans = 0
for j in l_2:
    i = l.count(j)
    ans += int((i*(i-1))/2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from math import factorial

# input
N = int(input())
S = {}
for n in range(N):
    s = input()
    counter = Counter(s)
    S[n] = counter

matched = []
count = {}
cnt = 0
m_append = matched.append
for k in S.keys():
    if S[k] in matched:
        continue
    add = list(S.values()).count(S[k])
    if add > 2:
        m_append(S[k])
        cnt += factorial(add) // factorial(2) // factorial(add - 2)
    elif add == 2:
        m_append(S[k])
        cnt += 1
    else:
        pass
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy

n = int(input())
s = list(list(input()) for i in range(n))
count = 0

for i in range(n):
  for j in range(i + 1, n):
    test = copy.copy(s[j])
    for k in s[i]:
      if(k in test):
        test.remove(k)
    if(len(test) == 0):
      count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []

index = []
tg = 0

for i in range(N):
    a = sorted(input())
    # a.sort()
    sa = ''.join(a)
    # print(sa)
    for k in range(len(index)):
        
        if sa == index[k]:
            s[k] += 1
            tg = 1
            
    if tg == 0:
        index.append(sa)
        s.append(1)
    
    tg = 0
        

ans = []

# print(index)

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for r in range(2):
            # c = r
            d *= (s[i] - r)
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = sorted(input())
    # a.sort()
    sa = ''.join(a)
    # print(sa)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

ans = []

#print(index)

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for r in range(2):
            # c = r
            d *= (s[i] - r)
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []

index = []

for i in range(N):
    a = list(input())
    a.sort()
    sa = ''.join(a)
    # print(sa)
    if sa in index:
        s[index.index(sa)] += 1
        
    else:
        index.append(sa)
        s.append(1)

ans = []

for i in range(len(s)):
    
    if s[i] >= 2:
        d = 1
        for r in range(2):
            # c = r
            d *= (s[i] - r)
            
        d //= 2
        
        ans.append(d)
    
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
slist = []
for i in range(N):
    slist.append(''.join(sorted(list(input()))))

i = 0
count = 0
for s in slist:
    i += 1
    for target in slist[i:]:
        if target == s:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

string=itertools.combinations(s,2)
st1,st2=[],[]
count=0

for i in string:
  st1.extend(i[0])
  st2.extend(i[1])
  
  st1.sort()
  st2.sort()
  
  if st1==st2:
    count+=1
    
  st1.clear()
  st2.clear()
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N = int(input())
S = [[str(x) for x in input()] for _ in range(N)]
S = [''.join(sorted(x)) for x in S]

cnt=0
for i, j in itertools.combinations(S, 2):
    if i==j:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools
N = int(input())
S = [input() for _ in range(N)]
S_cnt = [collections.Counter(s) for s in S]

cnt=0
for i, j in itertools.combinations(S_cnt, 2):
    if i==j:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())

ws = []

for i in range(N):
    w = input()
    ws.append(Counter(w))

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
def count(data):
    dic = {}
    for d in data:
        if d in dic:
            dic[d] += 1
        else:
            dic[d] = 1
    return dic

n = int(input())
data = []
for _ in range(n):
    s = input()
    data.append(count(s))
ans = 0
for i in range(n):
    for ii in range(i+1, n):
        if data[i] == data[ii]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = [sorted(list(input())) for nesya in range(n)]
c = 0
for s in s_list:
  for a in s_list:
    if s == a:
      c += 1
print((c-n)//2)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
li = []
lic = []
count = 0
for i in range(n):
    lic.append(i+1)
    lia = list(input())
    lia.sort()
    li.append(lia)
lib = list(itertools.combinations(lic,2))
for i in range(len(lib)):
    if li[lib[i][0]-1] == li[lib[i][1]-1]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
li = []
lic = []
count = 0
for i in range(n):
    lic.append(i+1)
for i in range(n):
    lia = list(input())
    lia.sort()
    li.append(lia)
lib = list(itertools.combinations(lic,2))
for i in range(len(lib)):
    if li[lib[i][0]-1] == li[lib[i][1]-1]:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
s = sorted(s)
s = sorted([''.join(sorted(list(t))) for t in s])
count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if s[j] > s[i]:
            break
        elif s[j] == s[i]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# ABC137C

n = int(input())
s = [0] * n
for i in range(n):
    s[i] = input()
s = [sorted(list(t)) for t in s]
count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        count += s[i] == s[j]
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


n=int(input())
S = []
for i in range(n):
    S.append(input())

cnt = 0
for i,s in enumerate(S):
    for j,s2 in enumerate(S):
        if i >= j: continue
        if Counter(s) == Counter(s2):
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
num = []
count = 0
for i in range(n):
    s = str(input())
    
    num.append(sorted(list(map(ord, list(s)))))
    
    

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [0]*n
num = [[0]*26 for i in range(n)]
count = 0
for i in range(n):
    s[i] = str(input())
    for j in range(10):
        mozi = ord(s[i][j])
        num[i][mozi-97] += 1

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
sd = []
cnt = 0
for i in range(N):
    str = ','.join(sorted(input()))
    cnt += sd.count(str)
    sd.append(str)
print(cnt)

Submission status: Time Limit Exceeded

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


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
sin = [''.join(sorted(input())) for _ in range(n)]

ans = []
combi_list =[]

for i in set(sin):
    if sin.count(i)  > 1:
        combi_list.append(sin.count(i))

for j in set(combi_list):
    x = list(itertools.combinations(range(j), 2))
    ans.append(len(x)*combi_list.count(j))

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
sin = [''.join(sorted(input())) for _ in range(n)]

ans = []
combi =[]

for i in set(sin):
    if sin.count(i)  > 1:
        combi.append(sin.count(i))

for j in combi:
    x = list(itertools.combinations(range(j), 2))
    ans.append(len(x))

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
sin = [''.join(sorted(input())) for _ in range(n)]

ans = []

for i in set(sin):
    if sin.count(i)  > 1:
        combi = list(itertools.combinations(range(sin.count(i)), 2))
        ans.append(len(combi))

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
A = []
for _ in range(n):
    A.append([sorted(input())])
    B = sorted(A) 
for i in range(n-1):
    s = B[i]
    for j in range(i+1, n):
        t = B[j]
        if s == t:
            cnt += 1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
A = []
for _ in range(n):
    A.append([sorted(input())]) 
for i in range(n-1):
    s = sorted(A[i])
    for j in range(i+1, n):
        t = sorted(A[j])
        if s == t:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cnt = 0
A = []
for _ in range(n):
    A.append(input()) 
for i in range(n-1):
    s = sorted(A[i])
    for j in range(i+1, n):
        t = sorted(A[j])
        if s == t:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    s=[sorted(list(input())) for i in range(n)]
    cnt=0
    for i in range(n):
        for j in range(i+1,n):
            if s[i]==s[j]:
                cnt+=1
    print(cnt)
resolve()

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
d_list = []
cnt = 0
for i in range(n):
    s = str(input())
    
    d = collections.Counter(s)

    if i >= 1:
        if d in d_list:
            cnt += d_list.count(d)
    d_list.append(d)
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
s_list = []
d_list = []
cnt = 0
for i in range(n):
    s_list.append(str(input()))
    
    d = defaultdict(int)
    for j in range(len(s_list[i])):
        d[s_list[i][j]] += 1

    if i >= 1:
        if d in d_list:
            cnt += d_list.count(d)
    d_list.append(d)
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
S = [sorted(sys.stdin.readline().strip()) for _ in range(N)]

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

# def mycheck(a,b):
#     b = list(b)
#     for i in range(len(a)):
#         if a[i] in b:
#             b.remove(a[i])
#         else:
#             return False
#     return True
ls = []
for i in range(n):
    t = Counter(s[i])
    ls.append(t)
# print(ls)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
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:
n=int(input())
a=[]
for i in range(n):
    s=input()
    s=sorted(s)
    a.append("".join(s))
ans=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if a[i]==a[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import collections

cnt = 0

N = int(input())
string_counters = [collections.Counter(input()) for i in range(N)]

cnt = 0
for i in range(len(string_counters)-1):
    pattern_i = string_counters[i]
    for j in range(i+1, len(string_counters)):
        pattern_j = string_counters[j]
        if pattern_i == pattern_j:
            cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
def myAnswer(N:int,S:list) -> int:
   counter = 0
   dic = {}
   for s in S:
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s] = 0
   for value in dic.values():
      counter += (value * (value + 1)) // 2
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = ["".join(sorted(list(input()))) for _ in range(N)]
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
n = int(input())
ls = list(input() for i in range(n))
a = []
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(ls[j])
    t.sort()
    m = " ".join(t)
    a.append(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 = [None] * N
for i in range(N):
    S[i] = input()

C = []
for s in S:
    C.append(sorted(s))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = [collections.Counter(input()) for i in range(n)]
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:
N = int(input())
dic = []
count = []
ans = 0

for i in range(N):
  check = 0
  S = "".join(sorted(input()))
  for j in range(len(dic)):
    if dic[j] == S:
      ans += count[j]
      check = 1
      count[j] += 1
      break
    
  if check == 0:
    dic.append(S)
    count.append(1)


print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

N = int(input())
dic = []
ans = 0

for i in range(N):
  S = "".join(sorted(input()))
  l = bisect_left(dic, S)
  r = bisect_right(dic, S)
  ans += r-l
  dic.insert(l,S)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[]
for i in range(N):
  A.append(list(input()))
c=0  
for i in range(len(A)-1):
  for j in range(i+1,len(A)):
    if sorted(A[i])==sorted(A[j]):
      c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
count=0
dd=[]
for i in range(n):
  s=input()
  dic={}
  for j in range(0,10):
    k=s[j]
    if k in dic:
      dic[k]+=1
    else:
      dic[k]=1
  
  count+=dd.count(dic)
  dd.append(dic)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
from collections import defaultdict, deque, Counter
import sys
from bisect import bisect_left
import heapq
import math
import numpy as np

sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

c =[]
same = []

for i in range(n):
    ci = Counter(str(stdin.readline().rstrip()))
    if ci in c:
        same[c.index(ci)] += 1
    else:
        c.append(ci)
        same.append(1)

ans = 0
for i in range(len(same)):
    ans += same[i] * (same[i] - 1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ss=[input() for _ in range(n)]
ans=0
for i,s in enumerate(ss):
    for s_ in ss[i+1:]:
        if sorted(s)==sorted(s_):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = []
for i in range(n):
  s = str(input())
  slist.append(s)
sortedlist = []
for j in range(n):
  sorteds = []
  sorteds = sorted(slist[j])
  sortedlist.append("".join(sorteds))
analist = list(set(sortedlist))
analen = len(analist)
anacount = [0] * analen
dic = dict(zip(analist, anacount))
for k in sortedlist:
  if k in analist:
    dic[k] += 1
count = 0
for m in dic.keys():
  count += dic[m] * (dic[m] - 1) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
slist = []
for i in range(n):
  s = str(input())
  slist.append(s)
sortedlist = []
for j in range(n):
  sorteds = []
  sorteds = sorted(slist[j])
  sortedlist.append("".join(sorteds))
analist = list(set(sortedlist))
analen = len(analist)
anacount = [0] * analen
for k in range(analen):
  anacount[k] = sortedlist.count(analist[k])
anasum = 0
for q in anacount:
  anasum += q * (q - 1) / 2
print(int(anasum))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


def main():
    N = int(input())
    s = [Counter(input()) for _ in range(N)]
    ans = 0
    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 sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    S = [collections.Counter(iss()) for _ in range(N)]

    ret = 0
    for s in S:
        ret += S.count(s) - 1

    print(ret//2)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
for n in range(N):
    s=sorted(list(input()))
    s=''.join(s)
    S.append(s)

import itertools
ans=0
for i in range(N):
    for j in range(N):
        if i!=j:
            if S[i]==S[j]:
                ans+=1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[]
for n in range(N):
    s=sorted(list(input()))
    s=''.join(s)
    S.append(s)

import itertools
ans=0
for s1,s2 in list(itertools.combinations(S,2)):
    if s1==s2:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

c = 0
for i in range(len(s)):
    t1 = list(s[i])
    t1.sort()

    for j in range(i+1, len(s)):
        t2 = list(s[j])
        t2.sort()

        if t1 == t2:
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations
N = int(input())
s = [tuple(input()) for _ in range(N)]
dp = [False]*N
ans = 0
for i in range(N):
    for j in range(i+1, N):
        if s[j] in permutations(s[i]):
            ans += 1
print(ans)