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

#print(s)

#出現文字列
sdict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    for j in range(i+1,N):
        sdict[s_i] = 1

for i in sdict.values():
    ans += i*(i-1)//2

print(ans)

Submission status: Time Limit Exceeded

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

#出現文字列
sdict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in sdict:
        #組み合わせが増えるので
        sdict[s_i]+= 1
        continue

    for j in range(i+1,N):
        sdict[s_i] = 1

for i in sdict.values():
    ans += i*(i-1)//2

print(ans)

Submission status: Time Limit Exceeded

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

#出現文字列
dict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in dict:
        #組み合わせが増えるので
        dict[s_i]+= 1

        ans += dict[s_i]
        continue

    for j in range(i+1,N):
        dict[s_i] = 0

print(ans)

Submission status: Time Limit Exceeded

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

#出現文字列
dict = {}

ans = 0

for i in range(N):

    s_i = str(s[i])

    if s_i in dict:
        #組み合わせが増えるので
        dict[s_i] = dict[s_i] + 1

        ans += dict[s_i]
        continue

    for j in range(i+1,N):
        dict[s_i] = 0

print(ans)

Submission status: Time Limit Exceeded

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

#[print(i) for i in s]

ans = 0

for i in range(N):
    for j in range(i+1,N):
        if s[i] == s[j]:
            #print("s[" + str(i)+"]" + " = s[" + str(j)+"]" )
            ans+=1

if not ans == 0:
    print(ans)
else:
    print(0)

Submission status: Time Limit Exceeded

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


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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [0]*n
for i in range(n):
  v = list(input())
  vs = sorted(v)
  vss = "".join(vs)
  s[i]=vss


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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
  v = list(input())
  vs = sorted(v)
  vss = "".join(vs)
  s.append(vss)


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

print(counter)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = []
cnt = 0

for i in range(0, n):
    line = collections.Counter(str(input())).items()
    line_sorted = sorted(line, key=lambda x: x[0])
    cnt += s.count(line)
    s.append(line)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

i, ans=0, 0
flag=[-1]*n

while i<n:
    if flag[i] == 1:
        i+=1
        continue
    flag[i] = 1
    tmp = 1
    for j in range(i+1, n):
        if s[i] == s[j]:
            flag[j] = 1
            tmp+=1
    ans+=(tmp*(tmp-1)//2)
    i+=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter
N = int(input())
s = [input() for _ in range(N)]
comb = list(itertools.combinations(range(N), 2))

count=0
for i in range(len(comb)):
    if Counter(s[comb[i][0]].upper()) == Counter(s[comb[i][1]].upper()):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L = [ sorted(input()) for i in range(N)]
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:
N = int(input())
S = []
for i in range(N):
	s = list(map(str, input()))
	s.sort()
	S.append(s)
	
count = 0
for i in range(N):
	for j in range(i):
		if S[i] == S[j]:
			count += 1
			
print(count)

Submission status: Time Limit Exceeded

Solution code:
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


n=int(input())

s=[]
cnt=[]

for i in range(n):
    tmp=input()
    tmp = ''.join(sorted(tmp))
    
    for j in range(len(s)):
        if tmp==s[j]:
            cnt[j]+=1
            break
    else:
        s.append(tmp)
        cnt.append(1)
ans=0
for c in cnt:
    if(c>1):
        ans+=combinations_count(c, 2)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
L = [ sorted(Counter(input()).items()) for i in range(N)]
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 collections

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

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

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 j in range(N-1):
    for k in range(j+1, N):
        if (collections.Counter(S[j]) == collections.Counter(S[k])):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list()
for i in range(n):
    b = list(input())
    b.sort()
    a.append("".join(b))
# for i in range(n):
#     a.append(input())
# for i, youso in enumerate(a):
#     b = list()
#     for j in youso:
#         b.append(j)
#     b.sort()
#     x = str()
#     for j in b:
#         x += j
#         a[i] = x
x = 0

#TLE ver.
# for i, youso in enumerate(a):
#     for j in range(i, n-1):
#         if youso == a[j+1]:
#             x += 1
# print(x)

#TLE改良版
a.sort()
for i in range(n-1):
    if a[i] == a[i+1]:
        for j in range(i+1, n):
            if a[i] == a[j]:
                x += 1
            else:
                break
    else:
        continue

#いらない処理
# y = 0
# for i in range(1, x+1):
#     y += i

print(x)

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
a = list()
for i in range(n):
    a.append(input())
for i, youso in enumerate(a):
    b = list()
    for j in youso:
        b.append(j)
    b.sort()
    x = str()
    for j in b:
        x += j
        a[i] = x
x = 0
#TLE ver.
# for i, youso in enumerate(a):
#     for j in range(i, n-1):
#         if youso == a[j+1]:
#             x += 1
# print(x)
a.sort()
for i in range(n-1):
    if a[i] == a[i+1]:
        for j in range(i+1, n):
            if a[i] == a[j]:
                x += 1
            else:
                break
    else:
        continue

# y = 0
# for i in range(1, x+1):
#     y += i
print(x)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[input().split() for i in range(n)]
import collections as c
import itertools
d=list(itertools.combinations(range(n),2))
cnt=0
for i in d:
    x=c.Counter(a[i[0]][0])
    y=c.Counter(a[i[1]][0])
    if x==y:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

L2={}
for i in range(n-1):
      for j in range(i+1,n):
            if L[i]==L[j]:
                  if L[i] not in L2:
                        L2[L[i]]=1
                  else:
                        L2[L[i]]+=1
print(sum(L2.values()))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import sys

from scipy.misc import comb

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N = int(readline())
    S = read().split()
    S = list(map(lambda x: sorted(x.decode('UTF-8')), S))

    A = defaultdict(int)
    for i in range(N):
        s = ''.join(S[i])
        A[s] += 1

    cnt = 0
    for i in A.values():
        cnt += comb(i, 2)

    print(int(round(cnt)))


main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list()
for i in range(n):
    a.append(input())
for i, youso in enumerate(a):
    b = list()
    for j in youso:
        b.append(j)
    b.sort()
    x = str()
    for j in b:
        x += j
        a[i] = x
x = 0
for i, youso in enumerate(a):
    for j in range(i, n-1):
        if youso == a[j+1]:
            x += 1
print(x)

Submission status: Time Limit Exceeded

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

out = 0
for i in range(n):
  out += L[i+1:n].count(L[i])
  
print(out)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

out = 0
for i in range(n):
  for j in range(i+1, n):
    c = sorted(L[i])
    if c == sorted(L[j]):
      out += 1
      
print(out)

Submission status: Time Limit Exceeded

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

out = 0
for i in range(n):
  for j in range(i+1, n):
    if sorted(L[i]) == sorted(L[j]):
      out += 1
      
print(out)

Submission status: Time Limit Exceeded

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

print(x)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]
x = []
values = []
combs = []

for i in set(s):
  if s.count(i) > 1:
    values.append(s.count(i))
for i in values:
  combs.append(i*(i-1)//2)
print(sum(combs))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
x = []
values = []
combs = []
def cmb(h, r):
    if h - r < r: r = h - r
    if r == 0: return 1
    if r == 1: return h
    r = int(r)

    humerator = [h - r + k + 1 for k in range(r)]
    dehominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = dehominator[p - 1]
        if pivot > 1:
            offset = (h - r) % p
            for k in range(p-1,r,p):
                k = int(k)
                offset = int(offset)
                humerator[k - offset] /= pivot
                dehominator[k] /= pivot

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

    return result

for i in s:
  x.append("".join(i))
for i in set(x):
  if x.count(i) > 1:
    values.append(x.count(i))
for i in values:
  combs.append(cmb(i,2))
print(sum(combs))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S=[]
for i in range(N):
  s=str(input())
  u=''
  t=list(s)
  t.sort()
  for j in range(len(list(t))):
    u +=t[j]
  S +=[u]
count=0
for i in range(N-1):
  for j in range(i+1,N):
    if S[i]==S[j]:
      count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i in range(n):
  s = input()
  s = sorted(s)
  S.append(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:
# 2019-11-16 14:51:41(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left as bi_l, bisect_right as bi_r, insort_left as in_l
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
# import heapq
# import array


def main():
    n = int(sys.stdin.readline().rstrip())

    sorted_letters = []
    count = 0
    for _ in range(n):
        s = ''.join(sorted(sys.stdin.readline().rstrip()))
        count += bi_r(sorted_letters, s) - bi_l(sorted_letters, s)
        in_l(sorted_letters, s)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(n-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())))
	

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(str(input()))

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

for i in range(n):
  sort = sorted(input())
  t = ''.join(sort)
  if t in words:
    ans += words.count(t)
    
  words.append(t)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[sorted(input()) for _ in range(n)]
s.sort()
count = 0
for i in range(n):
    for j in range(i+1,n):
        if s[i] == s[j]:
            count = count + 1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
from collections import Counter
def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

n=int(input())
a=[get_counter(input().rstrip('\r\n')) for i in range(n)]

def r(n):
    cnt=0
    for i in range(n):
        cnt+=i+1
    return cnt

fin=0
res=0
while len(a)>=fin:
    b=[]
    cnt=0
    i=1
    for _ in range(1,len(a)):
        if a[0]==a[i]:
            cnt+=1
            a.pop(i)
        else:
            i+=1
    a.pop(0)
    fin+=1
    res+=r(cnt)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
from collections import Counter
def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

n=int(input())
a=[get_counter(input().rstrip('\r\n')) for i in range(n)]

def r(n):
    cnt=0
    for i in range(n):
        cnt+=i+1
    return cnt

fin=0
res=0
while len(a)!=fin:
    b=[]
    cnt=0
    i=1
    for _ in range(1,len(a)):
        if a[0]==a[i]:
            cnt+=1
            a.pop(i)
        else:
            i+=1
    if len(a)!=0:
        a.pop(0)
        fin+=1
        res+=r(cnt)
    else:
        break
print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [str(input()) for i in range(n)]
ss = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        b = 0
        for k in range(9,-1,-1):
            if ss[i][k] != ss[j][k]:
                b = 1
                break
        if b == 0:    
            ans += 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
from collections import Counter
def get_counter(s):
    return Counter(s.upper().replace(' ', ''))

n=int(input())
a=[get_counter(input().rstrip('\r\n')) for i in range(n)]
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())
s = [str(input()) for i in range(n)]
ss = [sorted(i) for i in s]
ans = 0 
for i in range(n):
    for j in range(i+1,n):
        b = 0
        for k in range(10):
            if ss[i][k] != ss[j][k]:
                b = 1
                break
        if b == 0:
            ans += 1
                
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

N = int(input())

word_dict = []
num = []

for i in range(N):
    s = input()
    count = collections.Counter(s)
    if count in word_dict:
        num[word_dict.index(count)] += 1
    else:
        word_dict.append(count)
        num.append(0)

ans = 0

for i in num:
    i += 1
    if i >= 3:
        ans = ans + (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
    elif i == 2:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

N = int(input())

word_dict = []
num = []

for i in range(N):
    s = [i for i in input()]
    count = collections.Counter(s)
    if count in word_dict:
        num[word_dict.index(count)] += 1
    else:
        word_dict.append(count)
        num.append(0)

ans = 0

for i in num:
    i += 1
    if i >= 3:
        ans = ans + (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
    elif i == 2:
        ans += 1
    else:
        continue

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math

N = int(input())

word_dict = []
num = [0 for _ in range(10**5)]

for i in range(N):
    s = [i for i in input()]
    count = collections.Counter(s)
    if count in word_dict:
        num[word_dict.index(count)] += 1
    else:
        word_dict.append(count)

ans = 0

for i in num:
    i += 1
    if i >= 3:
        ans = ans + (math.factorial(i) // (math.factorial(i - 2) * math.factorial(2)))
    elif i == 2:
        ans += 1
    else:
        continue

print(ans)

Submission status: Time Limit Exceeded

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

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

sorted_ss = [''.join(sorted(s)) for s in ss]
sorted_set = set(sorted_ss)

cnt = 0
for s in sorted_set:
	c = sorted_ss.count(s)
	cnt += c * (c - 1) // 2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = [input() for _ in range(n)]
sorted_ss = [''.join(sorted(s)) for s in ss]
sorted_set = set([s for s in sorted_ss])

cnt = 0
for s in sorted_set:
	c = sorted_ss.count(s)
	cnt += c * (c - 1) // 2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, sr):
    """Test Case
    >>> print_ans(3, ["acornistnt", "peanutbomb", "constraint"])
    1
    >>> print_ans(2, ["oneplustwo", "ninemodsix"])
    0
    >>> print_ans(5,["abaaaaaaaa","oneplustwo","aaaaaaaaba","twoplusone","aaaabaaaaa"]) 
    4
    """
    for i in range(N):
        sr[i] = "".join(sorted(sr[i]))
    count = 0
    for i in range(N):
        tmp = sr[i]
        for k in range(i + 1, N):
            if tmp == sr[k]:
                count +=1
    print(count)


if __name__ == '__main__':
    N = int(input().rstrip())
    sr = [ input().rstrip() for _ in range(N)]
    print_ans(N, sr)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def print_ans(N, sr):
    """Test Case
    >>> print_ans(3, ["acornistnt", "peanutbomb", "constraint"])
    1
    >>> print_ans(2, ["oneplustwo", "ninemodsix"])
    0
    >>> print_ans(5,["abaaaaaaaa","oneplustwo","aaaaaaaaba","twoplusone","aaaabaaaaa"]) 
    4
    """
    check_ar = []
    for s in sr:
        check_ar.append("".join(sorted(s)))
    count = 0
    for i in range(N):
        tmp = check_ar[i]
        for k in range(i + 1, N):
            if tmp == check_ar[k]:
                count +=1
    print(count)


if __name__ == '__main__':
    N = int(input().rstrip())
    sr = [ input().rstrip() for _ in range(N)]
    print_ans(N, sr)

Submission status: Time Limit Exceeded

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

#出現するアルファベットをカウントしていく
al_list=[chr(ord('a') + i) for i in range(26)]

num_list = []
for _s in s_list:
    num = ''
    for _al in al_list:
        num += str(_s.count(_al))
    num_list.append(num)

count_list = []
for _num in num_list:
    count = num_list.count(_num)
    if count != 1: #1はカウントしても無駄
        count_list.append(count)

ans = 0
for i in range(1,n+1):
    ans += count_list.count(i) * (i - 1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

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

#出現するアルファベットをカウントしていく
al_list=[chr(ord('a') + i) for i in range(26)]

num_list = []
for _s in s_list:
    num = ''
    for _al in al_list:
        num += str(_s.count(_al))
    num_list.append(num)

count_list = []
for _num in num_list:
    count = num_list.count(_num)
    count_list.append(count)

ans = 0
for i in range(1,n+1):
    ans += count_list.count(i) * (i - 1) / 2

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

N = int(input())
#s = list(map(int, input().split()))
s = [str(input()) for i in range(N)]
len_str = len(s[0])
#print(s)
list_s = [['0'for i in range(len_str)]for j in range(N)]
for i in range(N):
  list_s[i] = list(s[i])
  list_s[i].sort()
  #print(list_s[i])

cnt=0
for i in range(N-1):
  for j in range(i+1,N):
    accuracy=0
    for k in range(len_str):
      if list_s[i][k]!=list_s[j][k]:
        break
      else:
        accuracy+=1
    if accuracy==len_str:
      cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

a=[]
b=[]
m=0
r=0
for i in range(n):
    a.append(sorted(l[i]))

for i in range(n-1):
    if i in b:
        continue

    for j in range(i+1,n):
        if a[i]==a[j]:
            b.append(j)
            m+=1
    r=r+m*(m+1)//2
    m=0
    
print(r)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
v=0
for i in range(n):
  d=input()
  y="".join(sorted(d))
  a.append(y)
for j in range(n-1):
  for k in range(j+1,n):
    if a[j]==a[k]:
      v+=1

print(v)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

N = int(input())
S = list(''.join(sorted(str(input()))) for _ in range(N))
unique_S = list(set(S))

ans = 0
for s in unique_S:
    n = S.count(s)
    if n > 1:
        ans += factorial(n) // (factorial(n - 2) * factorial(2))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
b=[]
ans=0
for i in range(n):
  s=list(input())
  s.sort()
  a.append(str(s))
b=set(a)
for x in b:
  c=a.count(x)
  if c>1:
    ans+=c*(c-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
from collections import deque

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

s1 = copy.deepcopy(s)
s2 = copy.deepcopy(s)
s1.pop()
del s2[0]
#listの先頭、後方を削除してからイテレートする必要がある
cnt = 0
for i in s1:
    for j in s2:
        if i == j:
            cnt+=1
    del s2[0]

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
for i in range(n):
    s.append(list(str(input())))
    
for i in s:
    i.sort()
    
cnt = 0
for i in range(n-1):
    for j in range(i+1, n):
        if s[i] == s[j]:
            cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
ans = 0
for i in range(N):
    a = input()
    s = [ ]
    for j in range(10):
        s.append(a[j])
    s.sort()
    ans += S.count(s)
    S.append(s)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
  s.append(''.join(sorted(input())))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [sorted(list(input())) for _ in range(N)]
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:
from math import factorial
N = int(input())
s = ["".join(sorted(list(input()))) for i in range(N)]
tmp = list(set(s))
for i in range(len(tmp)):
    s.remove(tmp[i])
tmp = list(set(s))
countlist = []
for i in range(len(tmp)):
    counter = 1
    for j in range(len(s)):
        if tmp[i] == s[j]:
            counter += 1
    countlist.append(counter)
ans = 0
if countlist == []:
    print(0)
else:
    for i in range(len(countlist)):
        if countlist[i] == 2:
            ans += 1
        else:
            ans += factorial(countlist[i])//(factorial(countlist[i]-2)*2)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [sorted(list(input())) for i in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if s[i] == s[j]:
            count += 1
print(int((count-N)/2))

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())
s = [collections.Counter(input()) for _ in range(n)]
ans = 0

for i, e1 in enumerate(s):
    for e2 in s[i+1:]:
        if e1 == e2:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i, e1 in enumerate(s):
    for e2 in s[i+1:]:
        if collections.Counter(e1) == collections.Counter(e2):
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input());S=[''.join(sorted(list(input()))) for i in range(N)];print(sum([S[i+1:].count(name) for i,name in enumerate(S)]))

Submission status: Time Limit Exceeded

Solution code:
a=0
d=["".join(sorted(input()))for i in range(int(input()))]
for i in list(set(d)):
  n=d.count(i)
  a+=(n-1)*n
print(int(a/2))

Submission status: Time Limit Exceeded

Solution code:
d,a=[],0
for i in range(0,int(input())):
  d.append("".join(sorted(input().rstrip('\n'))))
for i in list(set(d)):
  n=d.count(i)
  a+=(n-1)*n
print(int(a/2))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#from collections import Counter
#from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
S = [sorted(input().rstrip()) for _ in range(N)]
#print(S)

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:
#from collections import Counter
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
S = [sorted(input().rstrip()) for _ in range(N)]
#print(S)

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
import sys
input = sys.stdin.readline

N = int(input())
S = [Counter(input().rstrip()) for _ in range(N)]

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations
#from sys.stdin import readline

N = int(input())
S = [input() for _ in range(N)]
ans = 0
for s1, s2 in combinations(S, 2):
  if Counter(s1) == Counter(s2):
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

N = int(input())
S = [Counter(input()) for _ in range(N)]
ans = 0
for s1, s2 in combinations(S, 2):
  if s1 == s2:
    ans +=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# C Green_Bin
n = int(input())
sl = []
ans = 0
for i in range(n):
    s = "".join(sorted(input()))
    for j in range(i):
        if (sl[j] == s):
            ans += 1
    sl.append(s)

print(ans)

Submission status: Time Limit Exceeded

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

sdict = []
for x in s:
    tmp = {}
    for y in x:
        if y in tmp:
            tmp[y] += 1
        else:
            tmp[y] =1
    sdict.append(tmp)
cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        if sdict[i] == sdict[j]:
            cnt += 1
print(cnt)