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 collections


def p_c():
    n = int(input())
    ans = 0

    l = [collections.Counter(input()) for _ in range(n)]

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

    print(ans)


if __name__ == '__main__':
    p_c()

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
sl=[]
count=0
for i in range(N):
  sl.append(input())
dl=[]
for i in range(N):
  lx=list(sl[i])
  dicx={}
  for j in range(10):
    countix=lx.count(lx[j])
    dicx[lx[j]]=countix
  dl.append(dicx)
for i in range(N-1):
  for j in range(i+1,N):
    if dl[i]==dl[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:

if __name__ == '__main__':
    n = int(input())
    dict_list = []
    for i in range(n):
        dict = {}
        s = input()
        for i in s:
            if i in dict:
                dict[i] = dict[i] + 1
            else:
                dict[i] = 1
        dict_list.append(dict)

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
li = [[],[]]
for _ in range(n):
  si = str(input())
  di = {}
  for i in range(10):
    if si[i] in di.keys():
      di[si[i]] += 1
    else:
      di[si[i]] = 1
  frag = True
  for j,st in enumerate(li[0]):
    if di == st:
      li[1][j] += 1
      frag = False
  if frag:
    li[0].append(di)
    li[1].append(1)
sm = 0
for j in li[1]:
  sm += j*(j-1)//2
print(sm)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

def main():
    n = int(input())
    s = deque(sorted(["".join(sorted(input())) for i in range(n)]))
    ans = 0
    while len(s) != 0:
        cnt = s.count(s[0])
        for i in range(cnt):
            s.popleft()
        if cnt == 1:
            continue
        ans += (cnt * (cnt - 1)) // 2
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
n = int(input())
candidate = [sorted(list(input())) for _ in range(n)]
ans = 0
candidate.sort()

# 有理数型をインポート
# 組合せの総数


def comb(n, k):

    if n < 0 or k < 0:
        pdt = 0

    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)

    # 戻り値をint型にするために分子を取り出す
    return pdt.numerator


cnt = 1
for i in range(1, n):
    if candidate[i] != candidate[i - 1]:
        ans += comb(cnt, 2)
        cnt = 1
    else:
        cnt += 1
        if i == n - 1:
            ans += comb(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

n=int(input())
S = list()
for i in range(n):
	S.append(list(input()))
cnt = 0
for i in range(n-1):
	for j in range(i+1,n):
		M=copy.deepcopy(S[i])
		N=copy.deepcopy(S[j])
		if(len(M)==len(N)):
			for k in range(len(M)):
				if(M[k] in N) :
					x = N.index(M[k])
					N[x] = 0
				else:
					break
			if(N.count(0)==len(N)):
				cnt+=1
			else:
				pass
		else:
			pass
print(cnt)

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
while s != []:
    string = s.pop()
    s_new = []
    temp = 1
    for mojiretu in s:
        if string == mojiretu:
            temp += 1
        else:
            s_new.append(mojiretu)
    ans += temp * (temp-1) // 2
    s = s_new.copy()

print(ans)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ls=sorted(["".join(sorted(list(input()))) for i in range(n)])
ls_set=sorted(list(set(ls)))

count=0
for i in ls_set:
    c=ls.count(i)
    count+=c*(c-1)/2
    ls=ls[c:]
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

tmp = []
counter = 0
for i in range(N):
    new_str = ''.join(list(sorted(str(input()))))
    tmp.append(new_str)
    for j in range(i):
        if str(new_str) == str(tmp[j]):
            counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [list(input()) for _ in range(N)]
l = []
cnt = 0
for st in s:
    st.sort()
    l.append("".join(st))
l.sort()
a = list(set(l))
for uni in a:
    c = l.count(uni)
    if c>1:
        cnt += (1+(c-1))*(c-1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

nlist=[""]*N

for i in range(N):
    t=str(input())
    t = ''.join(sorted(t))
    nlist[i] = t

cnt=1
sum=0
for i in range(N):
    cnt=1
    cnt=nlist.count(nlist[i])
    if(cnt!=1):
        sum+=cnt-1

print(int(sum/2))

Submission status: Time Limit Exceeded

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

for i in range(N-1):
  s1 = s[i]
  s1list = list(s1)
  for j in range(i+1, N):
    s2 = s[j]
    s2list = list(s2)
    for c in s1list:
      try:
        s2list.remove(str(c))
      except:
        continue
    if not s2list:
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

N = input()
S = []
for i in range(int(N)):
    S.append(input())
dics = [{} for i in range(int(N))]
for i in range(int(N)):
    for s in S[i]:
        if s in dics[i]:
            dics[i][s] += 1
        else:
            dics[i][s] = 1
cnt = 0
for i in range(len(dics)):
    for j in range(len(dics)):
        if j<=i: continue
        src = dics[i]
        trg = dics[j]
        if src == trg:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#coding: utf-8

N = int(input())


s_list = []
for i in range(N):
    input_string = input()
    tmp_list = []
    for s in input_string:
        tmp_list.append(s)
    tmp_list.sort()
    sorted_string = ""
    for s in tmp_list:
        sorted_string = sorted_string + s
    s_list.append(sorted_string)


count = 0

while len(s_list) != 0:
    for i in range(1, len(s_list)):
        if s_list[0] == s_list[i]:
            count = count + 1

    del(s_list[0])
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = [input() for i in range(n)]
b = []
for i in range(n):
  b.append(''.join(sorted(a[i])))
c = list(set(b))
cnt = []
for i in range(len(c)):
  cnt.append(b.count(c[i]))
ans = 0
for i in cnt:
  ans += int(i*(i-1)/2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
z=0

for i in range(0,n):
    m=input()
    y=list(m)
    y.sort()
    m=''.join(y)
    s.append(m)



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


z=(z-n)//2

print(z)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = []
ans = 0
for _ in range(n):
    l = sorted(input())
    tmp = ""
    for i in range(len(l)):
      tmp += l[i]
    S.append(tmp)

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())
s = [input() for i in range(n)]
for i in range(n):
	s[i] = ''.join(list(sorted(s[i])))
ns = sorted(s)
t=0
for i in range(n-1):
	for j in range(1,n-i):
		if ns[i]==ns[i+j]:
			t += 1
		else:
			break
	continue
print(t)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
s_af = [""]*N
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    for k in range(10):
        s_af[i] += s[i][k]
s_af.sort()
count = 0
for i in range(N):
    for j in range(i+1,N):
        if s_af[i] == s_af[j]:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

List = []
for i in range(N):
    temp = {}
    for j in range(10):
        if A[i][j] in temp:
            temp[A[i][j]] += 1
        else:
            temp[A[i][j]] = 1
    List.append(temp)
    
ans = 0
i = 0
while i < len(List):
    j = i+1
    while j < len(List):
        if List[i] == List[j]:
            ans += 1
        j += 1
    i += 1

print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(N):
    s = [v for v in input()]
    s.sort()

    hit = 0
    for i in range(length):
        t, num = S[i]
        if s == t:
            S[i] = (t, num + 1)
            hit = 1
            break
    if hit == 0:
        S.append((s, 1))
        length += 1

ans = 0
for i in range(length):
    t, num = S[i]
    ans += (num * (num - 1)) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def fun(x):
    ret = 1
    while x:
        ret *= x
        x -= 1
    return ret

def cmb(n,r):
    if n==r: return 1
    else: return fun(n) // (fun(r)*fun(n-r))




n = int(input())

ss = [sorted(input()) for i in range(n)]
ss.sort()

tmp = ss[0]
sss = [0]*n
j = 0
for i in range(n):
    if tmp == ss[i]: sss[j]+=1
    else:
        tmp = ss[i]
        j += 1
        sss[j]+=1

ans = 0
for i in sss:
    if i-1: ans += cmb(i,2)
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0
for i, x in enumerate(s[:-1]):
    for y in s[i+1:]:
        if x == y:
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
    x = [x for x in input()]
    x.sort()
    s.append(''.join(x))

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [list(input()) for i in range(N)]
count = [[0 for i in range(26)] for j in range(N)]

for i in range(N):
    for j in range(len(S[i])):
        count[i][ord(S[i][j]) - ord('a')] += 1
#print(count)

A = [i for i in range(N)]
for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            continue
        if count[i] == count[j]:
            A[j] = A[i]
#print(A)
COUNT = 0
for i in range(max(A) + 1):
    num = A.count(i)
    #print(num)
    if num == 0:
        continue
    COUNT += num*(num-1)//2
print(COUNT)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [input() for _ in range(N)]
answer = 0
for i1 in range(N):
  s1 = S[i1]
  s1hist = dict((x, s1.count(x)) for x in s1)
  for i2 in range(i1+1,N,1):
    s2 = S[i2]
    s2hist = dict((x, s2.count(x)) for x in s2)
    if s1hist == s2hist:
      answer += 1
print(answer)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
s=sorted([sorted(list(input())) for i in range(N)])
count=0
l=[]
for i in range(N-1):
    if not s[i] in s[i+1:][0]:
        l.append(i)
l.append(N-1)
s=[ s[i] for i in range(N) if i in l  ]
s_l=len(s)

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

Submission status: Time Limit Exceeded

Solution code:
def green_bin(n,s):
    count = 0
    for i in range(n-1):
        si = sorted(s[i])
        for j in range(i+1,n):
            if i == j:
                continue
            else:
                sj = sorted(s[j])
            if si == sj:
                count += 1

    return count
if __name__ == '__main__':
    n = int(input())
    s = [ input() for i in range(n)]

    print(green_bin(n,s))

Submission status: Time Limit Exceeded

Solution code:

N = int(input())
s = [""]*N
a =[[0]*26 for i in range(N)]
b =[""]*N

cn =ord("a")

for i in range(N):
    s[i] = list(input())
    for j in range(26):
        a[i][j] = s[i].count(chr(cn+j))
    b[i] ="".join(str(a[i]))

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=int(input())
l=[]
for i in range(n):
    l.append(input())
alp=[chr(_) for _ in range(97,97+26)]
res=[]
ans=0

for j in l:
    ll=list(j)
    tmp=[0]*26
    for k in ll:
        m=0
        for x in alp:
            if k==x:
                tmp[m]+=1
            m+=1
    aa="".join(map(str,tmp))
    res.append(aa)

for y in res:
    tmp2=0
    for z in res:
        if y==z:
            tmp2+=1
    ans+=tmp2-1

print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:

N = input()
dic = {}
for i in range(0, N):
    str = "".join(sorted( raw_input() ))
    if str in dic.keys():
        dic[str] += 1
    else:
        dic[str] = 0
        
sum = 0
for v in dic.values():
    sum += v * (v + 1) / 2

print sum

Submission status: Time Limit Exceeded

Solution code:
import  numpy   as  np
N   =   int(input())
A   =   []

Alphabet    =   np.zeros((N,26)).astype(np.uint8)

counter     =   0

for i in range(N):
    A.append(sorted(input()))

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

Submission status: Time Limit Exceeded

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

def main():
    N = int(input())
    s = []
    for i in range(N):
        s.append("".join(sorted(list(input().strip()))))
    s = sorted(s)

    ans = 0
    for i in range(N-1):
        for j in range(i+1, N):
            ok = True
            for k in range(10):
                if s[i][k] != s[j][k]:
                    ok = False
                    break
            if ok:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

sn = []
count = 0

for i in range(n):
  sn.append(sorted(Counter(list(input())).items()))


for i in range(n - 1):
  for j in range(i+1,n):
    if len(sn[i]) != len(sn[j]):
      continue
    if sn[i] == sn[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import json

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

ana = []
for i in range(n):
  alpha = {}
  for j in range(10):
    if alpha.get(str[i][j]) == None:
      alpha[str[i][j]] = 1
    else:
      alpha[str[i][j]] += 1
  ana.append(sorted(alpha.items(), key=lambda x:x[0]))

anastr = []
for i in range(n):
  anastr.append(json.dumps(ana[i]))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

count = 0
start = 0
while(start<N):
    for j in range(len(s)):
        if j <= start:
            pass
        else:
            if s[start] == s[j]:
                count += 1

    start += 1

    if s==False:
        break

print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strings = []
strlist = []
for i in range(n):
  strings.append(input())
  strlist.append([])

for i in range(n):
  for c in strings[i]:
    strlist[i].append(c)
  strlist[i].sort()
  
anagram_count = 0
for i in range(n):
  for j in range(n):
    if not i == j:
      if strlist[i] == strlist[j]:
        anagram_count += 1

print(int(anagram_count / 2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

my_list = [None] * N

for i in range(N):
    s_i = sorted(input())
    my_list[i] = s_i

sum = 0

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

print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools, os
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)
def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('- {} -> {}'.format(name, val), file=sys.stderr)
            return None

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

"""
a-zの文字数カウントする
[1,1,0,,,]
[1,1,0,,,]
[1,2,1,,,]

などのリストが得られる。
setしてカウント
"""

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

chars = []
for s in S:
    char_list = []
    for char in s:
        char_list.append(char)
    char_list.sort()
    char_list = ''.join(char_list)
    chars.append(char_list)
#  print(chars)
ans = 0
done_list = []
for char in chars:
    #  print('char' , char)
    if char in done_list:
        continue

    cnt = chars.count(char)
    if cnt == 1:
        continue
    done_list.append(char)
    ans += combinations_count(cnt, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

saved = []
cnt_ls = []
saved_ap = saved.append
cnt_ap = cnt_ls.append

for i in range(N):
    s = "".join(sorted(input()))
    if s not in saved:
        saved_ap(s)
        cnt_ap(1)
    else:
        cnt_ls[saved.index(s)] += 1

result = 0

for i in range(len(cnt_ls)):
    tmp = cnt_ls[i]
    result += int( tmp * (tmp - 1) / 2 )

print(result)

Submission status: Time Limit Exceeded

Solution code:
import collections
import itertools


def p_c():
    n = int(input())
    ans = 0

    l = [collections.Counter(input()) for _ in range(n)]

    b = list(itertools.combinations(l, 2))
    for i in b:
        if i[0] == i[1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_c()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
strings = [input() for _ in range(N)]

str_count = [Counter(l) for l in strings]

ans = 0
for x in range(len(str_count)):
    for y in range(x + 1, len(str_count)):
        if str_count[x] == str_count[y]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = [0]*N
for n in range(N):
  chars = sorted(list(input()))

  if chars in s:
    ans[s.index(chars)] += 1
  else:
    s.append(chars)

for idx,x in enumerate(ans):
  ans[idx] = x * (x+1) // 2
print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())


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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
def factorial(n):
    a = 1
    for i in range(1, n + 1):
        a *= i
    return a

def nCr(n,r):
    if r > n:
        return 0
    return factorial(n) // factorial(r) // factorial(n - r)

def nC2(n):
    if n < 2:
        return 0
    else:
        return n * (n-1) // 2


####
N = int(input())
sorted_dic = {}
for i in range(N):
    s = "".join(sorted(input()))
    v = 0
    if s in sorted_dic:
        v = sorted_dic[s]
    sorted_dic[s] = v + 1

ans = 0
for k in sorted_dic:
    v = sorted_dic[k]
    #print(k,v,factorial(v),factorial(2), factorial(v - 2), nCr(v, 2))
    ans = ans + nCr(v, 2)

print(ans)

Submission status: Time Limit Exceeded

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

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

print(num)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
 
N = int(input())
data = sorted([''.join(sorted(input().rstrip())) for n in range(N)])
count = 0
while data:
    number = data.count(data[0])
    if number > 1:
        count += number - 1
    del data[0]
    
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


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

ans=0
for i in range(N):
    for j in range(i+1,N):
#         print(i,j)
#         print(verify_anagrams(A[i],A[j]))
        if verify_anagrams(A[i],A[j]):
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

arr = []

for i in range(n):
    arr.append(list(input()))

for s in arr:
    s.sort()

count = 0

for i in range(n):
    s1 = arr[i]
    for j in range(i+1, n):
        s2 = arr[j]
        result = True
        for k in range(10):
            if(s1[k] != s2[k]):
                result = False
                break
        if(result):
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

A = []
for i in range(N):
    a = sorted(list(input()))
    A.append(a)
    
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        if A[i] == A[j]:
            cnt += 1
            
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [input() for i in range(n)]
r = 0
    
for i in range(n):
    for j in range(i+1, n):
        anagram = True
        
        for k in range(10):
            t = l[i][k]
            if not (l[i].count(t) == l[j].count(t)):
                anagram = False
                break
        if anagram:
            r += 1

print(r)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [0 for i in range(N)]
S[0] = ''.join(sorted(list(input())))
ans = 0
for i in range(1, N):
    S[i] = ''.join(sorted(list(input())))
S2 = list(set(S))
for j in range(len(S2)):
    x = S.count(S2[j])
    if x != 1:
        ans += x * (x - 1) / 2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# ABC 137, c
from collections import Counter
import math
n = int(input())
S = []
for i in range(n):
    s = ''.join(sorted(input()))
    S.append(s)
count = 0
for i in range(n):
    for j in range(i+1, n):
        if S[i] == S[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
  s.append("".join(sorted(input())))
s.sort()
sss=set(s)
ans=0
for _ in sss:
  l=s.count(_)
  ans+=l*(l-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = []
ans = 0
for i in range(N):
  s = input()
  S.append(s)
for i in range(N-1):
  for j in range(i+1,N):
    A = [False]*10
    B = [False]*10
    for k in range(10):
      for l in range(10):
        if S[i][k] == S[j][l] and A[k] == False and B[l] == False:
          A[k] = True
          B[l] = True
          continue
    if all(A):
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import combinations

a = 0
for i,j in combinations(s,2):
  if i == j:
    a+=1
print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
L = 0
for c in range(0,N):
    S.append(str(input()))
    c += 1
for d in range(0,N):
    S[d] = ''.join(sorted(S[d]))
for i in range(0,N):
    for l in range(i+1,N):
        if S[i] == S[l]:
            L += 1
print(L)

Submission status: Time Limit Exceeded

Solution code:
mst_l = [chr(i) for i in range(97,97+26)]

n = int(input())
l = [input() for _ in range(n)]
l = ["".join(map(str, [x.count(a) for a in mst_l])) for x in l]
result = 0
for i in range(n-1):
    result += len([x for x in l[i+1:] if x == l[i]])
print(result)

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 sorted(S[i]) == sorted(S[j]):
            ans += 1
            #print(S[i],S[j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = []
for i in range(n):
    s.append(Counter(list(input())))
ans = s.copy()
cnt_ans = 0
while len(s):
    remove_list = []
    cnt = 0
    for i in range(1, len(s)):
        if s[0] == s[i]:
            cnt += 1
            remove_list.append(s[i])
    cnt = int((cnt+1) * (cnt) / 2)
    cnt_ans += cnt
    remove_list.append(s[0])
    for lst in remove_list:
        s.remove(lst)
print(cnt_ans)

Submission status: Time Limit Exceeded

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

ans=[[0 for i in range(26)] for j in range(n)]
check="abcdefghijklmnopqrstuvwxyz"

for j in range(n):
    for i in range(26):
        ans[j][i]=s[j].count(check[i])

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
    
n = int(input())
S = []
count = []
for i in range(n):
    s = list(str(input()))
    #print(s)
    #print(sorted(s))
    s = sorted(s)
    if i == 0:
        S.append(s)
        count.append(0)
        continue
    if s in S:
        #print(S,s)
        #print(S.index(s))
        count[S.index(s)] += 1
        #count += 1
        #S.append(s)
    else:
        S.append(s)
        count.append(0)
#print(count)
ans = 0
for cnt in count:
    if cnt==0:
        continue
    ans += cmb(cnt+1, 2)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [''.join(sorted(input())) for i in range(n)]

    sset = set(sl)

    ans = 0
    for s in sset:
        scount = sl.count(s)
        ans += sum([i for i in range(scount)])

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

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

n = int(input())
s = [''.join(sorted(input())) for i in range(n)]
s_set = set(s)

ans = 0
for i in s_set:
  ans += cmb(s.count(i), 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted([x for x in input()]) for i in range(N)]

check = [False] * N
cnt = 0
for i in range(N - 1):
    part = 0
    if check[i]:
        continue
    for j in range(i + 1, N):
        if check[j]:
            continue
        if s[i] == s[j]:
            part += 1
            check[j] = True
    cnt += (part + 1) * part // 2

print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(n):
	s[i].sort()

ans = 0
# print(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:
N = int(input())
L = []
M0 = []
M = []
C = 0
for i in range(N):
  L.append(input())
for j1 in range(N):
  for j2 in range(10):
    M0.append(L[j1][j2])
  M.append(M0)
  M0 = []
for i in range(N):
  M[i].sort()
for l in range(N):
  for m in range(N):
    if m > l:
      if M[m] == M[l]:
        C += 1
print(C)

Submission status: Time Limit Exceeded

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

N = int(input())
s = []
for i in range(N):
    c = input()
    c = list(c)
    c.sort()
    s.append(c)

count = 0
while len(s) > 1:
    d = s.pop(-1)
    for j in s:
        if d == j:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

S = []
cnt = 0

for i in range(N):
    s = "".join(sorted(list(input())))
    cnt += S.count(s)
    S.append(s)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

dic = []
cnt = [0 for _ in range(N)]

for i in range(N):
    s = input()
    test = {}
    for ss in s:
        if not ss in test:
            test[ss] = 1
        else:
            test[ss] += 1
    for j, prev in enumerate(dic):
        if prev == test:
            cnt[j] += 1
            break
    dic.append(test)

ans = 0
for i in cnt:
    for j in range(1, i+1):
        ans += j
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
s.sort()
s_af = [""]*N
for i in range(N):
    for k in range(10):
        s_af[i] += s[i][k]
count = 0
for i in range(N):
    for j in range(i+1,N):
        if s_af[i] == s_af[j]:
            count += 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for i in range(n):
    d = {}
    for s in input():
        if s not in d.keys():
            d[s] = 1
        else:
            d[s] += 1
    l.append(d)

ans = 0
i = 0
while i < len(l):
    ans += sum([l[i] == l[n] for n in range(i+1,n)])
    i += 1
print(ans)