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:
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int N;
    cin >> N;
    
    vector<string> v;
    string s;
    for(int i=0; i<N; i++) {
        cin >> s;
        v.push_back(s);
    }

    for(int i=0; i<v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }

    int result = 0;
    for(int i=0; i<v.size(); i++) {
        result += count(v.begin()+i, v.end(), v[i]) - 1;
    }
    
    cout << result << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
import math
n = int(input())
s = [['n' for i in range(10)] for j in range(n)]
for i in range(n):
    s[i]=list(input())
    s[i].sort()
j=0
tans=1
ans=0
donei=[]
for i in range(n):
    if not i in donei:
        j=n-1
        while j>i:
            if s[i]==s[j]:
                tans = tans + 1
                donei.append(j)
            j=j-1
        ans = ans + int(math.factorial(tans)/2)
        tans=1

print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter

def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s)
 
    return get_counter(first_word) == get_counter(second_word)

N = int(input())

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
S=list(input() for k in range(N)
Slist = [0] * N
for i in range(N):
    Slist[i] = sorted(S[i])
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if len(Slist) - len(get_unique_list(Slist)) == 0:
    print(0)
else:
    print(len(Slist) - len(get_unique_list(Slist)) + 1)

Submission status: Runtime Error

Solution code:
n = int(input())
s = []
cnt = 0
h = []
x = 0
g = long(0)

for z in range(n) :
    g = 0
    s.append((list(input())))
    for w in range(10) :
        g = ord(s[z][w]) + g
    h.append(g)

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

print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
    s.append(input())
def uniGram(sentences_String):
    return([sentences_String[0+i:1+i] for i in range(len(sentences_String)-1+1)])
sUniGramed = list(map(uniGram, s))
sSorted = []
for k in range(N):
    sSorted.append(sUniGramed[k].sort())

ans = 0
for i in range(N):
    current = sUniGramed[i]
    for j in range(N-i):
        if current == sUniGramed[i+j+1]:
            ans += 1
        else:
            pass
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

l=[]
for _ in range(n):
  a=soretd([i for i in input()])
  b=''.join(a)
  l.append(b)

count=0
for i in range(n):
  for j in range(n):
    count+=int(l[i]==l[j])

ans=count/2-n
print(ans)

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
    int N;
    cin >> N;
    
    vector<string> v;
    string s;
    for(int i=0; i<N; i++) {
        cin >> s;
        v.push_back(s);
    }

    for(int i=0; i<v.size(); i++) {
        sort(v[i].begin(), v[i].end());
    }

    int result = 0;
    for(int i=0; i<v.size(); i++) {
        result += count(v.begin()+i, v.end(), v[i]);
    }
    
    cout << result << endl;
    
    return 0;
}

Submission status: Runtime Error

Solution code:
N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  a=list(s1)
  b=list(s2)
  a.sort()
  b.sort()
  if a==b:
    return True
  else:
    return False
  
cnt=0
for i in range(len(sn)-1):
  m=1
  for ii in range(i+1,len(sn)):
    if sn[ii] and check(sn[i],sn[ii]):
      cnt+=m
      m+=1
      sn[ii]=None

print(cnt)

Submission status: Runtime Error

Solution code:
N=int(input())
l=[]
for x in range(0,N):
    l.append(input())
for x in range(0,N):
    l[x]=sorted(list(l[x]))
l=sorted[l]
x=0
y=0
for i in range(0,N):
    for j in range(i+1,N):
        if l[i]==l[j]:
            x=x+1
        else:
            y=y+sum(range(1,x+1))
            i=i+x+1
            break
print(y)

Submission status: Runtime Error

Solution code:
N = int(input())
s = []
for _ in range(N):
    s.append(input())
def uniGram(sentences_String):
    return([sentences_String[0+i:1+i] for i in range(len(sentences_String)-1+1)])
sUniGramed = list(map(uniGram, s))
sSorted = []
for k in range(N):
    sSorted.append(sUniGramed[k].sort())

ans = 0
for i in range(4):
    current = sUniGramed[i]
    for j in range(4-i):
        if current == sUniGramed[i+j+1]:
            ans += 1
        else:
            pass
print(ans)

Submission status: Runtime Error

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

for i in range(n):
    s[i].sort()
s.sort()

ans=0
result=0
for i in range(n):
    for j in range(1,n-i-1):
        if(s[i]==s[i+j]):
            result+=1
            continue
        else:
            ans+=result*(result+1)/2
            print(result)
            result=0
            i=i+j

print(int(ans))

Submission status: Runtime Error

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

char_list = []
lst = []
lst02 = []
for i in range (0,n):
  str = letters[i]
  char_list = list(str)
  a = sorted(char_list)
  a = ", ".join(a)
  lst = lst.append(a)

Submission status: Runtime Error

Solution code:
n=int(input())

l=[]
for _ in range(n):
  a=soretd([i for i in input()])
  b=''.join(a)
  l.append(b)

count=0
for i in range(n):
  for j in range(n):
    count+=int(l[i]==l[j])

ans=count-n
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())

for _ in range(N):
    S = input()

ans = 0
for i in range(N-1):
  for j in range(1,N-i):
    cnt = 0
    for ca in S[i]:
      for cb in S[i+j]:
        if ca == cb:
          cnt += 1
          break
    if cnt == 10:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from collections import defaultdict
from itertools import combinations
import sys
input = sys.stdin.readline

n = int(input())
s = [input().split()[0] for _ in range(n)]
cnt = defaultdict(int)
for i in range(n):
    s[i].sort()
    cnt["".join(s[i])] += 1
result = 0
for c in cnt:
    result += len(list(combinations([""] * cnt[c], 2)))
print(result)

Submission status: Runtime Error

Solution code:
from collections import Counter
from scipy.special import comb
N = int(input())
s = [input() for i in range(N)]
c = []
rem = []
num = 0
for i,si in enumerate(s):
    s.pop(i)
    snum = 0
    for j,sj in enumerate(s):
        if Counter(si) == Counter(sj):
            snum+=1
            rem.append(j)
    rem.reverse()
    num += comb(snum+1, 2, exact=True)
    for r in rem:
        s.pop(r)
    rem.clear()
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import collections
from math import factorial

max = int(input())
i = 0
strings = []
while True:
  if i == max:
    break
  strings.append(input())
  i+=1

#print(strings) # ['acornistnt', 'peanutbomb', 'constraint']

strings2 = [list(str) for str in strings]
[str.sort() for str in strings2] # 配列の中身を副作用でソートする
# print(strings2)
strs3 = [''.join(str) for str in strings2] # ソートした文字のリストを文字列に戻す

#print(strs3)

c = collections.Counter(strs3)
# print(c)
counts = list(c.values()) # 組み合わせの数のリスト
counts2 = [ c for c in counts if c > 1] # 2個以上の重複がないものは除外
#print(counts2)

# nC2 の組み合わせを計算して、合計する
print(sum([int(factorial(n) / factorial(2) / factorial(n - 2)) for n in counts2]))

Submission status: Runtime Error

Solution code:
import collections
import math
 
N = int(input())
words = [input() for i in range(N)] 
 
ans = 0
L = []
for ix, word in  enumerate(words):
    word_list = list(word)
    word_list.sort()
    L.append(''.join(map(str, word_list)))
 
c = collections.Counter(L)
 
for i in c.values():    
    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)
 
print(int(ans))

Submission status: Runtime Error

Solution code:
N = int(input())

for _ in range(N):
    S = input()

ans = 0
for i in range(N-1):
  for j in range(1,N-i):
    cnt = 0
    for ca in S[i]:
      for cb in S[i+j]:
        print("i+j"+str(i+j))
        print(ca)
        print(cb)
        if ca == cb:
          print("ok")
          cnt += 1
          print(cnt)
          break
    if cnt == 10:
      ans += 1
    print("next!!!!")

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from math import factorial

n = int(input())
strlist = []
for i in range(n):
    strlist.append(sorted(list(str(input()))))

allcount = 0
while (len(strlist) > 1):
    i = 1
    count = 1
    while True:
        if(strlist[0] == strlist[i]):
            count += 1
            strlist.pop(i)
        else:
            i += 1
        if(i==len(strlist)):
            if(count > 1):
                allcount += int(factorial(count) / factorial(2) / factorial(count-2))
            break
    strlist.pop(0)
print(allcount)

Submission status: Runtime Error

Solution code:
N=int(input())
sn=[input() for _ in range(N)]
def check(s1,s2):
  for c in s1:
    if s1.count(c)!=s2.count(c):
      return False
  else:
    return True
  
cnt=0
for i in range(len(sn)-1):
  m=1
  for ii in range(i+1,len(sn)):
    if sn[ii] and check(sn[i],sn[ii]):
      cnt+=m
      m+=1
      sn[ii]=None

print(cnt)

Submission status: Runtime Error

Solution code:
def conv(s):
  return ord(s) - 97

def sum_list(i):
    return int((i*(i+1))/2)

n = int(input())

ls = []
for i in range(n):
    ls.append(input())

lss = []
for i in range(n):
    ll = [0] * 25
    lss.append(ll)

for i in range(n):
    for j in range(10):
        lss[i][conv(ls[i][j])]+=1

ans = 0
llss = sorted(lss)

count = 0
for i in range(len(llss)):
    if (i == len(llss)-1):
        break

    if (llss[i] == llss[i+1]):
        count+=1
        if (i == len(llss)-2):
            ans += sum_list(count)
    else:
        ans += sum_list(count)
        count=0

print(ans)

Submission status: Runtime Error

Solution code:
import math

num = int(input())
emp = []
for i in range(num):
    emp.append(','.join(sorted(input())))
set_emp = set(emp)
emp2 = []
for i in set_emp:
    emp2.append(emp.count(i))
num = 0
for i in emp2:
     num += int(math.factorial(i) / 2)
print(num)

Submission status: Runtime Error

Solution code:
import numpy as np
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append(np.zeros(10))
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.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
        else:
            break

print(int(a))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
lst = list()
num = 0
flag = 1
for i in range(n):

    s = input()
    s = list(s)
    s.sort()
    lst.append(s)

lst.sort()

for i in range(n-1):
    if (lst[i] == lst[i+1]):
        flag = flag + 1
    else:
        num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
        flag = 1
if (flag > 1):
    num = num + math.factorial(flag) // (math.factorial(flag - 2) * 2)
print(num)

Submission status: Runtime Error

Solution code:
iport numpy as np
n=int(input())
ans=[]
for i in range(n):
    qw=input()
    ans.append(np.zeros(10))
    for j in range(10):
        ans[i][j]=qw[j]
    ans[i].sort()

ans.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
        else:
            break

print(int(a))

Submission status: Runtime Error

Solution code:
n = int(input())
s = {}
for i in range(n):
    string = sorted(str(input()))
    s.add(string)
num = len(s)
if n==num:
    print(0)
else:
    print(n-num+1)

Submission status: Runtime Error

Solution code:
from itertools import combinations
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))

Submission status: Runtime Error

Solution code:
from collections import deque
import sys
input = sys.stdin.readline

n=int(input())
s=deque([])
cnt=0
for _ in range(n):
    s.append(input().sort())
for i in range(n):
    for j in range(n):
        if i<j:
            if s[i]==s[j]:
                cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())

for _ in range(N):
    S = input()

ans = 0
for i in range(N-1):
  for j in range(1,N-i+1):
    cnt = 0
    for ca in S[i]:
      for cb in S[i+j]:
        print("i+j"+str(i+j))
        print(ca)
        print(cb)
        if ca == cb:
          print("ok")
          cnt += 1
          print(cnt)
          break
    if cnt == 10:
      ans += 1
    print("next!!!!")

print(ans)

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

N = int(input())
b =[]
for i in range(N):
    a = input()
    b.append([j for j in a])
    b[i].sort()
a = [''.join(j) for j in b]
b = [k for k in collections.Counter(a).values()]
c = 0
for x in range(len(b)):
    if b[x] > 1:
        c += comb(b[x], 2, exact=True)
    else:
        None
print(c)

Submission status: Runtime Error

Solution code:
n = int(input())
result = []
for i in range(n):
    s = input()
    s = list(s)
    s.sort()
    result.append(s)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
no = get_unique_list(result)
counter = 0
for v in no:
  　c = result.count(v) - 1
　  cc = c * (c-1) /2
    counter += cc
print(counter)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

anagramed = []

def main():
    # n = map(int, input().split(" "))
    n = int(input())
    m = []
    count = 0

    for _ in range(n):
        m.append(input())
        anagramed.append(False)

    for i in range(n):
        shurui = 1
        if anagramed[i]:
            continue
        else:
            for j in range(i+1, n):
                if anagramed[j]:
                    continue
                elif is_anagram(m[i], m[j]):
                    shurui += 1
                    anagramed[i] = True
                    anagramed[j] = True
        if shurui > 1:
            count += int(math.factorial(shurui) / 2)
    print(count)


def is_anagram(s1, s2):
    s1_length = len(s1)
    s2_length = len(s2)
    if s1_length != s2_length:
        return False
    else:
        for index in range(s1_length):
            search_char = s1[index: index+1]
            search_result = s2.find(search_char)
            if search_result == -1:
                return False
            else:
                s2 = s2.replace(search_char, "", 1)
    return True

main()

Submission status: Runtime Error

Solution code:
N= int(input())
s = [''.join(sorted(list(input()))) for i in range(N)]
tmp = list(combinations(s,2))
result = [i for i in tmp if i[0] == i[1]]
print(len(result))

Submission status: Runtime Error

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

Dic = [1]*N
prime = {"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": 59,"r": 61,"s": 67,"t": 71,"u": 73,"v": 79,"w": 83,"x": 89,"y": 97,"z":101}

from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


for i in range(N):
    for s in S[i]:
        Dic[i]*= prime[s]

Dic.sort()
pre = Dic[0]
ans = 0
temp = 1
for d in Dic[1:]:
    if pre == d:
        temp += 1
    else:
        if temp >= 2:
            ans += comb(temp,2)
        pre = d
        temp = 1

ans += comb(temp,2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
import math

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

N = int(input())
s = [""]*N
S = []
for i in range(N):
    s[i] = input()
    test = [*s[i]]
    test.sort()
    S.append("".join(test))
ana = sorted(collections.Counter(S).values())
count = 0
for i in ana:
    if i >= 2:
        count += combinations_count(i,2)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S=list(input().split())
Slist = [0] * N
for i in range(N):
    Slist[i] = sorted(S[i])
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]

if len(Slist) - len(get_unique_list(Slist)) == 0:
    print(0)
else:
    print(len(Slist) - len(get_unique_list(Slist)) + 1)

Submission status: Runtime Error

Solution code:
import collections
import math


n = int(input())

inputlist = []

for i in range(n):
    inputlist.append("".join(sorted(list(input()))))

counter = collections.Counter(inputlist)

counter = dict(counter)
valuelist = list(map(int, counter.values()))

ans = 0

for i in valuelist:
    if i == 1:
        continue
    if i == 2:
        ans += 1
        continue
    ans += math.factorial(i) / 2 / math.factorial(i-2)

print(int(ans))

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(26)
for i in range(N):
    for j in range(26):
        l[i] += (1.1**(j+1)) * k[i,j]

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

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

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

Submission status: Runtime Error

Solution code:
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
s_list = []
ans = 0
for _ in range(N):
    s_list.append(''.join(sorted(list(input()))))
c = collections.Counter(s_list)
for i in range(N):
    m = c.most_common()[i][1]
    if m > 1:
        ans += cmb(m, 2)
    else:
        break
print(ans)

Submission status: Runtime Error

Solution code:
"""
https://atcoder.jp/contests/abc137/tasks/abc137_c
"""
import numpy as np


def calc(N: int, sorted_strings: np.ndarray) -> np.ndarray:
    strings_len = sorted_strings.shape[0]
    idx = np.arange(strings_len, dtype="int64")
    xx, yy = np.meshgrid(idx, idx, sparse=True)
    same = sorted_strings[xx] == sorted_strings[yy]
    same2 = same * (1 - np.tri(strings_len))
    return np.sum(same2, dtype="int64")


def main() -> None:
    N = int(input())
    sorted_strings = np.array(["".join(sorted(input())) for _ in range(N)])
    result = calc(N, sorted_strings)
    print(result)


main()

Submission status: Runtime Error

Solution code:
N = int(input())

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

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
  	if c > 1:
    	count += cmb(c, 2)

print(count)

Submission status: Runtime Error

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

from collections import Counter
from scipy.special import comb

nS = []
for s in S:
    s  = ''.join(sorted(s))
    nS.append(s)

c = Counter(nS)

acc = 0
for cnt in list(c.values()):
    acc+=comb(cnt, 2, exact=True)
print(acc)

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(26)
for i in range(N):
    for j in range(26):
        l[i] += (4**(j+1)) * k[i,j]

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

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

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

Submission status: Runtime Error

Solution code:
N=int(input())
count=0
s=[input() for i in range(N)]
n=['a' for t in range(N) for i in range(t+1,N) if s[t].sort==s[i].sort]
print(len(n))

Submission status: Runtime Error

Solution code:
"""
https://atcoder.jp/contests/abc137/tasks/abc137_c
"""
import numpy as np


def calc(N: int, sorted_strings: np.ndarray) -> np.ndarray:
    strings_len = sorted_strings.shape[0]
    idx = np.arange(strings_len, dtype="int64")
    xx, yy = np.meshgrid(idx, idx, sparse=True)
    same = sorted_strings[xx] == sorted_strings[yy]
    same2 = same * (1 - np.tri(strings_len))
    return np.sum(same2, dtype="int64")


def main() -> None:
    # N = int(input())
    # sorted_strings = np.array(["".join(sorted(input())) for _ in range(N)])
    N = 10 ** 5
    sorted_strings = np.array(["aaaaaaaaaa" for _ in range(N)])
    result = calc(N, sorted_strings)
    print(result)


main()

Submission status: Runtime Error

Solution code:
import collections
import math

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

N = int(input())
s = [""]*N
S = []
for i in range(N):
    s[i] = input()
    # print(s[i])
    # test = sorted(collections.Counter(input()))
    test = [*s[i]]
    test.sort()
    S.append("".join(test))
ana = sorted(collections.Counter(S).values())
count = 0
for i in ana:
    if i >= 2:
        count += combinations_count(i,2)
print(count)

Submission status: Runtime Error

Solution code:

n = int(input())
result = []
for i in range(n):
    s = input()
    s = list(s)
    s.sort()
    result.append(s)
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
no = get_unique_list(result)
counter = 0
for v in no:
  　j = result.count(v) - 1
　　b = j * (j-1) /2
   counter += b 
print(counter)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

n = int(input())
s = []
for i in range(n):
    sin = input()
    sin = list(sin)
    sin.sort()
    sin = ''.join(sin)
    s.append(sin)

ss = set(s)
count = 0
for u in ss:
    al = s.count(u)
    count += comb(al, 2, exact=True)
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S=list(input().split())
Slist = [0] * N
for i in range(N):
    Slist[i] = sorted(S[i])
def get_unique_list(seq):
    seen = []
    return [x for x in seq if x not in seen and not seen.append(x)]
print(len(Slist) - len(get_unique_list(Slist)) + 1)

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(26)
for i in range(N):
    for j in range(26):
        l[i] += (11**(j+1)) * k[i,j]

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

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

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

Submission status: Runtime Error

Solution code:
n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
for i in range(1,n) :
	ok = 1;
	k = 1;
	while s[i-k][9]==s[i][9] :
		#for j in range(10) :
			#if s[i-k][j] != s[i][j] :
				#ok = 0;
		if  s[i-k]==s[i]:
			ans += 1;
		k += 1;

print(ans);

Submission status: Runtime Error

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

mylist = []
for s in l:
    s_list = [ c for c in s]
    mylist.append("".join(sorted(s_list)))

ans=0
for i in range(len(mylist)):
    print(mylist)
    ans += mylist.count(mylist[0]) - 1
    del mylist[0]

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())

l=[]
for _ in range(n):
  a=soretd([i for i in input()])
  b=''.join(a)
  l.append(b)

ans=[]
for i in range(n-1):
  for j in range(i+1,n):
    ans.append(l[i]==l[j])

ans2=ans.count(True)    
print(ans2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from itertools import combinations
import math

N = int(input())
c = ["".join(sorted(str(input()))) for x in range(N)]
cs = Counter(c)

ans=0
for i in cs.values():
    ans += math.factorial(i)/2

print(int(ans))

Submission status: Runtime Error

Solution code:
import json


from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


n = int(input())
S = list()

A = list()
for _ in range(n):
  S.append(input())

for i in range(len(S)):
  hash = dict()
  for a in range(len(S)):
    for b in range(len(S[i])):
      hash[S[a][b]] = 0
  for j in range(len(S[i])):
    
    hash[S[i][j]] += 1
    
  A.append(hash)
  
count = 0
ddd = dict()
unique_list = list(map(json.loads, set(map(json.dumps, A))))
ans = 0
for dd in unique_list:

	ans += cmb(A.count(dd),2)

print(ans)

Submission status: Runtime Error

Solution code:
import collections

def total(n):
    if n < 1:
        return 0
    return n + total(n - 1)

l = [''.join(sorted(input())) for i in range(int(input()))]
s = collections.Counter(l)
a=0
for i in s.values():
    a += total(int(i)-1)
print(a)

Submission status: Runtime Error

Solution code:
n = int(input());
s = [0]*n;
for i in range(n) :
	s_pre = list(input());
	s_pre.sort();
	s[i] = s_pre;


s.sort(key=lambda x:(x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9]));

ans = 0;
for i in range(1,n) :
	ok = 1;
	k = 1;
	while s[i-k]==s[i] :
		#for j in range(10) :
			#if s[i-k][j] != s[i][j] :
				#ok = 0;
		if bool(ok) :
			ans += 1;
		k += 1;

print(ans);

Submission status: Runtime Error

Solution code:
import math

num = int(input())
emp = []
for i in range(num):
    emp.append(sorted(input())
set_emp = set(emp)
emp2 = []
for i in set_emp:
    emp2.append(emp.count(i))
num = 0
for i in emp2:
     num += int(math.factorial(i) / 2)
print(num)

Submission status: Runtime Error

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


N = int(input())
s = [""]*N
S = []
for i in range(N):
    s[i] = input()
    # print(s[i])
    # test = sorted(collections.Counter(input()))
    test = [*s[i]]
    test.sort()
    S.append("".join(test))
# print(s)
# print(S)
# count = 0
# for i in range(N-1):
#     for j in range(i+1,N):
#         if S[i] == S[j]:
#             count+=1
# print(count)
ana = sorted(collections.Counter(S).values())
ana_test = np.array(ana) - np.array([1]*(len(ana)))
# print(ana)
count = 0
for i in ana:
    if i >= 2:
        count += combinations_count(i,2)

print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [input() for i in range(N)]
from collections import defaultdict
encodes = [hash(tuple(sorted(list(s)))) for s in S]
hash_table = defaultdict(int)
for encode in encodes:
  hash_table[encode] += 1
import math
c_list = [int(math.factorial(v)/math.factorial(2)) for v in hash_table.values()]
count = sum(c_list)
print(count)

Submission status: Runtime Error

Solution code:
def main(text):
    n = int(input())
    a = [input() for i in range(n)]
    #a = text.split("\n")[1:]
    num = 0
    for i in range(len(a)):
        a[i] = "".join(sorted(a[i]))
    a.sort()
    i = 0
    while i < len(a):
        e = a[i]
        j = 1
        while i+j < len(a) and e == a[i+j]:
            j = j + 1
        if j != 1:
            num = num + combination(j)
            i = i+j
        else:
            i = i+1
    print(num)


def combination(x):
    return int(x*(x-1)/2)


main()

Submission status: Runtime Error

Solution code:
import collections
from math import factorial

n = int(input())
ls = []
for i in range(n):
    s = list(input())
    s = sorted(s)
    s = ''.join(s)
    ls.append(s)
c = collections.Counter(ls)
ans = 0
for i in range(len(c)):
    if c.most_common()[i][1] == 1:
        break
    a = factorial(c.most_common()[i][1]) / factorial(2) / factorial(c.most_common()[i][1] - 2)
    ans += a

print(round(ans))

Submission status: Runtime Error

Solution code:
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  s.sort()
  S.append(s)
S.sort()
cont=0
for i in range(n-1):
  t=1
  while S[i]==S[i+t]:
    cont+=1
    t+=1
print(cont)