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:
from __future__ import print_function
import argparse
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as anim
from tqdm import tqdm
from sklearn.datasets import fetch_openml
from sklearn.model_selection import train_test_split
import torch
from torch import nn,optim
from torch.utils.data import TensorDataset, DataLoader
from torchvision import datasets, transforms
import torch.backends.cudnn as cudnn


class View(nn.Module):
    def __init__(self, shape):
        super().__init__()
        self.shape = shape

    def forward(self, x):
        return x.view(*self.shape)

# I want this program to run on CUDA.
# However, runs without it. How come?

def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--no-cuda', action='store_true', default='False')
    args = parser.parse_args()

    use_cuda = (not args.no_cuda) and torch.cuda.is_available()
    print(args.no_cuda)
    print(torch.cuda.is_available())
    print(use_cuda)
    print(args)

    # idk why this line dosen't run correctly. tell me.
    #device = torch.device('cuda' if use_cuda else 'cpu')
    device = torch.device('cuda')
    print(device)

    ds_train = datasets.MNIST('../dataset', train=True, download=True,
                              transform=transforms.Compose([
                                  transforms.ToTensor(),
                                  transforms.Normalize((0.1307,), (0.3081,))
                              ]))
    
    ds_test = datasets.MNIST('../dataset', train=False,
                              transform=transforms.Compose([
                                  transforms.ToTensor(),
                                  transforms.Normalize((0.1307,), (0.3081,))
                              ]))
                                                           
    kwargs = {'num_workers': 4, 'pin_memory': True}
    train_loader = DataLoader(ds_train, batch_size=64, shuffle=True,  **kwargs)
    test_loader = DataLoader(ds_test, batch_size=64, shuffle=False, **kwargs)

    #disp_ds(ds_train, 10)

    model = nn.Sequential()
    model.add_module('view1', View((-1, 28*28)))
    model.add_module('fc1', nn.Linear(28*28*1, 100))
    model.add_module('relu1', nn.ReLU())
    model.add_module('fc2', nn.Linear(100, 100))
    model.add_module('relu2', nn.ReLU())
    model.add_module('fc3', nn.Linear(100, 10))
    model.to(device)

    #cudnn.benchmark = True
    
    loss_fn = nn.CrossEntropyLoss()
    optimizer = optim.Adam(model.parameters(), lr=1e-2)

    for epoch in tqdm(range(1, 11)):
        train(model, device, train_loader, loss_fn, optimizer, epoch)
        test(model, device, test_loader, loss_fn)

 
def get_mnsit():
    return fetch_openml('MNIST original', data_home='./datasets/')


def disp_ds(ds, num=None):
    if num is None: num = 100
    fig = plt.figure()

    ims = []
    for i in range(num):
        img = ds[i][0].numpy().reshape(28, 28)
        ims.append([plt.imshow(img)])

    animation = anim.ArtistAnimation(fig, ims, interval=100, repeat=False)
    plt.show()
    

def train(model, device, train_loader, loss_fn, optimizer, epoch):
    model.train()
    for data, target in tqdm(train_loader):
        data, target = data.to(device), target.to(device)
        optimizer.zero_grad()
        output = model(data)
        loss = loss_fn(output, target)
        loss.backward()
        optimizer.step()
    #print('epoch:{} Loss:{}'.format(epoch, loss))


def test(model, device, test_loader, loss_fn):
    model.eval()
    test_loss = 0
    correct = 0

    with torch.no_grad():
        for data, target in test_loader:
            data, target = data.to(device), target.to(device)
            output = model(data)
            #test_loss += loss_fn(output, target, reduction='sum').item()
            pred = output.argmax(dim=1, keepdim=True)
            correct += pred.eq(target.data.view_as(pred)).sum()
    #test_loss /= len(test_loader.dataset)
    print('accracy : {:.0f}%'.format(100. * correct / len(test_loader.dataset)))

'''
    print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
        test_loss, correct, len(test_loader.dataset),
        100. * correct / len(test_loader.dataset)))
'''


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import Counter
from collections import defaultdict
import math

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

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[s] += 1

for c in L.items():
    ans += combination(c, 2)
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
n = int(n)
total = 0
word = []

for i in range(n):
    word.append(input())

i = 0

while i <= len(word):   
    count = 0
    master = list(word[i])
    j = i + 1
    while j <= len(word):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while l < len(target):
                if master[k] == target[l]:
                    target.pop(l)
                else:
                    l += 1
        if len(target) == 0:
            word.pop(j)
            count += 1
        else:
            j += 1
    i += 1

    for a in range(count):
        total += a
print(total)

Submission status: Runtime Error

Solution code:
from math import factorial
N=int(input())
count=[0]
u=0
s=[sorted(input()) for i in range(N)]
s=sorted(s)
for t in range(N-1):
    if s[t+1]==s[t]:
        count[u]+=1
    else:
        count.append()
for i in range(u):
    a=factorial(u)/factorial(2)/factorial(u-2)
print(a)

Submission status: Runtime Error

Solution code:
N = int(input())
S = [sort(str(input())) for i in range(N)]

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

Submission status: Runtime Error

Solution code:
import math
import itertools

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

N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
ans = 0
for v in dicS.values():
	ans += combinations_count(v,2)
	
print(ans)

Submission status: Runtime Error

Solution code:
import fractions


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

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

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)

Submission status: Runtime Error

Solution code:
import collections

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

cnt=0

for i in range(N):
  if collections.Counter(S[0]) == collections.Counter(S[i+1]):
    cnt +=1

print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
n = int(raw_input())
li = list(map(int, input().split()))

for i in range(n):
    sl.append("".join(sorted(li[i])))

sl.sort()

c = collections.Counter(sl)

print(N - (len(c)-1))

Submission status: Runtime Error

Solution code:
n = input()
n = int(n)
total = 0
word = []

for i in range(n):
    word.append(input())

i = 0

while i <= len(word):   
    count = 0
    master = list(word[i])
    j = i + 1
    while j <= len(word):
        target = list(word[j])
        for k in range(len(master)):
            l = 0
            while l < len(target):
                if master[k] == target[l]:
                    target.pop(l)
                else:
                    l += 1
        if len(target) == 0:
            word.pop(j)
            count += 1
        else:
            j += 1
    i += 1
    if count != 0:
    	total += 1
    for a in range(count):
        total += a
print(total)

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:
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())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = cmb(aas,2)
        ans += int(abs)
print(ans)

Submission status: Runtime Error

Solution code:
from collections import Counter
from collections import defaultdict
import math

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

N = int(input())
L = defaultdict(int)
ans = 0
for _ in range(N):
    s = sorted(list(input()))
    L[s] += 1

for c in L.items():
    ans += combination(c)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
lst = []
count = 0
st = []

for i in range(N):
  if i==0:
    in_pu = input()
    l = list(in_pu)
    lst.append(in_pu)
    st.append(set(l))
    continue
    
  in_pu = input()
  l = list(in_pu)
  lst.append(list(in_pu))
  
  if set(l) in st:
    count = count + 1 
print(count+len(list(set(lst))))

Submission status: Runtime Error

Solution code:
import collections
from scipy.special import comb

n = int(input())
string_list=[input() for i in range(n)]
result = 0
for i in range(n):
    counter = 0
    for j in range(n):
#         print(string_list[i])
        if collections.Counter(string_list[i]) == collections.Counter(string_list[j]) and string_list[j]!=' ' and i != j:
            counter +=1
            string_list[j] = ' '
            
    counter  = comb(counter, 2, exact=True)
    result += counter 
    
print(int(result))

Submission status: Runtime Error

Solution code:
#1)文字列のリスト化
#2)文字列を一文字ずつ分ける→文字列を並べ替える→文字列をまたリストに格納する
#3)アナグラム判定
##ラストの但し書きがわからない

#n C 2関数
def for_factorial(n):
    val = 1
    for i in range(2, n + 1):
        val *= i
    return int(val/2)
N = int(input())
l = []
_l = [] #並び替えた文字列の格納
_c = 0 #カウントの総合
#1)リストの作成
for i in range(N):
    l.append(input())
#2)文字列の並び替えを"_l"に格納
for s in l:
    one_l = [c for c in s]
    one_l.sort()
    _one_l = "".join(one_l)
    _l.append(_one_l)
#3)アナグラム判定
for s in _l[:]:
    c = _l.count(s)
    if c > 1:
        #cの組み合わせを考える c C 2
        for_factorial(c)
        _c += c
        _l.remove(s)
print(_c)

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):
        a *= i
    return int(a / 2)
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
N=int(input())
count=[0]
u=0
s=[sorted(input()) for i in range(N)]
s=sorted(s)
for t in range(N-1):
    if s[t+1]==s[t]:
        count[u]+=1
    else:
        u.append(0)
for i in range(u):
    a=factorial(u)/factorial(2)/factorial(u-2)
print(a)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    count = 0
    lists =[]
    count_dict = {}

    for i in range(n):
        input_data = ''.join(sorted(input()))
        if input_data in lists:
            if input_data not in count_dict.keys():
                count_dict[input_data] = 1
        
            count_dict[input_data] += 1
        else:
            lists.append(input_data)

    count = sum(
        v for v in d.values()
    )

    print(count)


if __name__ == '__main__' :
    main()

Submission status: Runtime Error

Solution code:
import sys

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

for j in range(n):
    ll=list(l[j])
    ll.sort()
    aa="".join(ll)
    tmp2=0
    for z in range(len(res)):
        if aa==res[z]:
            tmp2+=res2[z]
            res2[z]+=1
    if tmp2==0:
        res.append(aa)
        res2.append(1)
    ans+=tmp2

print(int(ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(raw_input())
li = list(map(int, input().split()))

for i in range(n):
    sl.append("".join(sorted(list[i])))

sl.sort()

c = collections.Counter(sl)

print(N - (len(c)-1))

Submission status: Runtime Error

Solution code:
from collections import Counter as ct

N = int(input())
k = []
a = 0

for i in range(N):
    s = list(input().split())

for i in range(N - 1):
    for j in range(i + 1, N):
        if ct(s[i]) == ct(s[j]):
            a += 1

print(a)

Submission status: Runtime Error

Solution code:
from math import factorial
def conb(n):
    if n == 1:
        return 0
    else:
        return factorial(n) / factorial(2) / factorial(n - 2)


n = int(input())
l = [input() for _ in range(n)]
mst = set((list("".join(l))))
l = ["".join(map(str, [x.count(a) for a in mst])) for x in l]
l_s = set(l)
result = 0
for s in l_s:
    result += int(conb(l.count(s)))
print(result)

Submission status: Runtime Error

Solution code:
N = int(input())
L = [list(map(str, input().split())) for i in range(N)]

from collections import Counter
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.replace(' ', ''))
    if get_counter(first_word) == get_counter(second_word):
        return True
    else:
        return False

cnt=0
for i in range(N):
    for k in range(N):
        if k+1>len(L):
            continue
        if verify_anagrams(L[i],L[k+1]):
            cnt+=1

print(num)

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys
input = sys.stdin.readline
n = int(input())
str_list = [input() for i in range(n)]
counter_list = [Counter[i] for i in str_list]
ans = 0
for i in range(n):
  first = Counter(str_list[i])
  for j in range(n-i-1):
    second = Counter(str_list[j+i+1])
    if first == second:
      ans +=1
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[input() for j in range(n)]
for i in range(n)[:-1]:
	f=l[i]
	for s in range(n)[i+1:]:
		a=[f[k] for k in range(10)]
        g=l[s]
        b=[g[c] for c in range(10)]
        q +=1 if sorted(a)==sorted(b)
print(q)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
n = int(raw_input())
li = list(map(int, input().split()))

for i in range(N):
    sl.append("".join(sorted(list[i])))

sl.sort()

c = collections.Counter(sl)

print(N - (len(c)-1))

Submission status: Runtime Error

Solution code:
import itertools
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return len(result)


#n=int(input())
#a=[list(input()) for i in range(n)]
count=0
a=list(itertools.permutations(a))
for i in range(len(a[1])):
    if list_difference(a[i][0],a[i][1])==0:
        count+=1
print(count)

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)/2
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)
    
def kaijyo(n):
    ans=1
    for i in range(1,n+1):
        ans*=i
    return ans

count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    count+=kaijyo(times)*kaijyo(times-2)/2
    
print(int(count) )

Submission status: Runtime Error

Solution code:
from collections import Counter
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(input()) for _ in range(N)]
for i in range(N):
    s[i].sort()
    s[i]=''.join(s[i])

s.sort()

ans_tmp = 0
ans = 0
for i in range(N-1):
    if(i == N-2):
        if(s[i]== s[i+1]):
            ans_tmp += 1
        ans+= cmb(ans_tmp+1, 2)
    if(s[i]== s[i+1]):
        ans_tmp += 1
    elif(ans_tmp>=1):
        ans+= cmb(ans_tmp+1, 2)
        ans_tmp=0


print(ans)

Submission status: Runtime Error

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

def P(n, r):
    return fact(n)//fact(n-r)

def C(n, r):
    return P(n, r)//fact(r)

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
ls = []
l = [0 for i in range(n)]
for i in range(n):
  ls.append(input())
for i in range(n):
  for j in range(10):
    alpha = ord(ls[i][j]) - ord("a")
    l[i]+=10**alfa
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: Runtime Error

Solution code:
Y = list(input())
N = len(Y)-1
S = [0] * N
S=list[1: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:
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
f = 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
        for k in range(tans):
            f = f * (k+1)
        ans = ans + int(f/2)
        tans=1

print(ans)

Submission status: Runtime Error

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


def is_anagram(s_i, s_j):
    for k in range(10):
        found = False
        for l in range(10):
            if s_i[k] == s_j[l]:
                found = True
                break
        if not found:
            return False
    return True


num = 0
for i in range(n):
    for j in range(i + 1, n):
        if i == j:
            continue
        if is_anagram(s[i], s[j]):
            num += 1
            records[i].append(j)
print(num)

Submission status: Runtime Error

Solution code:
from math import factorial
N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
ns = []
ans = 0
for i in range(len(s)):
    if ns.count(s[i]) == 0:
        aas = s.count(s[i])
        if aas > 0:
            ns.append(s[i])
        abs = int(factorial(aas) / factorial(2) / factorial(aas - 2 ))
        ans += abs
print(ans)

Submission status: Runtime Error

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

## a-zの文字が各文字列でそれぞれ何度出てくるか数える
## 26要素を持つリストが複数できて、リストの中身の完全一致回数を求める

AtoZlist = [chr(i) for i in range(97,97+26)]
countlist = []
for l in range(N):
    countlist.append([])

for i in AtoZlist:
    for k in S:
        ci = k.count(i)
        countk = S.index(k)
        countlist[countk].append(ci)
    for x in range(N):
        xcount = 0
        for y in range(N):
            if countlist[x] == countlist[y]:
                xcount += 1
        if xcount == 1:
            del S[x]
            del countlist[x]
            N -= 1


answer = 0
for x in range(N):
    for y in range(x+1,N):
        if countlist[x] == countlist[y]:
            answer += 1
print(answer)

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
array = list()
for i in range(0, N):
    str = input()
    array.append(str)
count = 0
for i in range(0, N-1):
    for j in range(i+1, N):
        if Counter(array[i]) == Counter(array[j]):
	    array[j] = " "
  	    count = count + 1
print(count)

Submission status: Runtime Error

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

dic = {}
for i in range(N):
    temp = {}
    for j in range(10):
        if A[i][j] in temp:
            temp[A[i][j]] += 1
        else:
            temp[A[i][j]] = 1
    if dic in temp:
        dic[temp] += 1
    else:
        dic[temp] = 1
        
ans = 0    
for key in dic:
    if dic[key] > 1:
        ans += (dic[key]*(dic[key]-1)//2)

print(ans)

Submission status: Runtime Error

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

import collections
counters = []
count = 0
for text in texts:
    text_list = list(text)
    text_list.sort()
    text = "".join(text_list) 
    c = collections.Counter(text)
    counters.append(c)



ccccc = []
anss = 0
for ccc in counters:
    ccc = str(ccc)
    ccccc.append(ccc)
    

dd = collections.Counter(ccccc)
for v in dd.values():
    ans = v * (v-1) / 2
    anss.append(ans)
    
print(int(sum(anss)))

Submission status: Runtime Error

Solution code:
# -*- config: utg-8 -*-

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

sort_list = []

for i in s:
	str_sort_list = sorted(i)
	new_str = ''.join(str_sort_list)
	sort_list.append(new_str)

count = 0
for i in sort_list:
  hoge = sort_list.pop(0)
  chohuku_count = sort_list.count(hoge)
  sort_list.remove(hoge)
  
  sum = 0
  for i in range(chohuku_count+1):
    sum += i
  count += sum
  

print(count)

Submission status: Runtime Error

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

N=int(input())
s=[input() for i in range(N)]
a=0
b=N-1
for i in range(b):
    c=N-i-1
    t=s[i]
    u=list(s[i])
    u.sort()
    for j in range(c):
        v=s[i+j+1]
        w=list(v)
        w.sort()
        for k in range(11):
            if u[k]!=w[k]:
                break
            else:
                if k<10:
                    continue
                else:
                    a=a+1
print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
l=list()
q=0
for k in range(n):
	st=input()
    l.append(st)
for i in range(n)[:-1]:
	f=l[i]
	for s in range(n)[i+1:]:
		a=[f[k] for k in range(10)]
        g=l[s]
        b=[g[c] for c in range(10)]
        q +=1 if sorted(a)==sorted(b)
print(q)

Submission status: Runtime Error

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

    td = {}
    for _ in range(N):
        str = [ci for ci in input()]
        str.sort()
        t = ''.join(str)
        if t not in td.keys():
            td[t] = 0
        else:
            if td[t] == 0:
                td[t] = 1
            else:
                td[t] += td[t] * 2
    count = 0
    for v in td.values():
        count += v
    print(count)


m

Submission status: Runtime Error

Solution code:
import itertools
def list_difference(list1, list2):
    result = list1.copy()
    for value in list2:
        if value in result:
            result.remove(value)

    return len(result)


n=int(input())
a=[list(input()) for i in range(n)]
count=0
a=list(itertools.permutations(a))
for i in len(a):
    if list_difference(a[i][0],a[i][1])==0:
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
# -*- config: utg-8 -*-

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

sort_list = []

for i in s:
	str_sort_list = sorted(i)
	new_str = ''.join(str_sort_list)
	sort_list.append(new_str)

count = 0
for i in sort_list:
  hoge = sort_list.pop(0)
  chohuku_count = sort_list.count(hoge)
  sort_list.remove(hoge)
  
  sum = 0
  for i in range(chohuku_count+1):
    sum += i
  count += chohuku_count
  

print(count)

Submission status: Runtime Error

Solution code:
n=input()
l=list()
q=0
for k in range(n):
	st=input()
    l.append(st)
for i in range(n)[:-1]:
	f=l[i]
	for s in range(n)[i+1:]:
		a=[f[k] for k in range(10)]
        g=l[s]
        b=[g[c] for c in range(10)]
        q +=1 if sorted(a)==sorted(b)
print(q)

Submission status: Runtime Error

Solution code:
from collections import Counter

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()
    if(snum==1):
        num = num + 1
    else:
        num = num + int(snum*(snum+1)/2)

    for r in rem:
        s.pop(r)
    rem.clear()
print(num)

Submission status: Runtime Error

Solution code:
import numpy as np

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

#辞書を準備
alpha_dict = {}
for i,c in enumerate(range(ord('a'),ord('z')+1)):
    alpha_dict[chr(c)] = i
    
result = []
for words in s:
    result_list = np.zeros(26,dtype=int)
     for i in range(words):
        result_list[alpha_dict[i]] +=1
    result.append(result_list)
result_2 = set(list(map(tuple,result)))
final_result = len(result) - len(result_2) 
print(final_result)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for nn in range(n):
    sraw.append(sorted(input().encode()))

ans = 0

#s = np.sort(np.array(sraw), axis=0).tolist()
s = sorted(sraw)
#print(s)

l = len(s)

for ss in range(0, l):
    fl = 0
    #print("")
    for sss in range(ss+1, l):
        #print("{0} {1}".format(s[ss],s[sss]))
        if s[ss] == s[sss]:
            ans += 1
            fl = 1

        elif fl == 1:

            break


print(ans)

Submission status: Runtime Error

Solution code:
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())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) for v in str_dict.values() if v >= 2 else 0]))

Submission status: Runtime Error

Solution code:
n=int(input())
wordlist=[input() for i in range(n)]
sortlist=[]
for i in range(n):
    a=list(wordlist[i])
    a.sort()
    a="".join(a)
    sortlist.append(a)
    
def kaijyo(n):
    ans=1
    for i in range(2,n+1):
        ans*=i
    return ans

count=0
sortlist.sort()


while sortlist:
    a=sortlist.pop()
    times=sortlist.count(a)+1
    for i in range(times-1):
        sortlist.pop()
    count+=kaijyo(times)*kaijyo(times-2)/2
    
print(int(count/2) )

Submission status: Runtime Error

Solution code:
N = int(input())
lst = []
count = 0
st = []

for i in range(N):
  if i==0:
  	in_pu = input()
  	l = list(in_pu)
  	lst.append(list(input()))
    st.append(set(l))
    continue
    
  in_pu = input()
  l = list(in_pu)
  lst.append(list(input()))
  
  if set(l) in st:
    count = count + 1
print(count)

Submission status: Runtime Error

Solution code:
import math


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

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

n = int(input())
str_list = []
for i in range(n):
    str_list.append(list(sorted(input())))
str_list=sorted(str_list)
str_list.append("a")

ans=0
cnt=0
for i in range(n):
    if str_list[i]==str_list[i+1]:
        cnt+=1
    else:
        if cnt==1:
            ans+=1
            cnt = 0
        else:
            ans+=C(cnt+1,2)
            cnt=0

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

N = input()
str = []
for i in range(int(N)):
    str.append(input())

ans = 0

for i in range(len(str)-1):
    list1 = list(set(list(str[i])))
    for j in range(i+1,len(str)):
        list2 = list(set(list(str[j])))
        
        count = 0
        for k in range(len(list1)):
            if list1[k] == list2[k]:
                count = count + 1
            else:
                break
            
        if count == len(list1):
            ans = ans + 1
        
print(ans)

Submission status: Runtime Error

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

n = int(input())
ss = [sorted(stdin.readline()) for i in range(n)]
ss.sort()

tmp = ss[0]
cnt = 0
ans = 0
for i in range(n):
    if tmp == ss[i]: cnt+=1
    else:
        tmp = ss[i]
        ans += comb(cnt, 2)
        cnt=1
print(int(ans+comb(cnt,2)))

Submission status: Runtime Error

Solution code:
from math import factorial

N = int(input())
s = {}
h = {'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}
for i in range(N):
    total = 1
    chs = list(input())
    for j in range(10):
        total *= h[chs[j]]
    s[total] = s.get(total, 0) + 1

cnt = 0
for v in s.values():
    if v < 2: continue
    a = factorial(v) / factorial(2) / factorial(v - 2)
    cnt += a

print(int(cnt))

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()
S.append(a)
cont=0
for i in range(n-1):
  t=1
  while S[i]==S[i+t]:
    cont+=1
    t+=1
print(cont)

Submission status: Runtime Error

Solution code:
n = int(input())
s = ["".join(sorted([j for j in input()])) for i in range(n)]
s.sort()
count = 0
key = s[0]
sum = 0
def saiki(a):
    if a == 0:
        return 0

    return a + saiki(a-1)

for i in s:
    if key == i:
        count += 1
    else:
        sum += saiki(count-1)
        key = i
        count = 1
sum += saiki(count-1)
print(sum)