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:
import collections
N = int(input())
s = [collections.Counter(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        c = 1
        for k in s[i].items():
            if k not in s[j].items():
                c = 0
                break
        if c == 1:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
s = [collections.Counter(input()) for i 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())
l = []
c=0
for i in range(N):
    s = input()
    ss = sorted(s)
    for te in l:
        if ss == te:
            c+=1
    l.append(ss)
print(c)

Submission status: Time Limit Exceeded

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    s = [SS() for _ in range(N)]

    cnt = [collections.Counter(i) for i in s]
    
    ans = 0
    for i, j in itertools.combinations(cnt, 2):
        if i == j:
            ans += 1

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [''.join(sorted(input())) for i in range(N)]
ans=0
for elem in set(S):
    sum_ = S.count(elem)
    if sum_>=2:
        ans += sum_*(sum_-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S = [''.join(sorted(input())) for i in range(N)]
ans=0
for elem in set(S):
    sum_ = sum([s==elem for s in S])
    ans += sum_*(sum_-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,*S=open(0).read().split()
S = [''.join(sorted(s)) for s in S]
ans=0
for elem in set(S):
    sum_ = sum([s==elem for s in S])
    ans += sum_*(sum_-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,*S=open(0).read().split()
ans=0
def is_anagram(a,b):
    a = sorted(a)
    b = sorted(b)
    return True if a==b else False

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
ans = 0
c = []
for _ in range(n):
    k=input()
    c.append(Counter(k))

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

Submission status: Time Limit Exceeded

Solution code:
'''
Created on 2020/08/31

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  S=[]
  for _ in [0]*N:
    s=list(pin()[:-1])
    s.sort()
    S.append(s)
  cnt=0
  for i in range(N):
    for j in range(i+1,N):
      if S[i]==S[j]:
        cnt+=1
  print(cnt)
  return 
main()

Submission status: Time Limit Exceeded

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

l = []
ans = 0
for i in range(N):
    if sorted(s[i]) in l:
        ans += l.count(sorted(s[i]))
    l.append(sorted(s[i]))

print(ans)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
alf=["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"]
N=int(input())
li=[]
mi=[]
for i in range(N):
    s=input()
    temp=[0]*26
    for j in range(10):
        num=alf.index(s[j])
        temp[num]+=1
    if temp in li:
        mi[li.index(temp)]+=1
    else:
        li.append(temp)
        mi.append(1)
ans=0
for m in range(len(mi)):
    ans+=mi[m]*(mi[m]-1)//2
print(ans)

Submission status: Time Limit Exceeded

Solution code:
alf=["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"]
N=int(input())
li=[]
for h in range(N):
    li.append([0]*26)
for i in range(N):
    s=input()
    for j in range(10):
        num=alf.index(s[j])
        li[i][num]+=1
ans=0       
for k in range(N):
    for l in range(N):
        if k<l:
            if li[k]==li[l]:
                ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

z = {():0}
ans = 0

def combinations(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(n):
    c = [0]*123
    s = input()
    for j in range(len(s)):
        c[ord(s[j])] += 1
    try:
        z[tuple(c)] += 1
    except:
        z[tuple(c)] = 1

for i in z:
    ans += combinations(z[i],2)

print(ans)

Submission status: Time Limit Exceeded

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

M_sorted = [''.join(sorted(m)) for m in M]
M_setlist = list(set(M_sorted))
ans = 0

for m in M_setlist :
    c =M_sorted.count(m)
    if c == 2 :
        ans += 1
    elif 3 <= c :
        ans += (c**2 -c*3)/2 + c

print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter
n = int(input())
s = [str(input()) for i in range(n)]
num = 0
for i in itertools.combinations(s,2):
    x = Counter(i[0]).most_common()
    y = Counter(i[1]).most_common()
    x.sort()
    y.sort()
    if x == y:
        num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = [str(input()) for i in range(n)]
m = 0
for i in itertools.combinations(s,2):
    num = 0
    for h in range(10):
        if i[1].count(i[0][h]) == i[0].count(i[0][h]):
            num += 1
    if num == 10:
        m += 1
print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

from collections import Counter

P = []
c = []
for _ in range(N):
    l=Counter(list(input())).most_common()
    l.sort(key = lambda x:x[0])
    if l not in P:
        P.append(l)
        c.append(1)
    else:
        p = P.index(l)
        c[p] += 1
ans = 0
for k in c:
    ans += int(k*(k-1)/2)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [tuple(sorted(list(input()))) for _ in range(n)]
ans = 0
st = []
count = {}

for i in range(n):
    if not s[i] in st:
        st += [s[i]]
        count[s[i]] = 0
    elif s[i] in st:
        count[s[i]] += 1
        ans += count[s[i]]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [tuple(sorted(list(input()))) for _ in range(n)]
ans = 0
st = []
count = {}

for i in range(n):
    if not s[i] in st:
        st += [s[i]]
        count[s[i]] = 0

for i in range(n):
    if s[i] in st:
        ans += count[s[i]]
        count[s[i]] += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
s = [Counter(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 = [sorted(input()) for i in range(n)]
cnt = 0
 
for j in range(n-1):
  for k in range(j+1,n):
    if s[j] == s[k]:
      cnt += 1
      
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import copy
dic = {}
for i in 'abcdefghijklmnopqrstuvwxyz':
    dic.setdefault(i,0)

n = int(input())
s = []
cnt = 0
for i in range(n):
    tmp_str = str(input())
    tmp_dic = copy.copy(dic)
    for j in range(10):
        tmp_dic[tmp_str[j]] += 1
    for j in range(len(s)):
        if tmp_dic == s[j]:
            cnt += 1
    s.append(tmp_dic)
#print(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = []
cnt = 0
for i in range(n):
    tmp_str = str(input())
    tmp_dic = {}
    for j in range(10):
        tmp_dic.setdefault(tmp_str[j],0)
        tmp_dic[tmp_str[j]] += 1
    sort_list = sorted(tmp_dic.items())
    for j in range(len(s)):
        if sort_list == s[j]:
            cnt += 1
    s.append(sort_list)
#print(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import copy

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

ssort=[]


for i in range(n):
  a=s[i]
  b=sorted(a)
  ssort.append(b)

tsort=copy.copy(ssort)

cnt=0

for i in tsort:
  for j in ssort:
    if i==j:
      cnt+=1

print((cnt-n)//2)

Submission status: Time Limit Exceeded

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

ssort=[]

for i in range(n):
  a=s[i]
  b=sorted(a)
  ssort.append(b)

cnt=0
for j in range(0,n):
  for k in range(0,n):
    if j!=k:
      if ssort[j]==ssort[k]:
        cnt+=1

print(cnt//2)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

a = []

for i in range(n):
  word = list(input())
  word.sort()
  letters = []
  for j in word:
    if j not in letters:
      letters.append([j, 1])
    else:
      letters[len(letters) - 1][1] += 1
  a.append(letters)

cnt = 0

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

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[''.join(sorted(input())) for _ in range(N)]
import itertools
l=itertools.combinations(range(N), 2)
cnt=0
for x,y in l:
     if S[x]==S[y]: cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[]
for i in range(N):
  S=input()
  tmp=[0]*26
  for s in S:
    tmp[ord(s)-ord('a')]+=1
  L.append(tmp)
ans=0
for i in range(N):
  for j in range(i+1,N):
    if L[i]==L[j]:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n = int(input())
s = [str(input()) for i in range(n)]
w = "abcdefghijklmnopqrstuvwxyz"
num = 0
for h in itertools.combinations(s,2):
    t = 0
    for j in w:
        if h[0].count(j) == h[1].count(j):
            t += 1
        if t == 26:
            num += 1
print(num)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

mylist = []
for i in range(N):
    mylist.append(''.join(sorted(input())))

count=0
for j in range(len(mylist)):
    for k in range(1,N-j):
        if mylist[j]==mylist[j+k]:
            count=count+1
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-08-18 14:20:26 +0900
# LastModified: 2020-08-18 14:29:03 +0900
#


import os
import sys
from collections import Counter


def main():
    n = int(input())
    ans_box = dict()
    for i in range(n):
        s = list(map(str, input()))
        s_cnt = Counter(s)
        ans_box[i] = s_cnt
    cnt = 0
    for i in range(n):
        for j in range(i+1, n):
            if ans_box[i] == ans_box[j]:
                cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
S.append("".join(sorted(input())))
cnt = 0
for _ in range(N-1):
    i = str("".join(sorted(input())))
    for j in S:
        if i == j:
            cnt += 1
    S.append(i)

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
S = []
S.append(input())
cnt = 0
for _ in range(N-1):
    i = input()
    a = sorted(i)
    for j in S:
        b = sorted(j)
        if a == b:
            cnt += 1
    S.append(i)

print(cnt)

Submission status: Time Limit Exceeded

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

IJ = list(itertools.combinations(S,2))
cnt = 0
for ij in IJ:
    i = sorted(list(str(ij[0])))
    j = sorted(list(str(ij[1])))
    if i == j:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
count =0
store_list=[]
ans_list=[1]*n
for _ in range(n):
    s = input()
    dict_s =Counter(s)
    #print(dict_s)
    if dict_s in store_list:
        a = store_list.index(dict_s)
        ans_list[a] += 1
    else:
        store_list.append(dict_s)
#print(sum(ans_list))
#print(ans_list)
sum = 0
for i in range(n):
    b = ans_list[i]
    sum += b*(b-1)/2
       
print(int(sum))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
# from fractions import gcd # >=Python3.5 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # <Python3.5
# from math import sqrt

# input = sys.stdin.readline
# def main():

#---------------------------------------------------------

n = int(input())

clist = [None for _ in range(n)]
cnt   = 0

for i in range(n):
    clist[i] = Counter(input())

for i in range(n):
    if i < n:
        for j in range(i+1,n):
            if clist[i] == clist[j]:
                cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = sorted([sorted(input()) for _ in range(n)])
ans = 0
start = 0
for i in range(start, n - 1):
    for j in range(i + 1, n):
        if ss[i] == ss[j]:
            ans += 1
        else:
            start = j
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ss = sorted([sorted(input()) for _ in range(n)])
ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        #print(i, ss[i], j, ss[j])
        if ss[i] == ss[j]:
            ans += 1
        else:
            break
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import factorial

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

N=int(input())
A=[]
B=[]
for i in range(N):
    s=input()
    s=sorted(s)
    A.append(s)
    if s not in B:
        B.append(s)

ans=0
for i in range(len(B)):
    if A.count(B[i])>1:
        ans+=combinations_count(A.count(B[i]),2)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

strings = []
cnts = []

for i in range(n):
    s = input()
    sd = {}
    for i in range(10):
        if s[i] in sd:
            sd[s[i]] += 1
        else:
            sd[s[i]] = 1

    new = True
    for i in range(len(strings)):
        match = True
        for key, value in strings[i].items():
            if key in sd:
                if sd[key] != value:
                    match = False
                    break
            else:
                match = False
                break

        if match:
            cnts[i] += 1
            new = False
            break

    if new:
        strings.append(sd)
        cnts.append(1)

print(sum(list(map(lambda x: x*(x-1)//2, cnts))))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = list(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:
S=[]
n = int(input())
for i in range(n):
    s=sorted(input())
    S.append(s)
cnt=0
for j in range (len(S)):
    for p in range(j+1,len(S)):
        if S[j]==S[p]:
            if j!=p:
                cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

l=list(set(s))

ans=[]
for i in range(len(l)):
    ans.append(s.count(l[i]))
m=0
for i in range(len(l)):
    j=ans[i]
    m+=j*(j-1)//2
print(m)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=[[0]*26 for _ in range(N)]
a=ord('a')
for i in range(N):
  s=input()
  for c in s:
    L[i][ord(c)-a]+=1
count = 0
for i in range(N-1):
  for j in range(i+1,N):
    if L[i] == L[j]:
      count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

T = [''.join(sorted(input())) for _ in range(N)]
S = set(T)

ans = 0
for moji in S:
    c = T.count(moji)
    ans += c * (c - 1) // 2

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    S = [sorted(input()) for i 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)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
S=[[x for x in sorted(input().rstrip())] for i in range(N)]
c=0
for i in range(N):
    for j in range(i+1,N):
        if S[i]==S[j]:
            c+=1
print(c)

Submission status: Time Limit Exceeded

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i in range(n):
    s[i] = [s[i][j] for j in range(10)]
    s[i] = collections.Counter(s[i])

same =[]

for dic in s:
    count = 0
    while dic in s:
        s.remove(dic)
        count += 1
    else:
        same.append(count)

ans = 0

for num in same:
    ans += num * (num-1) // 2

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections

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

for i in range(n):
    s[i] = [s[i][j] for j in range(10)]
    s[i] = collections.Counter(s[i])

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:
import collections
N = int(input())
A = []
for i in range(N):
    s = sorted(input())
    A.append(str(s))
cnt = 0
for i in set(A):
    k = collections.Counter(A)[i]
    cnt += k*(k-1)//2
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import collections
N = int(input())
cnt = 0
A = []
for i in range(N):
    s = sorted(input())
    s = str(s)
    cnt += collections.Counter(A)[s]
    A.append(s)
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N=int(input())
s=[sorted(input()) for i in range(N)]

def factorial(num):
    x=1
    for i in range(num,0,-1):
        x = x *i

    return x

s.sort()

ans=0
ref=s[0]

cnt=1

for i in range(1,N):
    if s[i]==ref:
        cnt+=1
        if i==N-1:
            ans+=factorial(cnt)//factorial(cnt-2)//2
    else:
        ref=s[i]
        if cnt>1:
            ans+=factorial(cnt)//factorial(cnt-2)//2
        cnt=1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
def main():
    N = int(input())
    
    lst = []
    count = 0
    for i in range(N):
        s = ''.join(sorted(str(input())))
        #print(s,lst)
        if s in lst:
            count += Counter(lst)[s]
        lst.append(s)
    print(count)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

# s = [''.join(sorted(str(input()))) for _ in range(N)]
# #print(s)
# count = 0
# for i in range(N):
#     for j in range(i+1,N):
#         #diff = Counter(s[i])-Counter(s[j])
#         diff = s[i].replace(s[j],'')
#         if len(diff) == 0:
#             count += 1
        
# print(count)
lst = []
count = 0
for i in range(N):
    s = ''.join(sorted(str(input())))
    #print(s,lst)
    if s in lst:
        count += Counter(lst)[s]
    lst.append(s)
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

s = [''.join(sorted(str(input()))) for _ in range(N)]
#print(s)
count = 0
for i in range(N):
    for j in range(i+1,N):
        #diff = Counter(s[i])-Counter(s[j])
        diff = s[i].replace(s[j],'')
        if len(diff) == 0:
            count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N = int(input())

s = [str(input()) for _ in range(N)]
count = 0
for i in range(N):
    for j in range(i+1,N):
        diff = Counter(s[i])-Counter(s[j])
        if len(diff) == 0:
            count += 1
        
print(count)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
s = [input() for _ in range(n)]
ans = 0
c = []
cnt = []

for i in range(n):
    tmp = collections.Counter(s[i])
    if tmp not in c:
        c.append(tmp)
    else:
        ans += cnt.count(tmp)
    cnt.append(tmp)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import collections
n = int(input())
S = [input() for _ in range(n)]
ans = 0
c = []

for s in S:
    c.append(collections.Counter(s))

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N=int(input())
arr=[input() for i in range(N)]
ans=[]

for j in arr:
    kari={}
    for i in range(len(j)):
        if j[i] not in kari:
            kari[j[i]]=1
        else:
            kari[j[i]]+=1
    ans.append(kari)       

bns=0
for i in combinations(range(N),2):
    if ans[i[0]]==ans[i[1]]:
        bns+=1
print(bns)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n = int(input())
sl = []
for i in range(n):
    d = Counter(list(input()))
    sl.append(d)

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        jud = True
        for k in list(sl[i].keys()):
            if sl[j][k] != sl[i][k]:
                jud = False
                break
        if jud:
            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(input())
cnt = 0
for i in range(1,n):
    d1 = Counter(S[i])
    for j in range(i):
        d2 = Counter(S[j])
        if d1 ==d2: cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
s=[sorted(input()) for _ in range(int(input()))]
print(sum([sum(k) for k in [[s[i]==s[j] for j in range(i+1,len(s))] for i in range(len(s))]]))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
ans={}
visited=[]
for _ in range(n):
    s="".join(sorted(list(input())))
    if s in visited:
      ans[s]+=1
    else:
      ans[s]=1
      visited.append(s)

count=0
for i in ans:
  count+=((ans[i]*(ans[i]-1))//2)
print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
def main():
  input = sys.stdin.readline
  R=list()
  s=0
  L=list()
  N=int(input())
  for i in range(N):
    S=sorted(list(input()))
    if S not in R:
      R.append(S)
    L.append(S)
  for i in range(len(R)):
    c=L.count(R[i])
    s+=(c*(c-1))//2
  print(s)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
R=list()
s=0
L=list()
N=int(input())
for i in range(N):
  S=sorted(list(input()))
  if S not in R:
    R.append(S)
  L.append(S)
for i in range(len(R)):
  c=L.count(R[i])
  s+=(c*(c-1))//2
print(s)

Submission status: Time Limit Exceeded

Solution code:
s=0
L=list()
N=int(input())
for i in range(N):
  S=sorted(list(input()))
  s+=L.count(S)
  L.append(S)
print(s)

Submission status: Time Limit Exceeded

Solution code:
# abc137_c.py
# https://atcoder.jp/contests/abc137/tasks/abc137_c

# C - Green Bin /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 文字列 aに含まれる文字を何らかの順序で並べることで得られる文字列を aの アナグラム と呼びます。
# 例えば、greenbin は beginner のアナグラムです。このように、同じ文字が複数回現れるときはその文字をちょうどその回数だけ使わなければなりません。
# N個の文字列 s1,s2,…,sN が与えられます。それぞれの文字列は長さが 10 で英小文字からなり、またこれらの文字列はすべて異なります。
# 二つの整数 i,j (1≤i<j≤N) の組であって、si が sjのアナグラムであるようなものの個数を求めてください。

# 制約
#     2≤N≤105
#     siは長さ 10の文字列である。
#     siの各文字は英小文字である。
#     s1,s2,…,sNはすべて異なる。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# s1
# s2
# :
# sN

# 出力
# 二つの整数 i,j(1≤i<j≤N) の組であって、si が sjのアナグラムであるようなものの個数を出力せよ。

# 入力例 1
# 3
# acornistnt
# peanutbomb
# constraint

# 出力例 1
# 1

# s1=acornistnt は s3= constraint のアナグラムです。
# 他に si が sj のアナグラムであるような i,j の組はないため、答えは 1です。

# 入力例 2
# 2
# oneplustwo
# ninemodsix

# 出力例 2
# 0

# siが sj のアナグラムであるような i,j の組がないときは 0と出力してください。

# 入力例 3
# 5
# abaaaaaaaa
# oneplustwo
# aaaaaaaaba
# twoplusone
# aaaabaaaaa

# 出力例 3
# 4

# ここにそのようなケースを置くことはできませんが、答えは 32bit 整数型に収まらない可能性があるので注意してください。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # X, A = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    values = list()
    for i in range(N):
        values.append(lines[i+1])
    # valueses = list()
    # for i in range(M):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lines = list()

    for n in range(N):
        dic = get_blank_dic()
        for char in values[n]:
            dic[char] += 1
        lines.append(dic)

    cnt = 0
    for i in range(N-1):
        for j in range(i+1, N):
            flag = True
            for char in 'abcdefghijklmnopqrstuvwxyz':
                if lines[i][char] != lines[j][char]:
                    flag = False
            if flag:
                cnt += 1

    return [cnt]


def get_blank_dic():
    dic = dict()
    for char in 'abcdefghijklmnopqrstuvwxyz':
        dic[char] = 0
    return dic


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', 'acornistnt', 'peanutbomb', 'constraint']
        lines_export = [1]
    if pattern == 2:
        lines_input = ['2', 'oneplustwo', 'ninemodsix']
        lines_export = [0]
    if pattern == 3:
        lines_input = ['5', 'abaaaaaaaa', 'oneplustwo', 'aaaaaaaaba', 'twoplusone', 'aaaabaaaaa']
        lines_export = [4]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n=int(input())

lis=[]

for i in range(n):
  lis.append(sorted(list(input())))
co=0
for i in range(n):
  for j in range(i+1,n):
    if lis[i]==lis[j]:
      co+=1
print(co)

Submission status: Time Limit Exceeded

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def S(): return sys.stdin.readline().rstrip()

N = I()
s = [sorted(S()) for i 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)