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())
l = [list(input()) for i in range(n)]
l = ["".join(sorted(i)) for i in l]
l = [i for i in l if i != 1]
l.sort()
s = 0
for i in range(len(l)-1):
  for j in range(i+1,len(l)):
    if l[i] == l[j]:
      s += 1
print(s)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
str = [input() for i in range(N)] 

str1 = []
for i in range (0,N):
  new_str_list = sorted(str[i])
  b = ''.join(new_str_list)
  str1.append(b)

k = 0

for i in range (0,N):
  k = k + str1.count(str1[i])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
str = [input() for i in range(N)] 

str1 = []
for i in range (0,N):
  new_str_list = sorted(str[i])
  b = ''.join(new_str_list)
  str1.append(b)

k = 0

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
for i in range(N):
    tmp = list(input())
    tmp = sorted(tmp)
    s.append(tmp)
s.sort()
for i in range(N - 1):
    for j in range(N - i - 1):
        if s[i] == s[i + j + 1]:
            ans += 1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
n = int(input())
array = []
 
# 並べ替え
for i in range(n):
  array.append(''.join(sorted(input())))
 
count = 0
for x in range(len(array)):
  for y in range(len(array)):
    if x != y:
      count += 1 if array[x] == array[y] else 0
 
print(round(count / 2))

Submission status: Time Limit Exceeded

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

# 並べ替え
for i in range(n):
  array.append(''.join(sorted(input())))

count = 0
for x in range(len(array)):
  for y in range(len(array)):
    if x != y:
      count += 1 if array[x] == array[y] else 0

print(round(count / 2))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
str = [input() for i in range(N)] 
k = 0

for i in range (0,N):
  a = Counter(str[i])
  for j in range (i+1,N):
    if a == Counter(str[j]) :
      k = k + 1
print(k)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
str = [input() for i in range(N)] 
k = 0

for i in range (0,N):
  for j in range (i+1,N):
    if Counter(str[i]) == Counter(str[j]) :
      k = k + 1
print(k)

Submission status: Time Limit Exceeded

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

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
#import scipy
#import sys
#from collections import defaultdict
from collections import Counter
#from itertools import accumulate
from itertools import product, permutations,combinations
#from operator import itemgetter
#from bisect import bisect_left,bisect
#from heapq import heappop,heappush
#from fractions import gcd
#from math import ceil,floor,sqrt,cos,sin,pi
#from copy import deepcopy
#import numpy as np

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

count = []
for i in range(N):
	count.append(Counter(S[i]))

conb = list(combinations(count, 2))

ans = 0
for i in range(len(conb)):
	if conb[i][0] == conb[i][1]:
		ans += 1

#print(conb)

'''
ans = 0
for i in range(N):
	for j in range(i, N):
		if (count[i] == count[j]) and (i != j):
			ans += 1
'''

#print(count)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import scipy
#import sys
#from collections import defaultdict
from collections import Counter
#from itertools import accumulate
from itertools import product, permutations,combinations
#from operator import itemgetter
#from bisect import bisect_left,bisect
#from heapq import heappop,heappush
#from fractions import gcd
#from math import ceil,floor,sqrt,cos,sin,pi
#from copy import deepcopy
#import numpy as np


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

count = []
for i in range(N):
	count.append(Counter(S[i]))

ans = 0
for i in range(N):
	for j in range(i, N):
		if (count[i] == count[j]) and (i != j):
			ans += 1


#print(count)
print(ans)

#print(S)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a=[]
cnt=0
for i in range(N):
  a.append(input())
for j in range(N):
  a[j]=list(sorted(a[j]))
for k in range(N):
  cnt += (a.count(a[k])-1)
  
print(int(cnt/2))

Submission status: Time Limit Exceeded

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

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

s_dash.sort()
for i in range(n):
	for j in range(i+1,n):
		if s_dash[i] == s_dash[j]:
			ans += 1
		else:
			break

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

s_dash.sort()
for i in range(n):
	for j in range(i+1,n):
		if s_dash[i][0] != s_dash[j][0]:
			break
		elif s_dash[i] == s_dash[j]:
			ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)
	s_dash.sort()

for i in range(n):
	for j in range(i+1,n):
		if s_dash[i][0] != s_dash[j][0]:
			break
		elif s_dash[i] == s_dash[j]:
			ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(n):
	s.append(input())
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

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

print(ans)

Submission status: Time Limit Exceeded

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

for _ in range(n):
	s.append(input())

for i in range(n):
	c.clear()
	for j in s[i]:
		c.append(j)

	c.sort()
	c_str = ''
	for j in range(10):
		c_str += c[j]

	s_dash.append(c_str)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
while True:
    try:
        n = int(input())
        S = []
        for i in range(n):
            S.append(input())
            
        dic = {}
        for c in "abcdefghijklmnopqrstuvwxyz":
            dic[c] = [0 for i in range(n)]
            
        for i in range(n):
            for c in S[i]:
                dic[c][i] += 1
        
        ans = 0
        for i in range(n-1):
            for j in range(i+1, n):
                for k, v in dic.items():
                    if v[i] != v[j]:
                        break
                else:
                    ans += 1
        print(ans)
    except:
        break

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
d={}
for i in range(n):
  a=str(sorted(input()))
  if a in list(d.keys()):
    d[a]+=1
  else:
    d[a]=1
l=list(d.values())
c=0
for i in l:
  c+=(i*(i-1))//2
print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list()
for i in range(n):
    s.append(list(input()))
c = 0
for i in range(len(s)):
    s[i].sort()
    if i == 0:
        continue

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

print(c)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
sary = [sorted(stdin.readline().rstrip()) for _ in range(n)]

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
n = int(stdin.readline().rstrip())
sary = [stdin.readline().rstrip() for _ in range(n)]

res = 0
for i in range(n):
    for j in range(i+1, n):
        if str(sorted(sary[i])) == str(sorted(sary[j])):
            res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = []
for i in range(n):
    s_list.append(sorted(input()))
count = 0
for j in range(len(s_list)):
    for k in range(j+1,len(s_list)):
        if s_list[j] == s_list[k]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = ["".join(sorted(input())) for i in range(n)]
count = 0
for j in range(len(s_list)):
    for k in range(j+1,len(s_list)):
        if s_list[j] == s_list[k]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s_list = [input() for i in range(n)]
count = 0
for j in range(len(s_list)):
    for k in range(j+1,len(s_list)):
        if set(list(s_list[j])) != set(list(s_list[k])):
            continue
        if sorted(s_list[j]) == sorted(s_list[k]):
            count += 1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main(): 
    n = int(input())
    s = sorted([sorted(input()) for _ in range(n)])
    
    cnt = 0
    for i in range(n):
        for j in range(i+1,n):
            if s[i] == s[j]:
                cnt += 1
            else:
                break

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1:
            l.append([strg])
            l[-1].append(1)
        else: l[x][1] += 1
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        t = e_l[1]
        ans += t * (t - 1) / 2
    return int(ans)

print(calcAns(makeSortList(int(input()))))

Submission status: Time Limit Exceeded

Solution code:
def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1:
            l.append([strg])
            l[-1].append(1)
        else: l[x][1] += 1
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        t = e_l[1]
        if 1 < t: ans += t * (t - 1) / 2
    return int(ans)

print(calcAns(makeSortList(int(input()))))

Submission status: Time Limit Exceeded

Solution code:
def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1:
            l.append([strg])
            l[x].append(1)
        else: l[x][1] += 1
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        t = e_l[1]
        if 1 < t: ans += t * (t - 1) / 2
    return int(ans)

print(calcAns(makeSortList(int(input()))))

Submission status: Time Limit Exceeded

Solution code:
def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1:
            l.append([strg])
            l[x].append(1)
        #l[x].append(i)
        else: l[x][1] += 1
    return l

def calcAns(l):
    ans = 0
    """
    for e_l in l:
        lngth = len(e_l) - 1
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    """
    #print(l)
    for e_l in l:
        if 1 < e_l[1]: ans += e_l[1] * (e_l[1] - 1) / 2
    return int(ans)

print(calcAns(makeSortList(int(input()))))

"""
5
abaaaaaaaa
oneplustwo
aaaaaaaaba
twoplusone
aaaabaaaaa

4
"""

Submission status: Time Limit Exceeded

Solution code:
def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

print(calcAns(makeSortList(int(input()))))

Submission status: Time Limit Exceeded

Solution code:
def main():
    print(calcAns(makeSortList(int(input()))))

def searchList(l, s):
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l = makeSortList(n)
    print(calcAns(l))

def searchList(l, s):
    """
    for i in range(len(l)):
        if l[i][0] == s:
            return i
    else: return -1
    """
    try: return [e[0] for e in l].index(s)
    except: return -1

def makeSortList(n):
    l = []
    for i in range(n):
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        #ans += lngth * (lngth - 1) / 2
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l = makeSortList(n)
    print(calcAns(l))

def searchList(l, s):
    length = len(l)
    for i in range(length):
        if l[i][0] == s:
            return i
    else: return -1

def makeSortList(n):
    l = []
    #sortString = lambda s: "".join(sorted(s))
    for i in range(n):
        #strg = sortString(input())
        strg = "".join(sorted(input()))
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        #ans += lngth * (lngth - 1) / 2
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l = makeSortList(n)
    print(calcAns(l))

def searchList(l, s):
    length = len(l)
    for i in range(length):
        if l[i][0] == s:
            return i
    else: return -1

def makeSortList(n):
    l = []
    sortString = lambda s: "".join(sorted(s))
    for i in range(n):
        strg = sortString(input())
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        #ans += lngth * (lngth - 1) / 2
        if lngth > 1:
            ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    l = makeSortList(n)
    print(calcAns(l))

def searchList(l, s):
    length = len(l)
    for i in range(length):
        if l[i][0] == s:
            return i
    else: return -1

def makeSortList(n):
    l = []
    sortString = lambda s: "".join(sorted(s))
    for i in range(n):
        strg = sortString(input())
        x = searchList(l, strg)
        if x == -1: l.append([strg])
        l[x].append(i)
    return l

def calcAns(l):
    ans = 0
    for e_l in l:
        lngth = len(e_l) - 1
        ans += lngth * (lngth - 1) / 2
    return int(ans)

main()

Submission status: Time Limit Exceeded

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

ans, u = 0, set()
for i in range(n-1):
    c = set()
    if i not in u:
        for j in range(i+1, n):
            if s[i] == s[j]:
                c.add(i)
                c.add(j)
                u.add(i)
                u.add(j)
        ans += (len(c) * (len(c) - 1)) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def judgeAngrm(s, t):
    for c_s in s:
        if t.count(c_s):
            t = t.replace(c_s, "", 1)
        else:
            return False
    else:
        return True

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

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [input() for i in range(n)]
    print(runAllCheck(n, s))

def judgeAngrm(s, t):
    for c_s in s:
        if t.count(c_s):
            t = t.replace(c_s, "", 1)
        else:
            return False
    else:
        return True

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

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    s = [input() for i in range(n)]
    print(runAllCheck(n, s))

def judgeAngrm(s, t):
    for c_s in s:
        if t.count(c_s):
            t = t.replace(c_s, "", 1)
            if t == "":
                return True
        else:
            return False

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

main()

Submission status: Time Limit Exceeded

Solution code:
A =[]
c = 0
for i in range(int(input())):
    a=sorted(input())
    c += A.count(a)
    A.append(a)
print(c)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans= 0
for i in range (N):
  li[i].sort()
  
for i in range(N-1):
  for j in range(i+1,N):
    if li[i] == li[j]:
      ans+=1
    else: continue
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf8 -*-

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [list(range(s.count(i))) for i in set(s) if s.count(i) != 1]
t = [sum(i) for i in c]
print(sum(t))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf8 -*-

n = int(input())
s = [input() for _ in range(n)]
s = [''.join(sorted(i)) for i in s]
c = [list(range(s.count(i))) for i in set(s)]
t = [sum(i) for i in c if i != 1]
print(sum(t))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = [input() for i in range(N)]
L = list(map("".join, list(map(sorted, list(map(list, L))))))
count = 0
for j in range(N):
    for k in range(j + 1, N):
        if L[j] == L[k]:
            count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

string_list = [''.join(sorted(input())) for i in range(n)]

counter = 0

for i in range(n):
  str_i = string_list[i]
  for j in range(i + 1, n):
    str_j = string_list[j]
    if str_i == str_j:
      counter += 1

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
c=[]
for i in range(n):
    t=input()
    l=len(s)
    t=sorted(t)
    tam=0
    for j in range(l):
        if(t==s[j]):
            c[j]+=1
            tam=1
            break
    if(tam==0):
        c.append(1)
        s.append(t)
#print(*s)
kq=0
for i in c:
    kq=kq+(i*(i-1))//2
print(kq)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
c=[]
for i in range(n):
    t=[(ord(i)-97) for i in input()]
    l=len(s)
    t.sort()
    tam=0
    for j in range(l):
        if(t==s[j]):
            c[j]+=1
            tam=1
            break
    if(tam==0):
        c.append(1)
        s.append(t)
#print(*s)
kq=0
for i in c:
    kq=kq+(i*(i-1))//2
print(kq)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
t=input()
a=[0]*27
for i in t:
    a[ord(i)-97]+=1
a[26]=1
s.append(a)
for i in range(n-1):
    t=input()
    a=[0]*27
    for j in t:
        a[ord(j)-97]+=1
    t=set(t)
    l=len(s)
    ok=0
    for j in range(l):
        tam=1
        for k in t:
            b=ord(k)-97
            if(a[b]!=s[j][b]):
                tam=0
                break
        if(tam==1):
            s[j][26]+=1
            ok=1
            break
    #print(ok)
    if ok==0:
        a[26]=1
        s.append(a)
kq=0
for i in range(len(s)):
    if s[i][26]==2:
        kq+=1
    elif(s[i][26]>2):
        t=(s[i][26]*(s[i][26]-1))//2
        kq+=t
print(int(kq))

Submission status: Time Limit Exceeded

Solution code:
def hantei(s1, s2):
    x = list(s1)
    y = list(s2)
    for i in range(10):
        h = 0
        a = x.pop(0)
        for j, b in enumerate(y):
            if a == b:
                y.pop(j)
                h = 1
                break
        if h == 0:
            return 0
    return 1              


n = int(input())
a = []
cnt = 0
for i in range(n):
    a.append(input())
for i in range(n-1):
    for j in range(i+1, n):
        if hantei(a[i], a[j]) == 1:
            cnt += 1


print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = []
cnt = 0
for i in range(n):
    tmp = "".join(sorted(input()))
    cnt += S.count(tmp)
    S.append(tmp)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = []
for i in range(n):
    tmp = "".join(sorted(input()))
    S.append(tmp)
#print(S)
cnt = 0
for s in S:
    #print(S.count(s))
    cnt += (S.count(s)-1)
    S = S[1:]
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = []
for i in range(n):
    tmp = "".join(sorted(input()))
    S.append(tmp)
#print(S)
cnt = 0
for s in S:
    #print(S.count(s))
    cnt += (S.count(s)-1)
print(cnt//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
S = []
for i in range(n):
    tmp = list(input())
    tmp.sort()
    S.append(tmp)
count = 0
for j in range(len(S)):
    for k in range(j+1,len(S)):
        if S[j] == S[k]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
sn=["".join(sorted(input())) for _ in range(n)]
l=len(sn)
ans=0
for i in range(l-1):
    ans+=sn[i+1:].count(sn[i])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#137C
N = int(input())
S = []
ans = 0
sortWord =""
for i in range(1,N+1):
    sortWord = "".join(sorted(input()))
    if sortWord in S:
        ans += S.count(sortWord)
    S.append(sortWord)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#137C
N = int(input())
S = []
ans = 0
sortWord =""
for i in range(1,N+1):
    sortWord = "".join(sorted(input()))
    if S.count(sortWord) >= 1:
        ans += S.count(sortWord)
    S.append(sortWord)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import collections
import sys

input=sys.stdin.readline

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

for i in range(N):
    clist.append(collections.Counter(list(input().replace("\n",""))))#ここは普通に入れてfor文でcounterする

count=0

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

Submission status: Time Limit Exceeded

Solution code:
#137C
N = int(input())
S = []
ans = 0
for i in range(1,N+1):
    S.append("".join(sorted(input())))

#for j in range(0,N):
  #  S[j] = "".join(sorted(S[j]))
    
for k in range(0,N-1):
    for l in range(k+1,N):
        if S[k] == S[l]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#137C
N = int(input())
S = []
ans = 0
for i in range(1,N+1):
    S.append(input())

for j in range(0,N):
    S[j] = "".join(sorted(S[j]))
    
for k in range(0,N-1):
    for l in range(k+1,N):
        if S[k] == S[l]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
s = [0]*n
count = 0

for i in range(n):
    tmp = list(str(input()))
    tmp.sort()
    s[i] = "".join(tmp)

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())
strings = []
for _ in range(N):
    strings.append(sorted(list(input().rstrip('\n'))))

count = 0
for i in range(len(strings)):
    for j in range(i + 1, len(strings)):
        if strings[i] == strings[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans=0
hoge=[]
for i in range(n):
  a=list(input())
  a.sort()
  if(hoge.count(a)==0):
    hoge.append(a)
  else:
    ans+=hoge.count(a)
    hoge.append(a)
print(ans)

Submission status: Time Limit Exceeded

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

ss = []
cnt = 0
for i in range(N):
    x = "".join(sorted(list(s[i])))
    if x in ss:
        cnt += ss.count(x)
    ss.append(x)

print(cnt)

Submission status: Time Limit Exceeded

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

ss = []
cnt = 0
for i in range(N):
    x = list(s[i])
    x.sort()
    y = "".join(x)
    cnt += ss.count(y)
    ss.append(y)

print(cnt)

Submission status: Time Limit Exceeded

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

ss = []
for i in range(N):
    x = list(s[i])
    x.sort()
    y = "".join(x)
    ss.append(y)

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

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N):
    s[i] = ''.join(sorted(s[i])) # 文字列をソートすると配列になる

ans = 0
for i in range(N): # iは0からN-1まで
    ans += (s.count(s[i]) - 1)/2

print(int(ans))

Submission status: Time Limit Exceeded

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

for i in range(N):
    s[i] = sorted(s[i]) # 2次元配列になる

ans = 0
for i in range(N-1): # iは0からN-2まで
    for j in range(i+1, N): # jはi+1からN-1まで
        if s[i] == s[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
l = 0
for i in range(0,N):
    s.append(str(input()))
for i in range(0,N):
    s[i] = ''.join(sorted(s[i]))
s.sort()
for i in range(0,N-1):
    for n in range(i+1,N):
        if s[i] == s[n]:
            l += 1
print(l)

Submission status: Time Limit Exceeded

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

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#C - Green Bin(ABC137)
N=int(input())
S=[]
c=0
for i in range(N):
    S.append(input())
    
for i in range(N-1):
    for v in range(i+1,N):
        A=S[v]
        for n in S[i]:
            A=A.replace(n,'',1)
        if A=="":
            c+=1
print(c)

Submission status: Time Limit Exceeded

Solution code:
#C - Green Bin(ABC137)
N=int(input())
S=[]
c=0
for i in range(N):
    S.append(input())
    
for i in range(N-1):
    for v in range(i+1,N):
        A=S[v]
        for n in range(10):
            A=A.replace(S[i][n],'',1)
        if A=="":
            c+=1
print(c)