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:
#!/usr/bin/env python3
import sys
from collections import defaultdict
from collections import Counter
from collections import OrderedDict

def solve(N: int, s: "List[str]"):
    count_dict = defaultdict(int)
    for i, string in enumerate(s):
        string = list(string)
        info = sorted(OrderedDict(Counter(string)).items(), key=lambda x:x[0])
        info = tuple([tuple([i, j]) for i, j in info])
        count_dict[info] += 1
    result = 0
    for _, v in count_dict.items():
        result += sum([i for i in range(v)])
    print(result)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
N = int(input())
string = [0] * N
ans = 0
for i in range(N):

    mozi = input()
    for k in range(10):
        string[i] += (ord(mozi[k])-96)**10

string_new = sorted(string)
for j in range(N-1):
    index = j + 1
    while string_new[j] == string_new[index]:
        ans += 1
        index += 1
        if index >= N:
            break

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n = int(input())
s_list = [input().split() for i in range(n)]
s_list = sorted(["".join(sorted(s[0])) for s in s_list])

comb = itertools.combinations(s_list, 2)
cnt = 0
for c in comb:
  if c[0]==c[1]:
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
s=[]
for i in range(n):
    s.append(str(input()))
    s[i]=''.join(sorted(s[i]))
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        tmp=0
        for k in range(10):
            if s[i][k]==s[j][k]:
                tmp+=1
            else:
                break
            if tmp==10:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
str_list = []
for i in range(N):
  str_dict = {}
  for j in input():
    if j in str_dict:
      str_dict[j] += 1
    else:
      str_dict[j] = 1
  str_list.append(str_dict)
  
count = 0
for i in range(N):
  for j in range(i+1, N):
    if str_list[i] == str_list[j]:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
s = []
for i in range(n):
    m = list(input())
    m.sort()
    s.append(m)
# print(s)
count = 0
for i in range(n):
    for j in range(n):
        # if i != j:
        if i < j:
        #     print(s[i])
        # print(s[j])
            if s[i] == s[j]:
                count += 1
# for i in range(n):
    
print(count)

Submission status: Time Limit Exceeded

Solution code:

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

ans = 0

for i in range(N):
    S.append(input())

for i in range(N):
    s_i = S[i]

    for j in range(i+1, N):
        s_j = S[j]

        if sorted(s_i) == sorted(s_j):
            ans += 1


print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())
s = list(input() for k in range(N))
result = 0

for i in range(N):
    counter = Counter(s[i])
    for j in range(i+1, N):
        temp = Counter(s[j])
        if counter == temp:
            result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

# input
[n] = [int(x) for x in stdin.readline().rstrip().split()]
s = []
for i in range(n):
    raw = list(str(stdin.readline().rstrip()))
    raw.sort()
    s.append("".join(raw))

c = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        if i > j:
            continue
        if s[i] == s[j]:
            c += 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# ABC137 C

def is_anagram(w1, w2):
    f = lambda y: "".join(sorted(map(lambda x: x.replace(' ', '').lower(), y)))
    return f(w1) == f(w2)
    
n = int(input())
s = []
for _ in range(n):
    s.append(input())

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

print(count)

Submission status: Time Limit Exceeded

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

S.sort()

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

cnt = 0
for c in itertools.combinations(s, 2):
    l1 = list(c[0])
    l1.sort()
    l2 = list(c[1])
    l2.sort()
    if l1 == l2:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

for _ in range(n):
    w = list(input())
    w.sort()
    s.append("".join(w))

count = 0

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

print(count)

Submission status: Time Limit Exceeded

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

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




n = int(input())

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

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
lists = []
for i in range(n):
    a = input()
    k = []
    for i in range(10):
        k.append(a[i])
    k.sort()
    lists.append(k)
count = 0
for i in range(n-1):
    for j in range(i+1,n):
        if lists[i] == lists[j]:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(list(si)))
    ans += s.count(sortedSi)
    s.append(sortedSi)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
ans = 0
for i in range(N):
    s = [v for v in input()]
    s.sort()

    for t in S:
        if s == t:
            ans += 1

    S.append(s)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i in range(N):
    S = input()
    s.append(collections.Counter(list(S)))

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

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
ls = []
for i in range(n):
    s = list(input())
    s = sorted(s)
    ls.append(s)
ans = 0
for i in ls:
    ans += (ls.count(i)-1)
    
print(round(ans/2))

Submission status: Time Limit Exceeded

Solution code:
import collections as c
import math

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

def C(n, r):
  return P(n, r)//math.factorial(r)

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

for i in s:
  count.append(dict(c.Counter(i).most_common()))

unique_count = []
comb = []
for i in count:
  if not i in unique_count:
    unique_count.append(i)
    comb.append(count.count(i))

print(sum([C(i, 2) for i in comb if i >= 2]))

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

cnt_dic = defaultdict(lambda: 0)

for _ in range(n):
    s = list(input())
    s.sort()
    cnt_dic[str(s)] +=1


ans = 0
for i in cnt_dic.values():
    if 1 < i:
        ans += combinations_count(i,2)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def isAnagramm(s1, s2):
    s1l = list(s1)
    s2l = list(s2)
    s1l.sort()
    s2l.sort()
    if (s1l == s2l):
        return True

n = int(input())
k = 0
s_arr = []+[""]*n
for i in range(n):
    s_arr[i] = str(input())
for i in range(n):
    for j in range(i+1, n):
        if isAnagramm(s_arr[i], s_arr[j]):
            k += 1
print(k)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

S=[''.join(sorted(input())) for _ in range(n)]

ans=0

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

Submission status: Time Limit Exceeded

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

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

COUNT = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        flag = 0
        for k in range(26):
            if count[i][k] != count[j][k]:
                flag = 1
                break
        if flag == 0:
            COUNT += 1

print(COUNT)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

line=[]
c=0

for i in range(n):
    string = sorted(list(input()))
    # print(string)
    c+=line.count(string)
    line.append(string)

print(c)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
data = []
for _ in range(n):
    d = {}
    line = list(input())
    for let in line:
        if not let in d:
            d[let] = 1
        else:
            d[let] += 1
    data.append(d)

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


print(count)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

al = [0] * (n + 10)
al[0] = 1
al[1] = 1
for i in range(2, n + 1):
    al[i] = al[i-1] * i

s = []
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    s.append(ss)

sset = list(set(s))

if(len(sset) == len(s)):
    print(0)
else:
    for e in sset:
        if(s.count(e) == 1):
            continue
        ans += s.count(e) * (s.count(e) - 1) // 2

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
count = 0
for i in range(n-1):
    si = [x for x in s[i]]
    si = Counter(si)
    for j in range(i+1, n):
        sj = [x for x in s[j]]
        if si == Counter(sj):
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math
def combinations(n, r):
  if n == r:
    return 1
  else:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N = int(input())
s = [[sorted(list(input())),1]]
ans = 0
for i in range(N-1):
  s_i = sorted(list(input()))
  flag = 0
  for j in range(len(s)):
    if s[j][0] == s_i:
      flag = 1
      s[j][1] += 1
      break
  if flag != 1:
    s.append([s_i,1])
for j in range(len(s)):
    tmp = s[j][1]
    if tmp != 1:
      ans += combinations(tmp,2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:

n = int(input())
data = []
data2 = []
ans = 0
for i in range(n):
    a = input()
    p = sorted(a)
    if p not in data:
        data.append(p)
        data2.append(1)
    else:
        data2[data.index(p)] += 1

#print(data2)
for i in data2:
    ans+=int(i*(i-1)/2)
print(ans)

Submission status: Time Limit Exceeded

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

cnt = 0

for i, item in enumerate(s):
    s[i] = ''.join(sorted(s[i]))

visited = []
for i in range(0, n):
    for j in range(i+1, n):
        if s[i] == s[j] and (i, j) not in visited:
            visited.append((i, j))
            visited.append((j, i))
            cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for i in range(n-1):
  for j in range(n):
    if i < j:
      for k in range(10):
        if s[i].count(s[i][k]) != s[j].count(s[i][k]):
          break
        if k == 9:
          ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

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:
# ' 'dで区切ってprintする方法
# print(*a, sep=' ')

import math

n = int(input())

ss = []
ss_data = []
sum = 0

for i in range(n):
    s_i = input()
    ss.append(s_i)
    s_i_data = {}

    for chara in s_i:
        if chara in s_i_data:
            s_i_data[chara] += 1
        else:
            s_i_data[chara] = 1

    ss_data.append(s_i_data)

# print(ss, ss_data)

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

print(sum)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

N = int(input())
# S = input()
# N, M = map(int, input().split())
# 横
# L = [int(x) for x in input().split()]
# 縦
S = [sorted(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
for i, s in enumerate(S) :
    for ss in range(i + 1, N) :
        if s == S[ss] :
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

strings = []

for i in range(N):
    strings.append(''.join(sorted(list(input()))))

ans = 0

for i in range(N-1):
    for j in range(i+1, N):
        if strings[i] == strings[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
dp = [0 for i in range(N)]
dp[0] = ''.join(sorted(list(input())))
ans = 0
for i in range(1, N):
    dp[i] = ''.join(sorted(list(input())))
    for j in range(i):
        if dp[j] == dp[i]:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = [None] * N
sums = [0] * N
sums2 = [0] * N
for i in range(N):
    s = input()
    S[i] = s
    count = 0
    count2 = 1
    for k in list(s):
        t = ord(k)
        count += t
        count2 *= t
    sums[i] = count
    sums2[i] = count2

result = 0
for i in range(N - 1):
    for k in range(i + 1, N):
        if sums[i] == sums[k] and sums2[i] == sums2[k]:
            result += 1

print(result)

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
for i in range(n):
    ans += letter[i:].count(letter[i]) -1
print(ans)

Submission status: Time Limit Exceeded

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

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

print(res)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

S = []
for i in range(n):
    s = input()
    s = sorted(list(s))
    S.append(s)

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

print(sum(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys
import collections
import copy
import math
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)
input = sys.stdin.readline
N = int(input())
ans_list=["test"]
ans_num=[1]
for i in range(N):
    chk = input().strip()
    for j in range(len(ans_list)):
        if verify_anagrams(ans_list[j],chk):
            ans_num[j] +=1
            break
        if j == len(ans_list)-1:
            ans_list.append(chk)
            ans_num.append(1)
ans = 0
for i in range(len(ans_num)):
    ans += ans_num[i]*(ans_num[i]-1)//2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
lis=[]
ans=[]
for i in range(n):
    lis.append(input())
    ans.append([0,0,0,0,0,0,0,0,0,0])
    for j in range(10):
        ans[i][j]=lis[i][j]
    ans[i].sort()

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

print(a)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


N = int(input())

s = [ input() for _ in range(N)]

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
n = int(sys.stdin.readline())
s_list = [sorted(list(sys.stdin.readline().rstrip())) for x in range(n)]
count = 0
for x in range(len(s_list)):
    for y in range(x+1, len(s_list)):
        if s_list[x] == s_list[y]:
            count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
  from collections import Counter
  N = int(input())
  S = [input() for _ in range(N)]

  tmp = []
  for s in S:
    tmp.append("".join(sorted(s)))
  cnt = 0
  for i, t in enumerate(tmp):
    for j in range(i+1, N):
      if tmp[i] == tmp[j]:
        cnt += 1
  print(cnt)

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

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

print(count)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
def main():
    n = int(input())
    ls = []
    count = 0
    for i in range(n):
        inp = sorted(input())
        count += ls.count(inp)
        ls.append(inp)
    print(count)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

adict=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

slist=[]
for _ in range(N):
    slist.append([])

for i in range(N):
    for j in range(len(adict)):
        p=s[i].count(adict[j])
        slist[i].append(p)

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

print(num)

Submission status: Time Limit Exceeded

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

ans = 0
for s in ssset:
    n = ss.count(s)
    if n > 1:
        ans += n * (n - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
for n in range(N):
  s = [ss for ss in input()]
  s.sort()
  S.append(s)

ans = 0
for i in range(0, len(S)-1):
  for j in range(i+1, len(S)):
    if S[i] == S[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)

count=0
for i in range(n-1):
    for j in range(i+1,n):
        a=sortlist[i]
        b=sortlist[j]
        if a==b:
            count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [input() for i in range(n)]
che = []
for i in s:
    che.append(Counter(i))
count=0
for i in range(len(che)):
    for k in range(i+1,len(che)):
        if che[i] == che[k]:
            count +=1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
S = []
ans = 0
for i in range(N):
  s = list(input())
#  c = Counter(s)
  c = sorted(s)
  S.append(c)
for i in range(N-1):
  for j in range(i+1,N):
    if S[i] == S[j]:
      ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = [[0]*26 for _ in range(n)]
for i in range(n):
    for j in range(97,123):
        ans[i][j-97] = s[i].count(chr(j))


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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

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

res = 0
for i in range(N):
    for j in range(i + 1, N):
        chk = 1
        for k in range(26):
            kc = chr(ord('a') + k)
            if cnts[i][kc] != cnts[j][kc]:
                chk = 0
                break
        res += chk
print(res)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N = int(input())
s_list = [Counter(list(input())) for _ in range(N)]
dict_list = []
count = 0
for i in range(N):
  for j in range(i+1,N):
    if s_list[i] == s_list[j]:
      count += 1
      
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
#ABC137C
import copy
import sys
import math

n = int(input())
#tmp = input().split()
#hoge = list(map(lambda a: int(a), tmp))
#k=hoge[0]
#x=hoge[1]

list = [[0 for i in range(26)] for j in range(n)]
#list[0][1]=1
#print(list)

for i in range(0,n):
	tmp=input()
	for j in range(0,10):
		list[i][ord(tmp[j])-ord("a")]+=1

sum=0
for i in range(0,n-1):
	for j in range(i+1,n):
		for k in range(0,26):
			if(list[i][k]!=list[j][k]):
				break
			elif(k==25):
				sum+=1

print(sum)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(raw_input())
S = [raw_input() for _ in range(N)]
D = {}
for s in S:
    k = "".join(sorted(s))
    if k not in D:
        D[k] = []
    D[k].append(s)

ans = 0
for k,v in D.items():
    n = len(v)
    if n > 1:
        ans += math.factorial(n) / (2 * math.factorial(n-2))
print ans

Submission status: Time Limit Exceeded

Solution code:
import collections


def p_c():
    n = int(input())
    s = [input() for _ in range(n)]

    s_d = [collections.Counter(i) for i in s]
    ans = 0

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

    print(ans//2)


if __name__ == '__main__':
    p_c()

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
        

obj = defaultdict(lambda: 1)

N=int(input())
ANA=[]
L=[]
for i in range(N):
    k=sorted([x for x in input()])
    if k in L:
        obj[L.index(k)]+=1
    else:
        L.append(k)

result=0
for i in obj.values():
    if i and i-1:
        result+=i*(i-1)/2
    
print(int(result))

Submission status: Time Limit Exceeded

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

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

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

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
counts = []
ex = [chr(ord('a') + i) for i in range(26)]
for s in S:
    cnt = [0 for _ in range(26)]
    for char in set(s):
        cnt[ex.index(char)] = s.count(char)
    counts.append(cnt)
#  print(counts)
done_list = []
ans = 0
for cnt in counts:
    if cnt in done_list:
        continue
    
    # nC2 を計算
    c = counts.count(cnt)
    if c == 1:
        continue
    a = combinations_count(c, 2)
    ans += a
    done_list.append(cnt)



print(ans)

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):
        temp.append(A[i][j])
    temp.sort()
    List.append(temp)
    
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if List[i] == List[j]:
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
arr = [input() for _ in range(n)]
count = 0
for i in range(n-1):
  c1 = collections.Counter(arr[i])
  for j in range(i+1,n):
    c2 = collections.Counter(arr[j])
    if c1 == c2:
      count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
s = []
ans = 0
for _ in range(N):
    occurence = {}
    si = input()
    for char in si:
        if char not in occurence:
            occurence[char] = 1
        else:
            occurence[char] += 1
    for previous in s:
        if previous == occurence:
            ans += 1
    s.append(occurence)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
a = [input() for i in range(int(input()))]
res = 0
for i in range(len(a)):
    for j in range(i+1, len(a)):
        if sorted(a[i]) == sorted(a[j]):
            res += 1
print(res)