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=[input() for i in range(N)]
a=0
for i in range(N-1):
    t=s[i]
    u=list(t)
    u.sort()
    for j in range(N-1-i):
        v=s[i+j+1]
        w=list(v)
        w.sort()
        for k in range(10):
            if u[k]==w[k]:
                if k<9:
                    continue
                else:
                    a=a+1
            else:
                break
print(a)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
list1 = []
list2 = []
count = 0
for i in range(n):
    s = input()
    list1.append(s)

from collections import Counter
 
def verify_anagrams(first_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word)



for j in range(len(list1)):
    list2.append(verify_anagrams(list1[j]))
for k in range(len(list1)):
    for l in range(k+1,len(list1)):
        if list2[k] == list2[l]:
            count = count + 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())

S = [0 for i in range(N)]

for i in range(N):
  S[i] = input()
  
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
m=[]
o=[1]
ans=0
for i in range(n):
    s=input()
    l=[0]*26
    for v in range(10):
        if s[v]=="a":
            l[0]+=1
        elif s[v]=="b":
            l[1]+=1
        elif s[v]=="c":
            l[2]+=1
        elif s[v]=="d":
            l[3]+=1
        elif s[v]=="e":
            l[4]+=1
        elif s[v]=="f":
            l[5]+=1
        elif s[v]=="g":
            l[6]+=1
        elif s[v]=="h":
            l[7]+=1
        elif s[v]=="i":
            l[8]+=1
        elif s[v]=="j":
            l[9]+=1
        elif s[v]=="k":
            l[10]+=1
        elif s[v]=="l":
            l[11]+=1
        elif s[v]=="n":
            l[12]+=1
        elif s[v]=="m":
            l[13]+=1
        elif s[v]=="o":
            l[14]+=1
        elif s[v]=="p":
            l[15]+=1
        elif s[v]=="q":
            l[16]+=1
        elif s[v]=="r":
            l[17]+=1
        elif s[v]=="s":
            l[18]+=1
        elif s[v]=="t":
            l[19]+=1
        elif s[v]=="u":
            l[20]+=1
        elif s[v]=="v":
            l[21]+=1
        elif s[v]=="w":
            l[22]+=1
        elif s[v]=="x":
            l[23]+=1
        elif s[v]=="y":
            l[24]+=1
        else:
            l[25]+=1
    m.append(l)
m.sort()
for k in range(1,n):
    if m[k]==m[k-1]:
        o[-1]+=1
    else:
        o.append(1)
for _ in range(len(o)):
    if o[_]==1:
        pass
    else:
        c=(o[_]*(o[_]-1))//2
        ans+=c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def check(line):
    moji = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    for c in line:
        if c == 'a':
            moji[0] += 1
        if c == 'b':
            moji[1] += 1
        if c == 'c':
            moji[2] += 1
        if c == 'd':
            moji[3] += 1
        if c == 'e':
            moji[4] += 1
        if c == 'f':
            moji[5] += 1
        if c == 'g':
            moji[6] += 1
        if c == 'h':
            moji[7] += 1
        if c == 'i':
            moji[8] += 1
        if c == 'j':
            moji[9] += 1
        if c == 'k':
            moji[10] += 1
        if c == 'l':
            moji[11] += 1
        if c == 'm':
            moji[12] += 1
        if c == 'n':
            moji[13] += 1
        if c == 'o':
            moji[14] += 1
        if c == 'p':
            moji[15] += 1
        if c == 'q':
            moji[16] += 1
        if c == 'r':
            moji[17] += 1
        if c == 's':
            moji[18] += 1
        if c == 't':
            moji[19] += 1
        if c == 'u':
            moji[20] += 1
        if c == 'v':
            moji[21] += 1
        if c == 'w':
            moji[22] += 1
        if c == 'x':
            moji[23] += 1
        if c == 'y':
            moji[24] += 1
        if c == 'z':
            moji[25] += 1
    return moji


N = int(input())
s = [input() for i in range(N)]
res = []
count = 0

for x in s:
    res.append(check(x))

for k, x in enumerate(res):
    for j in range(k+1, N):
        if x == res[j]:
            count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import string

N = int(input())

CountList = []

atoz = string.ascii_lowercase
for i in range(N):
    temp = ''
    s=input()
    CountList.append(''.join(sorted(s)))

count = 0
for i,str1 in enumerate(CountList[:-1]):
    for str2 in CountList[i+1:]:
        if str1==str2:
            count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
l_cnt = []
for i in range(N):
  s.append(input())
list_dic = []
for i in range(N):
  se = set(s[i])
  dic = {}
  for sei in se:
    dic[sei] = 0
  for sii in s[i]:
    dic[sii] += 1
  flag = False
  for dic_mir in list_dic:
    if dic == dic_mir:
      flag = True
  if flag == True:
    l_cnt[list_dic.index(dic)] += 1
  else:
    list_dic.append(dic)
    l_cnt.append(0)
ans = 0
for cnt in l_cnt:
  ans += cnt * (cnt+1) // 2
print(ans)

Submission status: Time Limit Exceeded

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

nums = []
for w in ws:
    v = [0] * 52
    for c in w:
        if "Z" < c:
            v[ord(c) - ord("a")] += 1
        else:
            v[ord(c) - ord("A") + 26] += 1
    nums.append(v)

r = 0
for i in range(n):
    for j in range(n):
        if j <= i:
            continue
        b = True
        for k in range(52):
            b &= nums[i][k] == nums[j][k]
        r += b

print(r)

Submission status: Time Limit Exceeded

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

[s[i].sort() for i in range(len(s))]

cnt = 0
for i in s:
    for j in s:
       if i == j:
        cnt += 1
        
cnt = (cnt - N)//2

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy

n=int(input())
S = list()
A = [chr(i) for i in range(97, 97+26)]
for i in range(n):
	S.append(list(input()))

Q = [[0 for i in range(26)] for j in range(n)]
for i in range(n) :
	for j in range(26) :
		Q[i][j]=S[i].count(A[j])
	
cnt = 0

for i in range(n-1):
	for j in range(i+1,n):
		if(Q[i]==Q[j]):
			cnt+=1
		else:
			pass

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
anag = []
for _ in range(N):
  anag.append(input())

counter = [] 
for i in anag:
  counter.append(collections.Counter(i))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

count = 0
for j in range(N):
    if s.count(s[j]) > 1:
        count += s.count(s[j])-1

print(count//2)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
sl =[]
ans = 0
for i in range(n):
    s = sorted(input())
    ans+=sl.count(s)
    sl.append(s)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
count = 0
word = []
def verify_anagrams(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)

for _ in range(N):
    word.append(input())

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

Submission status: Time Limit Exceeded

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

for i in range(N):
  S = input()
  letters = list(S)
  letters.sort()
  S = "".join(letters)
  Candidate.append(S)

Answer = []
for i in range(N):
  for k in range(N-i-1):
    if Candidate[i] == Candidate[i+k+1]:
      Answer.append([i,k])
print(len(Answer))

Submission status: Time Limit Exceeded

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

def make_charcount(word):
    charcount = {}
    for c in word:
        if c not in charcount:
            charcount[c] = 1
        else:
            charcount[c] += 1
    return charcount

charcount_list = {}
charcount_list_index = 0
same_log = {}
for word in word_list:
    this_charcount = make_charcount(word)
    index = -1
    for i in charcount_list:
        if charcount_list[i] == this_charcount:
            index = i
            break
    if index != -1:
        if index not in same_log:
            same_log[index] = 1
        else:
            same_log[index] += 1
    else:
        charcount_list[charcount_list_index] = this_charcount
        charcount_list_index += 1
        
result = 0
for index in same_log:
    cnt = same_log[index]
    result += int(cnt*(cnt+1)/2)
print(result)

Submission status: Time Limit Exceeded

Solution code:
n =int(input())
A=[]
for I in range(n):
  moji=input()
  A.append(moji)
N=0
for i in range(n):
  a=list(A[i])
  a.sort()
  #print(a)
  for s in range(i+1,n,1):
    b=list(A[s])
    b.sort()
    #print(b)
    if a==b:
      N+=1
print(N)

Submission status: Time Limit Exceeded

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

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

print(match)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
A = [collections.Counter(list(input())) for i in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]==A[j]:
            ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction


def comb(n: int, k: int) -> int:
    if n < 0 or k < 0:
        pdt = 0
    else:
        pdt = 1
        for s in range(1, k + 1):
            pdt *= Fraction(n - s + 1, s)

    return pdt.numerator


N = int(input())

dic = {}
for i in range(N):
    s = sorted(input())
    s = "".join(s)
    dic.setdefault(s, 0)
    dic[s] += 1

ans = 0
for value in dic.values():
    ans += comb(value, 2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

def encode(s):
    alp = [0]*26
    for c in s:
        alp[ord(c)-97] += 1
    return tuple(alp)

def main():
    N = int(sys.stdin.readline())
    S = [encode(x.rstrip()) for x in sys.stdin.readlines()]

    dic = {}
    for i, s in enumerate(S):
        if s not in dic:
            dic[s] = [i]
        else:
            dic[s].append(i)

    count = 0
    for i, s in enumerate(S):
        count += len([x for x in dic[s] if x > i])

    print(count)

if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def ToAscii( str_, digit ) :
	num = 0
	for i in range( digit ) :
		num += 100**(i) * ( ord( str_[i] )-96 )
	return num

n = int( input() )
strs = []

str_nums = []
for i in range( n ):
	#strs.append( ''.join( sorted( list( input() ) ) ) )
	str_temp = sorted( list( input() ) )
	str_nums.append( ToAscii( str_temp, 10 ) )
count = 0
#strs = sorted( strs )
str_nums = sorted( str_nums )
for i in range( n ) :
	bFound = False
	for j in range( i+1, n ) :
		#if strs[i] != strs[j] :
		if str_nums[i] != str_nums[j] :
			break
		#if strs[i] == strs[j] :
		if str_nums[i] == str_nums[j] :
			count += 1
			bFound = True

print( count )

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

line=[]

for i in range(n):
    string = list(input())
    string.sort()
    line.append(''.join(string))

line_set = set(line)

c=0
k=None

for i in line_set:
    k = line.count(i)
    k = k*(k-1)//2
    c+=k

print(c)

Submission status: Time Limit Exceeded

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    s = list(sys.stdin.readlines())
    # new_s=sorted(s)
    char_list=[]
    for i in s:
        i = i.replace('\n','')
        new_s=sorted(i)
        new_s = ''.join(new_s)
        char_list.append(new_s)


    c = 0
    for j in range(n):
        if char_list[j] in char_list[j+1:]:
            c+=char_list[j+1:].count(char_list[j])
    print(c)

Submission status: Time Limit Exceeded

Solution code:
import math

n = int(input())
a = ["".join(sorted(input())) for i in range(n)]

uni_a = list(set(a))
eles = []
for i in range(len(uni_a)):
	eles.append(a.count(uni_a[i]))
cnt = 0
for i in range(len(eles)):
	if eles[i] != 1:
		cnt += eles[i]*(eles[i]-1) / 2
print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input() for i in range(N)]
ans = 0
str_list = []
for i in range(N):
  str_list.append(sorted(s[i]))
for i in range(N):
  for j in range(N):
    if i==j:
      continue
    if str_list[i] == str_list[j]:
      ans += 1
print(int(ans/2))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

s = []
for _ in range(N):
  s.append(''.join(sorted(str(input()))))   

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy
import math

def dictCount(str):
    dict = {}


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

    count = 0
    check = [0]*n
    for i in range(n):
        tmp=0
        for j in range(i,n):
            if j > i and check[j] ==0:
                if dict_list[i] == dict_list[j]:
                    check[j]=1
                    tmp=tmp+1
        if tmp >0:
            count = count + (1+tmp)*tmp/2
    print(int(count))

Submission status: Time Limit Exceeded

Solution code:
def sumsun(n):
  ret = 0
  for i in range(n,0,-1):
    ret = ret + i
    
  return ret

N = int(input())
# hoge = input().split()
s = []

for i in range(N):
  hoge = input()
  s.append("".join(sorted(hoge)))

ans = 0
itr = 0
while(1==1):
  fin = len(s) 
  if fin == 0:
    break
  is_google = s[itr]
  indexes = [i for i, x in enumerate(s) if x == is_google]
  ans = ans + sumsun(len(indexes)-1)
  while is_google in s:s.remove(is_google)
  
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import json
import hashlib

N = int(input())
c = []

for _ in range(N):
    s = input()
    d = dict(Counter(s))
    ds = sorted(d.items(), key=lambda x:x[0])
    h = hashlib.md5(json.dumps(ds).encode("utf-8")).hexdigest()
    c.append(h)

sum = 0
for i , v in Counter(c).items():
    sum += (v*(v-1)//2)
print(sum)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def verify_counters(first, second):
    return first == second

N = int(input())
words = [Counter(input()) for _ in range(N)]
ans = 0
while True:
    if not words:
        break
    target = words.pop(0)
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_counters(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)
    
    # 後ろからも
    if not words:
        break
    target = words.pop()
    same_word_index = []
    loop_sum = 0
    for i, word in enumerate(words):
        if verify_counters(target, word):
            same_word_index.append(i)
            loop_sum += 1
    # 同じやつをリストから消す
    if same_word_index:
        for index in reversed(same_word_index):
            words.pop(index)
    # 合計に加算
    ans += int((loop_sum * (loop_sum+1)) / 2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    t = list(r)
    t.sort()
    s[i] = ''.join(t)
total = 0
while len(s):
    a = s.pop(-1)
    count = 0
    for i in reversed(range(0, len(s))):
        if s[i] == a:
            count += 1
            s.pop(i)
    total += int((count + 1) * count / 2)
print(total)

Submission status: Time Limit Exceeded

Solution code:
N,*s=open(0).read().split()
s = ["".join(sorted(s_)) for s_ in s]
cnt = 0
for i in range(len(s)):
  cnt += (s[i:].count(s[i])-1)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))

for i in range(num):
  for j in range(num -i - 1):
    p = 0
    for k in range(10):
      if words[i][k] == words[j + 1 + i][k]:
        p += 1
      else:
        break
    if p == 10:
      answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = [input().split() for i in range(N)]
for i in range(N):
    s[i] = list(s[i][0])
    s[i].sort()
    s[i] = ''.join(map(str, s[i]))
s.sort()
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 i in range(n)])
q = []
c = 0
for i in range(n):
	q.append(sorted(s[i]))

for i in range(n):
	for j in range(i+1,n):
		if i != j:
			if q[i] == q[j]:
				c += 1

print(int(c))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

def verify_anagrams(w1, w2):
  f = lambda y: "".join(sorted(map(lambda x: x, y)))
  return f(w1) == f(w2)

count = 0

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

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

Submission status: Time Limit Exceeded

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

for j, si in enumerate(s):
    counter = [0 for _ in range(26)]
    for c in si:
        i = ord(c) - 0x61
        counter[i] += 1
    rep = 0
    for i in range(26):
        rep += counter[i] * (1<<(i*4))
    s2[j] = rep

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

print(pair)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

duplication = 0
output = 0

for i in range(N):
    for j in range(duplication, N):
        if i != j:
            if collections.Counter(s[i]) == collections.Counter(s[j]):
                output += 1
    duplication += 1

print(output)

Submission status: Time Limit Exceeded

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

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

    
ans = 0
i = 0
while i < len(List):
    j = i+1
    num = 1
    if List[i] != 0:
        while j < len(List):
            if List[i] == List[j]:
                num += 1
                List[j] = 0
            j += 1
        ans += (num*(num-1)*0.5)
    i += 1

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

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

    return result


N=int(input())

S=[]
S_count=dict()
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        S_count[s]+=1
    else:
        S_count[s]=1
    S.append(s)

key=list(set(S))

total=0

for k in key:
    t=S_count[k]
    if t>=2:
        total+=cmb(t,2)

print(total)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1

for v in count_dict.values():
    cnt += len(list(itertools.combinations(range(v), 2)))

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
from itertools import combinations

N=int(input())
count=0
S=[Counter(sorted(input())) for i in range(N)]
for a,b in list(combinations(S, 2)):
    if a==b:
        count+=1
print(count)

Submission status: Time Limit Exceeded

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

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


def comb(n, k):

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

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

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


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

Submission status: Time Limit Exceeded

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

t=['']*n

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

u=sorted(t)

cnt=0

for i in range(n-1):    
	seq=0
	for j in range(i+1,n):
		if u[i]==u[j]:
			cnt+=1
			seq=1
		else:
			if seq==1:
				break

print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
d = {}
for s in S:
  if s not in d:
    d[s] = 0
  d[s] += 1
  
ans = 0
for k, v in d.items():
  for i in range(v):
    for j in range(i+1,v):
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = 0
list1 = [list(input()) for i in range(N)]
for j in range(0,N-1):
    for k in range(j+1,N):
        if sorted(list1[j]) == sorted(list1[k]):
            a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dic = 'abcdefghijklmnopqrstuvwxyz'

save = []
cnt = 0
for i in range(N):
    s = input()
    l = []
    for j in range(len(dic)):
        l.append(s.count(dic[j]))
    for k in range(len(save)):
        if save[k] == l:
            cnt += 1
    save.append(l)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

ans = 0
T = []
ans = [1]*N
for i in range(N):
    if S[i] in T:
        p = T.index(S[i])
        ans[p] += 1
    else:
        T.append(S[i])

pp = 0
for i in ans:
    pp += (i-1)*i//2

print(pp)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
ans = 0
for i in range(n):
    s_str = list(input())
    s_str.sort()
    u="".join(s_str)
    s+=[u]
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:
import math
N = int(input())
s = []
for _ in range(N):
  s.append(str(input()))
  
cnt = 0

for i in range(N-1):
  s1 = s[i]
  s1list = list(s1)
  same = 0
  
  for j in range(i+1, N):
    s2 = s[j]
    s2list = list(s2) 
    if sorted(s1list) == sorted(s2list):
      cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import re
N = int(input())
al = "abcdefghijklmnopqrftuvwxyz"
S = []
for n in range(N):
    S2 = []
    s = input()
    for a in al:
        S2.append(s.count(a))
    S.append(S2)

# print (S)
cnt = 0
for n in range(N):
    for n2 in range(n + 1, N):
        if (S[n] == S[n2]): cnt += 1

print (cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

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

    return result

N = int(input())
matched = [False] * N
s = [None] * N
for i in range(N):
    s[i] = input()



ans = 0
i = 0
j = 1
cnt = 0
while i < N:
    cnt = 0

    if matched[i] == True:
        if i >= N-1:
            break
        
        i += 1
        j = i+1
        continue

    si = Counter(s[i])
    while j <= N-1:

        if matched[j] == True:
            j += 1

            continue


        sj = Counter(s[j])
        if si == sj:
            matched[i] = True
            matched[j] = True
            cnt += 1
        j += 1
    
    if cnt != 0:
        ans += cmb(cnt+1,2)

    if i == N-2:
        break

    i += 1
    j = i+1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

input = sys.stdin.readline


def main():
    n = int(input())
    lines = ["".join(sorted(input().strip())) for _ in range(n)]
    count = 0
    for text in set(lines):
        count += len([_ for _ in combinations(range(lines.count(text)), 2)])
    print(count)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
L = []
M = []
C = 0
for i in range(N):
  M0 = input()
  M1 = [M1 for M1 in M0]
  M.append(M1)
for i in range(N):
  M[i].sort()
for l in range(N):
  for m in range(N):
    if m > l:
      if M[m] == M[l]:
        C += 1
print(C)

Submission status: Time Limit Exceeded

Solution code:

N=int(input())
li=[]
for i in range(N):
  li.append(input())
count=0
from collections import Counter
 
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.upper().replace(' ', ''))
 
    return get_counter(first_word) == get_counter(second_word)
for i in range(N):
  for j in range(i+1):
    if i != j:
      if verify_anagrams(li[i],li[j]):
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a_list = []
a = 0
str1 = ""
str2 = ""

for i in range(N):
    a_list.append("".join(sorted(input())))

for k in range(N):
    for l in range(k + 1, N):
        if a_list[k] == a_list[l]:
            a += 1

print(a)

Submission status: Time Limit Exceeded

Solution code:
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

letter = []
alpha = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
for i in range(n):
    word = []
    s = input()
    for i in range(26):
        word.append(s.count(alpha[i]))
    letter.append(word)
ans = 0
moya = []
for i in range(n):
    moya.append([letter.count(letter[i]), letter[i]])
aaaa = get_unique_list(moya)
for i in range(len(aaaa)):
    kusa = aaaa[i][0]
    ans += kusa * (kusa -1) // 2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
words = []
answer = 0

for i in range(num):
  words.append(sorted(list(input())))

for i in range(num):
  for j in range(num -i - 1):
    p = 0
    for k in range(10):
      if words[i][k] == words[j + 1 + i][k]:
        p += 1
    if p == 10:
      answer += 1

print(answer)

Submission status: Time Limit Exceeded

Solution code:
import collections

n=int(input())
a=[]
for i in range(n):
  s=list(input())
  s.sort()
  t="".join(s)
  a.append(t)
c=collections.Counter(a)
l=len(c)
ans=0
for i in range(l):
  m=c.most_common()[i][1]
  ans += int(m*(m-1)/2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=int(input())
l=set(map(str,sys.stdin))
alp=[chr(_) for _ in range(97,97+26)]
res=[]
ans=0

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

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
lists = [input() for i in range(num)]

count = 0


for n, i in enumerate(lists):
   lists[n] = sorted(list(i))

for i in range(num):
  for j in range(num):
    if i != j:
      if lists[i] == lists[j]:
        count += 1

print(int(count/2))