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: Runtime Error

Solution code:
def cmb(n,r):
        if r > n: 
            return 0
        if n - r < r:
             r = n - r
        if r > n: 
            return 0
        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 resultr


import collections
N = int(input())
s= [input() for i in range(N)]
ans=0
#各文字列文字列をソート
s=list(map(sorted,s))

s.sort()        #リストをソート
s=list(map(''.join,s))  #リストになっていたものを文字列に変換
clist = collections.Counter(s) #リスト内の各要素の数を数え上げ
kaisu=list(clist.values())

for i in kaisu:
        ans += cmb(i,2)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())

s = []
ss = []
for i in range(n)
	s.append(str(input()))
  	ss.append(sorted(str(input())))
  
c = 0
for i in range(n)
	for l in range(i+1,n)
  		if ss[i] == ss[l]:
      		c += 1
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(10**10)
 
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

count = 0
memo = [0]*10**6
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]
        
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(100000000)
 
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

count = 0
memo = [0]*10**5
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]
        
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(10000000)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

count = 0
memo = [0]*10**4
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]

print(count)

Submission status: Runtime Error

Solution code:
a = int(input())
l = []
for x in range(a):
    s = sorted(input())
    w = ''.join(s)
    l.append(w)

l.sort()
count = 0
x = 0
for item in l:
    if(x == 0):
        x += 1
        continue
    else:
        if(item[x-1] == item[x]):
            x += 1
            count += 1
        else:
            x += 1

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
s = [input() for _ in range(N)]
 
import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())
 
import sys
sys.setrecursionlimit(100000)
 
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

count = 0
memo = [0]*10**4
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]

print(count)

Submission status: Runtime Error

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

import collections
sortedList = [''.join(sorted(x)) for x in s]
countNum = list(collections.Counter(sortedList).values())

import sys
sys.setrecursionlimit(100000)

nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

count = 0
memo = [0]*10**4
for n in countNum:
    if n!=1:
        if memo[n] == 0:
            memo[n] = cmb(n, 2)
        count += memo[n]
        
print(count)

Submission status: Runtime Error

Solution code:
a = int(input())
l = []
for x in range(a):
    s = sorted(input())
    w = ''.join(s)
    l.append(w)

count = 0
x = 0
for item in l:
    if(x == 0):
        x += 1
        continue
    else:
        if(item[x-1] == item[x]):
            x += 1
            count += 1
        else:
            x += 1

print(count)

Submission status: Runtime Error

Solution code:
n = int(input())

s = []
for _ in range(n):
    s += [sorted(input())]

import collections

c = collections.Counter(s)

ans = 0

for x in c.values():
    ans += x*(x-1)//2

print(ans)

Submission status: Runtime Error

Solution code:
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += cmb(v, 2)
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Submission status: Runtime Error

Solution code:
N = gets.to_i
as = N.times.map{gets.strip.codepoints.sort!}
h=Hash.new
cnt=0
for i in 0...N
  if h[as[i]].nil?
    h[as[i]]=0
  else
    h[as[i]]+=1
    cnt+=h[as[i]]
  end
end
puts cnt

Submission status: Runtime Error

Solution code:
#input N
N = int(input())

#define a list as a variable s:
s = list()

#input N words
for i in range(N):
    s.append(''.join(sorted(input())))

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

print(int(count)

Submission status: Runtime Error

Solution code:
import collections

n = int(input())
s = np.array([[str(i) for i in input().split()] for i in range(n)])
s = np.ravel(s)
ans = 0
sorted_list = [''.join(sorted(e)) for e in s]
# dict
c = collections.Counter(sorted_list)
for i in c.values():
  for j in range(0, i):
    ans += j

print(ans)

Submission status: Runtime Error

Solution code:
a

Submission status: Runtime Error

Solution code:
def f_c():

    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]

    c = 0
    for _ in range(n):
        si = s.pop()
        if si in s:
            c += s.count(s2)
    print(c)

if __name__ == "__main__":
    f_c()

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
#lis = list(set(s))
lis = list(map(list, set(map(tuple, s))))
print(lis)
c = 0
for i in lis:
    indexes = [k for k, x in enumerate(s[i:]) if x == i]
    c += len(indexes)
print(c)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append(sorted(input()))
lis = list(set(s))
print(lis)
c = 0
for i in range(1,N-1):
    indexes = [k for k, x in enumerate(s[i:]) if x == s[i-1]]
    c += len(indexes)
print(c)

Submission status: Runtime Error

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

ans=0
f=1
for i in range(n-1):
    if li[i]==li[i+1]:
        f+=1
    else:
        ans+=f*(f-1)//2
        f=1
print(ans+f*(f-1)//2)

Submission status: Runtime Error

Solution code:
import collections
import sys
from scipy.special import comb


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += str(v)
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c = [count_abc(st) for st in s]
  
  c_dict = collections.Counter(s_c)
  
  ans = 0
  
  for v in c_dict.values():
    if v > 1:
      ans += comb(v, 2, exact=True)
  
  print(ans)

  
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:

N = int(input())
mojiretu = [input() for _ in range(N)]
dict = {}
answer = 0

for n in mojiretu:
  a = ''.join(sorted(list(n)))
  if a in dict.keys():
    dict[a]+=1
  else:
    dict[a]= 1

def fact(n):
    if n == 0 or n == 1:
        return 1
    else:
        return n * fact(n-1) 
      
def nck(n,k):
  return int(fact(n)/(fact(n-k)*fact(k)))
      
for value in dict.values():
	if value > 1:
		answer += nck(value,2)

print(answer)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for s in A:
    if s in D:
        count+=1
    else:
        D+=s
print(count)

Submission status: Runtime Error

Solution code:
import collections
import sys


scan = sys.stdin.readline

def count_abc(string):
  alphabet = dict.fromkeys("abcdefghijklmnopqrstuvwxyz",0)
  
  for char in string:
    num = alphabet[char]
    alphabet[char] = num + 1
  
  c_str = ""
  for k, v in alphabet.items():
    c_str += k
    c_str += v
  
  return c_str


def main():
  n = int(scan().rstrip())
  s = [scan().rstrip() for _ in range(n)]
  
  s_c [count_abc(string) for string in s]
  
  c_dict = collections.Counter(s_c)
  
  print(max(c_dict))

Submission status: Runtime Error

Solution code:
n=int(input())
a=[list(input()) for i in range(n)]
b=[str(sorted(list(i))) for i in a]
count=list(collections.Counter(b).values())
count=[i for i in count if i>1]
print(int(sum([math.factorial(x)/(math.factorial(x-2)*2) for x in count])))

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
cnt = {}
ans = 0
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  if s_ in s:
    ans += cnt[s_]
    cnt[s_] += 1
  else:
    s.append(s_)
    cnt[s_] = 1

print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

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

d = {}
for s in S:
    s = "".join(sorted(s))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1
ans = 0
for v in d.values():
    if v > 1:
        ans += comb(v, 2)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
mojiretu = [input() for _ in range(N)]
dict = {}
answer = 0

for n in mojiretu:
  a = ''.join(sorted(list(n)))
  if a in dict.keys():
    dict[a]+=1
  else:
    dict[a]= 1
 

def fact(n):
  if n == 0 or n == 1:
    return 1
  else:
    return n * fact(n-1)

  
for value in dict.values():
	if value > 1:
		answer += fact(value-1)

print(answer)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
s = []
cnt = []
for i in range(n):
  s_ = list(str(input()))
  s_.sort()
  if s_ in s:
    cnt[s.index(s_)] += 1
  else:
    s.append(s_)
    cnt.appned(1)

print(sum(cnt))

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0

diclist = []

for i in range(0,N+1):
  temp = list(input())
  temp.sort()
  if temp in diclist:
    ans = ans +1
  else:
    diclist.append(temp)

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0

diclist = []

for i in range(0,N+1):
  temp = list(input()).sort()
  if temp in diclist:
    ans = ans +1
  else:
    diclist.append(temp_str)

print("{}".format(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0

diclist = []

for i in range(0,N+1):
  temp = list(input()).sort()
  if temp in diclist:
    ans = ans +1
  else:
    diclist.append(temp_str)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

ans = 0

diclist = []

for i in range(0,N+1):
  temp = list(input()).sort()
  temp_str = ''.join(temp)
  if temp_str in diclist:
    ans = ans +1
  else:
    diclist.append(temp_str)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
array = [sorted(input()) for x in range(n)]
set_array = set()
for i in array:
  set_array.add(i)
print(len(array) - len(set_array))

Submission status: Runtime Error

Solution code:
n = int(input())
array = [sorted(input()) for x in range(n)]
print(len(set(array)) )

Submission status: Runtime Error

Solution code:
n = int(input())
array = [sorted(input()) for x in range(n)]
print(len(array) - len(set(array)))

Submission status: Runtime Error

Solution code:
import numpy as np
N = input()
N = int(N)
Sdict = {}
n_anagram = 0
D = {"a":2, "b":3, "c":5, "d":7, "e":11, "f":13,"g":17, "h":19, "i":23, "j":29, "k":31, "l":37, "m":41, "n":43,
"o":47, "p":53, "q":57, "r":59, "s":61, "t":67, "u":71, "v":73, "w":79, "x":83, "y":87, "z":1}

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

for s in S:
    s = np.prod([D[x] for x in s])
    if s in S:
        n_anagram = n_anagram + S[s]
        S[s] += 1
    else:
        S[s] = 1
    
print(n_anagram)

Submission status: Runtime Error

Solution code:
import math
num = int(input())
words = {}

for i in range(num):
  a = str(sorted(list(input())))
  
  if a in words:
    words[a] += 1
  else:
  	words[a] = 1

points = list(words.values())
sum = 0
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
for i in range(len(points)):
  sum += combinations_count(points[i], 2)
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
ans = 0
dict_word = {}
for i in range(N):
  sorted_word = [''.join(sorted(list(input()))) for i in range(N)]
  try:
    ans += dict_word[sorted_word]
    dict_word[sorted_word] += 1
  except:
    dict_word[sorted_word] = 1

print(ans)

Submission status: Runtime Error

Solution code:
number=int(input())
List=[list(map(input() for i in range(number)))]
print(List)

Submission status: Runtime Error

Solution code:
N = int(input())
word = [input() for i in range(N)]
sorted_word = [sorted(list(word[i])) for i in range(N)]
dict_word = {sorted_word[i]:0 for i in range(N)}
count = 0
ans = 0

def sum_all(x):
  for i in range(x+1):
    y += i
  return y

for i in range(N):
  if sorted_word[i] in sorted_word[i+1:]:
	dict_word[sorted_word[i]] += 1
    
for value in dict_word.value():
  ans += sum_all(value)
  
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ans = 0
dict = {}
for _ in range(n):
    s = sorted(list(input()))
    if dict[s] == NULL:
        dict[s] = 0
    ans += dict[s]
    dict[s] += 1
print(ans)

Submission status: Runtime Error

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

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=_collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if tp[1]!=1:
        sums=sums+combinations_count(tp[1],2)
    else:break
    
print(sums)

Submission status: Runtime Error

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

N=int(input())
strings=[sorted(input()) for a in range(N)]
strings.sort()
sums=0
sorteds=strings
for st in list(set(sorteds)):
    n=sorteds.count(st)
    if n!=1:
       sums=sums+combinations_count(n,2)

print(sums)

Submission status: Runtime Error

Solution code:
import copy
N = int(input())
word = [input() for i in range(N)]
sorted_word = [sorted(list(word[i])) for i in range(N)]
copy_word = copy.copy(sorted_word)
count = 0
for i in range(N-1):
  copy_word.remove(sorted_word[i])
  if sorted_word[i] in copy_word
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
src = [''.join(sorted(input())) for _ in range(n)]
dic = {}
for s in src:
    # 辞書にキーが存在しなければキー追加
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
count = 0
# 辞書から値だけ取り出す
for d in dic.values():
    # dまでの値の組み合わせを合計する
    if d > 2:
        count += int(factorial(d) / factorial(2) / factorial(d - 2))
    elif d == 2:
        count += 1
print(count)

Submission status: Runtime Error

Solution code:
s = [''.join(sorted(input())) for i in range(N)]
 
dic = {}
cnt = 0
for i in range(N):
    if s[i] in dic:
        cnt += dic[s[i]]
        dic[s[i]] += 1
    else:
        dic[s[i]] = 1
print(cnt)

Submission status: Runtime Error

Solution code:
from math import factorial


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

l = []
count = 0
for i in range(n):
    if a[i] not in l:
        m = a.count(a[i])
        if m > 1:
            count += factorial(m) / 2 / factorial(m - 2)
        l.append(a[i])
    else:
        continue
print(int(count))

Submission status: Runtime Error

Solution code:
    n = int(input())
    li = [sorted(list(input())) for i in range(n)]
     
    li2 = []
    for i in range(len(li)):
        li2.append(li.count(li[i]))
     
    li3 = list(set(li2))
        
    num = 0   
    if len(li3) <=1:
      print(0)
    for i in range(len(li3)):
        if li3[i] >= 2:
            num += li3[i]*(li3[i]-1)//2        
     
    print(num)

Submission status: Runtime Error

Solution code:
from math import factorial


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

l = []
count = 0
for i in range(n):
    if a[i] not in l:
        m = a.count(a[i])
        if m > 1:
            count += factorial(m) / 2 / factorial(m - 2)
        l.append(a[i])
    else:
        pass
print(int(count))

Submission status: Runtime Error

Solution code:
N = input()
word = [input() for i in range(N)]
sorted_word = [word[i].sort() for i in range(N)]
count = 0
for i in range(N):
  for j in range(i, N):
    if sorted_word[i] == sorted_word[i+j]:
      count += 1
print(count)

Submission status: Runtime Error

Solution code:
import math

def calc_comb(n):
    k = 2
    if n <= 1 :
        return 0
    elif n ==2 :
        return 1
    return math.factorial(n)/(math.factorial(n-k) * math.factorial(k))

n = int(raw_input(""))

smap = {}
tmp = ""
for i in range(0, n):
    tmp = ''.join(sorted(raw_input("")))
    if smap.get(tmp, None) == None:
        smap[tmp] = 1
    else:
        smap[tmp] += 1
count = 0
for s, num in smap.items():
    #print num
    count += calc_comb(num)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in D:
        D[S] += 1
    else:
        D[S] = 1
 
ans = 0
for i in D.values():
    out += i-1
print(out)

Submission status: Runtime Error

Solution code:
N = int(input())
count = 0
DIC = {}
for i in range(n):
    j = ''.join(sorted(input()))
    if j in DIC:
        count += DIC[j]
        DIC[j] += 1
    else:
        DIC[j] = 1
print(count)

Submission status: Runtime Error

Solution code:
import heapq

n,m=map(int,input().split())
l=[[int(_) for _ in input().split()] for __ in range(n)]

l=sorted(l, key=lambda x:x[1], reverse=True)

a=[]
day=0
ans=0
for j in range(1,m+1):
    while 1:
        if day>=n:
            break
        if l[day][0]<=j:
            heapq.heappush(a,-l[day][1])
            day+=1
        else:
            break
    if a:
        ans-=heapq.heappop(a)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
count = 0
dic = {}
for _ in range(n):
    key = ''.join(sorted(input()))
    if key in dic:
        c += dic[key]
        dic[key] += 1
    else:
        dic[key] = 1
print(count)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [input() for _ in range(n)]
s = [sorted(i) for i in s]
s.sort()
s.append(["AA"])
counts = []
count = 1

for i in range(len(s) - 1):
    if s[i] == s[i + 1] and s[i + 1] == s[i + 2]:
        count += 1
    elif s[i] == s[i + 1] and s[i + 1] != s[i + 2]:
        count += 1
        counts.append(count)
        count = 1

ans = 0
for i in counts:
    mul = 1.0
    for j in range(i + 1)[1:]:
        mul *= j
    ans += mul / 2

print(int(ans))

Submission status: Runtime Error

Solution code:
#from collections import Counter
#from itertools import combinations
n = int(input())
lst = ["".join(soted(list(input()))) for i in range(n)]
#lst2 = 1#Counter(lst)
#for i in len(lst):
#  print(i.values)


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

#print(cmb(4,2),0,0,0)
cnt = 0
for i in Counter(lst).values():
  if i == 1:
    continue
  cnt += cmb(i, 2)
"""
for i in range(len(lst)-1):
  for j in range(i+1,len(lst)):
    #print(0)
    if lst[i]==lst[j]:
      cnt += 1
"""
print(cnt)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict
from scipy.special import comb

input = sys.stdin.readline

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += comb(d[key], 2, exact=True)
print(int(ans))

Submission status: Runtime Error

Solution code:
num = int(input())
range_arr = range(num)

strs = [[] for i in range_arr]
for i in range_arr:
    strs[i] = input()

def conv(str):
    str_arr = list(str)
    str_arr.sort()
    return ''.join(str_arr)

new_strs = list(map(lambda v: conv(v), strs))
new_strs.sort()
compact_strs = list(set(new_strs))

cnt = 0
for str in compact_strs:
    str_count = new_strs.count(str)
    print(f'str_count:{str_count}')
    if str_count >= 2:
        cnt += int(str_count*(str_count-1)/2)

print(cnt)

Submission status: Runtime Error

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict

n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] >= 2:
        ans += ncr(d[key], 2)

print(int(ans))

Submission status: Runtime Error

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict


n = int(input())
d = defaultdict(lambda: 0)

for i in range(n):
    s = list(str(input()).rstrip())
    s.sort()
    s = "".join(s)
    d[s] += 1   

ans = 0
for key in d.keys():
    if d[key] > 1:
        ans += ncr(d[key], 2)
print(d)
print(int(ans))

Submission status: Runtime Error

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

from math import factorial

def ncr(n, r):
    return factorial(n) / factorial(r) / factorial(n - r)

from collections import defaultdict


n = int(input())
d = defaultdict(lambda: 0)

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

ans = 0
for key in d.keys():
    if d[key] > 1:
        ans += ncr(d[key], 2)

print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

list = []

for i in range(N):
  list.append(list(input().sort()))
  
dct = {}
count = 0
for i in list:
  if i in dct:
    dct[i] = 1
    count = count + 1
    continue
  else:
    dct[i] = dct + 1
    count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
# -*- coding: UTF-8 -*-
import math

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

for i in range(n):
    l.append("".join(sorted(str(input()))))

l.sort()

p = 0
s = 0
f = 0

for i in range(n):
    if l[i] == l[i+1]:
        s =+ 1
        f = 1
    elif l[i] != l[i+1] and f == 1:
        s += 1
        f = 0
        p += math.factorial(s)/(2 * math.factorial(s-2))


print(p)

Submission status: Runtime Error

Solution code:
def C():
    N = int(input())

    word_dict = dict()
    count = 0

    for i in range(N):
        word = sorted(input())
        if word not in word_dict:
            word_dict[word] = 1
        else:
            count += 1

    print(count)
    
if __name__ == '__main__':
    C()

Submission status: Runtime Error

Solution code:
n = int(input())
di = {}
for i in range(n):
    sl = "".join(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = 1
    for i in range(1,n+1):
        a *= i
    return int(a / 2) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
s = [sum([ord(j) for j in input()]) for i in range(n)]
sum = 0
def saiki(a):
    if a == 0:
        return 0
    return a + saiki(a-1)
for i in range(len(set(s))):
    key = s[0]
    sum += saiki(s.count(s[0])-1)
    for j in range(s.count(s[0])):
        s.remove(key)

print(sum)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
N = int(input())
# スペース区切りの整数の入力
a = []
for i in range(N):
  a.append(input())

b = []
for s in a:
  temp = list(s)
  temp.sort()
  b.append("".join(temp))

count = 0
for s in set(b):
  temp = b.count(s)
  if temp >= 2:
    count += factorial(temp) / factorial(2) / factorial(temp - 2)

print(int(count))

Submission status: Runtime Error

Solution code:
di ={}
n = int(input())
di = {}
for i in range(n):
    sl = tuple(sorted(list(input())))
    if sl in di:
      di[sl] += 1
    else:
      di[sl] = 1
def nc2(n):
    a = 1
    for i in range(1,n+1):
        a *= i
    return int(a / 2) #1c2 =0
ls = di.items()
cnt = 0
for i in ls:
    cnt += nc2(i[1])
print(cnt)

Submission status: Runtime Error

Solution code:
from math import factorial

i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []

for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0
for e in l2:
    n = ll.count(e)
    if n >=2:
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial

i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []

for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0


if(i-len(l2) >=2):
    for e in l2:
        n = ll.count(e)
        if n >=2:
            a = factorial(n) / factorial(2) / factorial(n - 2)
            ans += a
    print(int(ans))
else:
    print(i-len(l2))

Submission status: Runtime Error

Solution code:
from math import factorial

i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []

for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0


if(i-len(l2) >=2):
    for e in l2:
        n = ll.count(e)
        if n >=0:
            a = factorial(n) / factorial(2) / factorial(n - 2)
            ans += a
    print(int(ans))
else:
    print(i-len(l2))

Submission status: Runtime Error

Solution code:
from math import factorial

i = int(input())
l = [sorted(input()) for i in range(i)]
ll= []

for item in l:
    an = ''.join(item)
    ll.append(an)
l2 = list(set(ll))
 
ans = 0


if(i-len(l2) >=2):
    for e in l2:
        n = ll.count(e)
        a = factorial(n) / factorial(2) / factorial(n - 2)
        ans += a
    print(int(ans))
else:
    print(i-len(l2))

Submission status: Runtime Error

Solution code:
import numpy as np
import string

a = string.ascii_lowercase

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

for i in range(N):
    s.append(input())
    
k = np.zeros((N,26))

for i in range(N):
    for j in range(26):
        k[i,j] = s[i].count(a[j])

l = np.zeros(N)
for i in range(N):
    for j in range(26):
        l[i] += (11**(j+1)) * k[i,j]

m = np.zeros(0)
for j in range(N):
    i = 0
    m = np.append(m, np.size(l[l == l[i]]))
    l = l[l != l[i]]
    
    if l.size == 0:
        break

m = np.delete(m, np.size(k)-1)

ans = 0
for i in range(np.size(m)):
    ans += m[i] * (m[i]-1) /2
    
print(int(ans))

Submission status: Runtime Error

Solution code:

N = int(input())

cnt_dict = {}

for i in range(N):
    s_list = list(input())
    s_str = "".join(s_list.sort())
    if s_str not in cnt_dict.keys():
        cnt_dict[s_str] = 1
        continue
    cnt_dict[s_str] += 1

import itertools
comb = itertools.combinations

total = 0
for key in cnt_dict.keys():
    cnt = cnt_dict[key]
    if cnt < 2:
        continue
    total += len(list(comb(range(cnt), 2)))

print(total)