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

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

print(count)

Submission status: Time Limit Exceeded

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

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

for i in range(n):
    inp = sorted(input())
    s.append(inp)

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

print(count)

Submission status: Time Limit Exceeded

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

for i in range(n):
    inp = sorted(input())
    s.append(inp)

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [str(sorted(input())) for i in range(N)]
count = [0]*N
for i in range(N):
    count[i] = s.count(s[0])-1
    s = s[1:]
print(sum(count))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
s = sorted(s)
cnt = 0
for i in range(len(s)):
    for j in s[i + 1:]:
        if s[i] == j:
            cnt += 1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = ["".join(sorted(input())) for i in range(n)]
cnt = 0
for i in range(len(s)):
    for j in s[i + 1:]:
        if s[i] == j:
            cnt += 1
        else:
            continue
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

list = []

count = 0

for i in range(N):
    moji = "".join(sorted(input()))
    if bool(list):
        count += list.count(moji)
        list.append(moji)
    else:
        list.append(moji)

print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
import math
import numpy as np

# = input()
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
#


dict_list = []
N = int(input())
for i in range(N):
  dict_list.append(collections.Counter(input()))

work = []
for i in dict_list:
  work.append(i)

  c = 0
  for i in range(len(dict_list)):
    if dict_list[i] in work[i+1:]:
      c += (dict_list[i:].count(dict_list[i])-1)

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

s = [sorted(s_) for s_ in s]
for i in range(N):
    for j in range(N):
        if(i<j):
            if(s[i]==s[j]):
                
                count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l=[list(sorted(input())) for x in range(n)]
q=0
ans=0
for i in range(n-1):
    q+=1
    for j in range(q,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.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())
ans=0
d=[]
for i in range(n):
  d.append(list(input()))
  d[i].sort()
  d[i]="".join(d[i])
x=set(d)
x=list(x)
for j in range(len(x)):
  X=d.count(x[j])
  ans+=(X*(X-1))/2
print(int(ans))

Submission status: Time Limit Exceeded

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

while True:
    if len(strings_list) == 0 or len(strings_list) == 1:
        break
    else:
        if strings_list[0] not in strings_list[1:]:
            strings_list.pop(0)
        else:
            n = strings_list[1:].count(strings_list[0])
            counter += n * (n + 1) /2
            strings_list = [i for i in strings_list if i != strings_list[0]]
print(round(counter))

Submission status: Time Limit Exceeded

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

while True:
    if len(strings_list) == 0 or len(strings_list) == 1:
        break
    else:
        if strings_list[0] not in strings_list[1:]:
            strings_list.pop(0)
        else:
            counter += strings_list[1:].count(strings_list[0])
            strings_list.pop(0)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import sys
def input() -> str:
    return sys.stdin.readline()
n = int(input())
s = [input() for _ in range(n)]
clist, cnt = [], []
for si in s:
    c = Counter(si)
    # print(c)
    if c in clist:
        cnt[clist.index(c)] += 1
    else:
        clist.append(c)
        cnt.append(1)
ans = 0
for ci in cnt:
    ans += sum(range(1, ci))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
clist, cnt = [], []
for si in s:
    c = Counter(si)
    # print(c)
    if c in clist:
        cnt[clist.index(c)] += 1
    else:
        clist.append(c)
        cnt.append(1)
ans = 0
for ci in cnt:
    ans += sum(range(1, ci))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = []
cnt = 0
for _ in range(int(input())):
    a = sorted(input())
    cnt += x.count(a)
    x.append(a)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
x = []
cnt = 0
for _ in range(int(input())):
    a = sorted(input())
    if a in x:
        cnt += x.count(a)
    x.append(a)
print(cnt)

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-1):
    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=[[j for j in input()] for i in range(n)]
for i in s:
  i.sort()
ans=0
for i in range(n-1):
  for j in range(i+1,n):
    if s[i]==s[j]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
q=[]  
for i in range(N):
    q+=[list(input())]
    q[i].sort()
    q.sort()
m=0
s=0
z=0 #総得点
while m<N-1:
    if q[m]!=q[m+1]:
        z+=((s*(s+1))//2)
        s=0
    else:
        s+=1
    m+=1
z+=((s*(s+1))//2)
print(z)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
q=[]
for i in range(N):
    q+=[list(input())]
    q[i].sort()
s=0
for j in range(N-1):
    for k in range(j+1,N):
        if q[j]==q[k]:
            s+=1
print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if not array:
            break
        alphabet = array[:][0]
        num = array.count(alphabet)-1
        if num <= 0:
            pass
        elif num <= 1:
            ans += 1
        else:
            ans += int((num+1)*num/2)
        for j in range(num+1):
            array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter

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

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if not array:
            break
        alphabet = array[:][0]
        num = array.count(alphabet)-1
        if num <= 0:
            pass
        elif num <= 1:
            ans += 1
        else:
            ans += combinations_count(num+1, 2)
        for j in range(num+1):
            array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter

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

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if array:
            alphabet = array[:][0]
            num = array.count(alphabet)-1
            if num <= 0:
                pass
            elif num <= 1:
                ans += 1
            else:
                ans += combinations_count(num+1, 2)
            for j in range(num+1):
                array.remove(alphabet)
        else:
            break
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter

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

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(n):
        if array:
            alphabet = array[:][0]
            num = array.count(alphabet)-1
            if num <= 0:
                pass
            elif num <= 1:
                ans += 1
            else:
                ans += combinations_count(num+1, 2)
            for j in range(num+1):
                array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math
from collections import Counter

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

def main():
    n = int(input())
    array_s = []
    array = []
    for i in range(n):
        array_s.append(input())

    for s in array_s:
        array.append(Counter(s))

    ans = 0
    for i in range(len(array)):
        if array:
            alphabet = array[:][0]
            num = array.count(alphabet)-1
            if num <= 0:
                pass
            elif num <= 1:
                ans += 1
            else:
                ans += combinations_count(num+1, 2)
            for j in range(num+1):
                array.remove(alphabet)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, s: "List[str]"):
    answer = 0
    ss = [collections.Counter(s[i]) for i in range(N)]

    for i in range(N):
        a = 1
        pop_index = []
        for j in range(i+1,len(ss)):
            if ss[i] == ss[j]:
                a += 1
                pop_index.append(j)
        
        ss = [ss[i] for i in range(len(ss)) if i not in pop_index]
        answer += int(a*(a-1)/2) if a > 1 else 0
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, s: "List[str]"):
    answer = 0
    ss = [collections.Counter(s[i]) for i in range(N)]
    for i in range(N):
        for j in range(i+1,N):
            if ss[i] == ss[j]:
                answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import collections

def solve(N: int, s: "List[str]"):
    answer = 0
    for i in range(N):
        for j in range(i+1,N):
            # print(collections.Counter(s[i]))
            if collections.Counter(s[i]) == collections.Counter(s[j]):
                answer += 1
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect


N = int(input())
s = []
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    if t:
        del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    del s[:t]
    ans += (t * (t + 1)) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect


N = int(input())
s = []
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    si.sort()
    s += [('').join(si)]
s.sort()
ans = 0
while (s):
    t = bisect.bisect_right(s, s.pop(0))
    ans += t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ans = 0
memo = [{} for _ in range(N)]
for i in range(N):
    si = list(input())
    for ss in si:
        if ss not in memo[i]:
            memo[i][ss] = 1
        else:
            memo[i][ss] += 1
for j in range(N):
    for k in range(j, N):
        if j != k:
            if memo[j] == memo[k]:
                ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
B = []
cnt = 0
for i in range(N):
  s = list(input())
  s.sort()
  k = 0
  while k < len(B):
    if B[k][0] == s:
      cnt += B[k][1]
      B[k][1] += 1
      break
    else:
      k += 1
  else:
    B.append([s,1])
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
count=0
for i in range(N):
  x=s.count(s[i])
  count+=(x-1)/2
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d=[[] for i in range(n)]
s=[]
count=0
for i in range(n):
  s=input()
  for j in range(10):
    d[i].append(s[j])
  d[i].sort()
for i in range(n):
  for j in range(n):
    if i!=j and d[i]==d[j]:
      count+=1
print(int(count/2))

Submission status: Time Limit Exceeded

Solution code:
def main():
	N = int(input())
	s = []
	for _ in range(N):
		s.append("".join(sorted([a for a in input()])))
	pair = 0
	for i in range(N-1):
		for j in range(i+1, N):
			if s[i] == s[j]:
				pair += 1
	print(pair)
main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
for _ in range(N):
	s.append(sorted([a for a in input()]))
pair = 0
for i in range(N-1):
	for j in range(i+1, N):
		if s[i] == s[j]:
			pair += 1
print(pair)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial
n = int(input())
list1 = [list(list(input())) for i in range(n)]
list2 = []
cout = 0

def combinations_count(n,r):
    """組み合わせnCr"""
    return factorial(n) // (factorial(n-r)*factorial(r))

for i in range(n):
    list1[i].sort()
    if list1[i] in list2:
        list2[list2.index(list1[i])+1].append(1)
    else:
        list2.append(list(list1[i]))
        list2.append([1])

for i in range(1,len(list2),2):
    if len(list2[i]) != 1:
        cout += combinations_count(sum(list2[i]),2)
print(cout)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def t(s):
    a = [''.join(sorted(list(i))) for i in s]
    b = set(a)
    r = 0
    for i in b:
        n = a.count(i)
        r += n * (n - 1) / 2
    return int(r)


if __name__ == '__main__':
    n = int(input())
    print(t([input() for i in range(n)]))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
d = []
count = 0
t = [0] * n
for _ in range(n):
    s = input()
    dic = defaultdict(int)
    for c in s:
        dic[c] += 1
    for i in range(len(d)):
        if all(dic[key] == d[i][key] for key in dic):
            if t[i] != 0:
                count += t[i] + 1
                t[i] += 1
                break
            else:
                count += 1
                t[i] += 1
    d.append(dic)


print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict

n = int(input())
d = []
count = 0
for _ in range(n):
    s = input()
    dic = defaultdict(int)
    for c in s:
        dic[c] += 1
    for i in range(len(d)):
        if all(dic[key] == d[i][key] for key in dic):
            count += 1
    d.append(dic)


print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = []
m = 0

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)
    
t.sort()

for i in range(n):
    for j in range(n - i - 1):
        if t[i] == t[i + j + 1]:
            m += 1
        else:
            break
        
print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
t = []
m = 0

for i in range(n):
    s = list(input())
    s.sort()
    t.append(s)
    
for i in range(n):
    for j in range(n - i - 1):
        if t[i] == t[j + i + 1]:
            m += 1
        
print(m)

Submission status: Time Limit Exceeded

Solution code:
#input
N = int(input())
S = [''.join(sorted(input())) for i in range(N)]

ana = 0
for i in range(N):
    ana += S.count(S[i])

print(int((ana - N) / 2))

Submission status: Time Limit Exceeded

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

ana = 0
for i in range(N):
    ana += S.count(S[i])

print(int((ana - N) / 2))

Submission status: Time Limit Exceeded

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

ana = 0
for s in S:
    ana += S.count(s)

print(int((ana - N) / 2))

Submission status: Time Limit Exceeded

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

ana = 0
for s1 in S:
    for s2 in S:
        if s1 == s2:
            ana += 1

print(int((ana - N) / 2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

L = [list(input()) for _ in range(N)]

dic = []
flag = {}
res = 0
for i in range(N):
    L[i].sort()

    if L[i] in dic:
        flag[str(L[i])] += 1
        res += flag[str(L[i])]
    else:
        dic.append(L[i])
        flag[str(L[i])] = 0

print(res)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
words_oc = set(words)
res = 0
for i in words_oc:
    c = 0
    for j in words:
        if i == j:
            c += 1
    res += (c**2 - c)//2
print(res)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = ["".join(sorted(input())) for i in range(num)]
c = 0
for i in range(len(words)-1):
    for j in range(i+1, len(words)):
        if words[i] == words[j]:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
count = 0
N = int(input())
str_lst = [None for _ in range(N)]
for i in range(N):
    str_lst[i] = list(input())
    str_lst[i].sort()
for i in range(N-1):
    for j in range(i+1, N):
        if str_lst[i] == str_lst[j]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

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

print(count)

Submission status: Time Limit Exceeded

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

count = 0
for i in range(N):
    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 _ in range(N)]
for i in range(N):
    S[i] = sorted(S[i])

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

print(count // 2)

Submission status: Time Limit Exceeded

Solution code:
N =int(input())
strings =[]
for i in range(N):
  strings.append(input())
strs=[]
for i in range(N):
  str1 =strings[i][0:1]
  str2 =strings[i][1:2]
  str3 =strings[i][2:3]
  str4 =strings[i][3:4]
  str5 =strings[i][4:5]
  str6 =strings[i][5:6]
  str7 =strings[i][6:7]
  str8 =strings[i][7:8]
  str9 =strings[i][8:9]
  str10 =strings[i][9:10]
  letters=[str1,str2,str3,str4,str5,str6,str7,str8,str9,str10]
  newstrlet =sorted(letters)
  newstr=newstrlet[0]+newstrlet[1]+newstrlet[2]+newstrlet[3]+newstrlet[4]+newstrlet[5]+newstrlet[6]+newstrlet[7]+newstrlet[8]+newstrlet[9]
  strs.append(newstr)
k=0
for i in range(N):
  for j in range(N):
    if strs[i]==strs[j]:
      k=k+1
ans=(k-N)/2
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

l = []
cnt = 0
t = 0
tmp = '0000000000'

for i in range(n):
    s = str(input())
    sl = ''.join(sorted(s))
    l.append(sl)
    l.sort()

for i in range(n):
  if tmp == l[i]:
    cnt += 1
  else:
    tmp = l[i]
    if cnt > 0:
      t += int(cnt * (cnt + 1) / 2)
    cnt = 0
else:
  if cnt > 0:
    t += int(cnt * (cnt + 1) / 2)
    
print(t)

Submission status: Time Limit Exceeded

Solution code:
import collections

n = int(input())

li = []
r = []
rs = []
cnt = 0

for i in range(n):
    s = str(input())
    sl = list(s)
    li.append(sl)
    r.append([])
    rs.append("")
    coll = collections.Counter(li[i])
    r[i].extend(coll.most_common())
    r[i].sort()
    rs[i] = ''.join(str(s) for s in r[i])

collr = collections.Counter(rs)

for i in collr.values():
    cnt += i * (i-1) / 2

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
import string
import collections

n = int(input())

li = []
ls = []
cnt = 0
res = [[list(i) for i in string.ascii_lowercase] for _ in range(n)]
# print(res)
r = [[] for _ in range(n)]
rs = ["" for _ in range(n)]

for i in range(n):
    s = str(input())
    sl = list(s)
    #  print(s)
    #  print(sl)
    li.append(sl)
    # for j in range(26):
    #     res[i][j].append(0)

# print(res)

for i in range(n):
    coll = collections.Counter(li[i])
    r[i].extend(coll.most_common())
    r[i].sort()
    rs[i] = ''.join(str(s) for s in r[i])

collr = collections.Counter(rs)

# print(collr)
# print(collr.values())
# print(sum(collr.values()))

for i in collr.values():
    cnt += i * (i-1) / 2

print(int(cnt))
        # print(res[i])
#     if not res[i] in dic:
#         dicdic[res[i]] = 0
#     else:
#         pass

# for m in range(n):
#   for l in range(n):
#     if l <= m:
#       continue
#     else:
#       if res[m] == res[l]:
#         cnt += 1

# print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import string

n = int(input())

li = []
ls = []
cnt = 0
res = [[list(i) for i in string.ascii_lowercase] for _ in range(n)]
# print(res)

for i in range(n):
  s = str(input())
  sl = list(s)
#  print(s)
#  print(sl)
  li.append(sl)
  for j in range(26):
    res[i][j].append(0)

#print(res)

for i in range(n):
  for j in li[i]:
    for k in range(26):
      if res[i][k][0] == j:
        res[i][k][1] += 1
        break
        #print(res[i])

for m in range(n):
  for l in range(n):
    if l <= m:
      continue
    else:
      if res[m] == res[l]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import string

n = int(input())

li = []
ls = []
cnt = 0
res = [[list(i) for i in string.ascii_lowercase] for _ in range(n)]
# print(res)

for _ in range(n):
  s = str(input())
  sl = list(s)
#  print(s)
#  print(sl)
  li.append(sl)

for i in range(n):
  for j in range(26):
    res[i][j].append(0)

#print(res)

for i in range(n):
  for j in li[i]:
    for k in range(26):
      if res[i][k][0] == j:
        res[i][k][1] += 1
        #print(res[i])

for m in range(n):
  for l in range(n):
    if l <= m:
      continue
    else:
      if res[m] == res[l]:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

result = []
for i in si:
    result.append(si.count(i)-1)

print(int(sum(result)/2))

Submission status: Time Limit Exceeded

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

result = []
for j in range(len(si)):
    a = si.count(si[j])
    result.append(a-1)

print(int(sum(result)/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strlist = []
strnum = []

for _ in range(n):
  s = input()
  ls = list(s)
  ls.sort()
  if ls in strlist:
    strnum[strlist.index(ls)] += 1
    
  else:
    strlist.append(ls)
    strnum.append(1)

ans = 0    
for n in strnum:
  if n > 1:
    ans += n*(n-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

si2 = []
for i in range(len(si)):
    s = []
    for k in list(set(si[i])):
        a = si[i].count(k)
        s.append([k,a])
    si2.append(s)
 
si3 = [] 
for i in range(len(si2)):
    si3.append(sorted(si2[i], key = lambda val : val[0]))

result = []
for i in range(len(si3)):
    result.append(si3.count(si3[i])-1)

print(int(sum(result)/2))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strlist = []
strnum = []

for _ in range(n):
  s = input()
  asc = [0 for _ in range(26)]
  for chr in s:
    asc[ord(chr)-ord("a")] += 1
    
  if asc in strlist:
    strnum[strlist.index(asc)] += 1

  else:
    strlist.append(asc)
    strnum.append(1)

ans = 0    
for n in strnum:
  if n > 1:
    ans += n*(n-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
# si と sj のアナグラムは Counter(si)==Counter(sj) で求められる
# 組の数を数える
N=int(input())
S=[Counter(input()) for n in range(N)]
c=0
l=[]
for s in S:
    if s in l:
        continue
    else:
        l.append(s)
        n=S.count(s)
        c+=(n*(n-1))//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
# si と sj のアナグラムは Counter(si)==Counter(sj) で求められる
# 組の数を数える
N=int(input())
S=[Counter(input()) for n in range(N)]
c=0
l=[]
for s in S:
    if s in l:
        continue
    else:
        l.append(s)
        c+=(S.count(s)*(S.count(s)-1))//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
S=[Counter(input()) for n in range(N)]
c=0
l=[]
for s in S:
    if s in l:
        continue
    else:
        l.append(s)
    c+=(S.count(s)*(S.count(s)-1))//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
S=[Counter(input()) for n in range(N)]
c=0
for s in S:
    c+=(S.count(s)*(S.count(s)-1))//2
    S=[i for i in S if i!=s]
    if len(S)==0:
        break
print(c)

Submission status: Time Limit Exceeded

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

to = 0
for i in range(N):
	str = input()
	s.append(sorted(str))
	cnt = s.count(s[i])
	if cnt > 1:
		to += cnt-1

print(to)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strings = []
answer = 0
for i in range(n):
  strn = input()
  strn = ''.join(sorted(strn))
  answer += strings.count(strn)
  strings.append(strn)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strings = []
answer = 0
for i in range(n):
  string = input()
  string = ''.join(sorted(string))
  answer += strings.count(string)
  strings.append(string)
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strings = []
num = []
answer = 0
for i in range(n):
  string = input()
  string = ''.join(sorted(string))
  if string not in strings:
    strings.append(string)
    num.append(0)
  else:
    hoge = num[strings.index(string)] = num[strings.index(string)] + 1
    answer = answer + hoge
print(answer)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
strings = []
num = []
answer = 0
for i in range(n):
  string = input()
  string = ''.join(sorted(string))
  if string not in strings:
    strings.append(string)
    num.append(0)
  else:
    num[strings.index(string)] += 1
    answer = answer + num[strings.index(string)]
print(answer)