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:
import sys
from collections import Counter
from math import factorial
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = np.int64(0)
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          ans += np.int64(np.int64(factorial(n)) / np.int64(factorial(r)) / np.int64(factorial(n - r)))
          #ans +=  scipy.special.comb(n, r, exact=True)
    print(ans)
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e30)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N = i_inpl()
    s = defaultdict(int)
    for _ in range(N):
        si = tuple(sorted(input()))
        s[si] += 1

    from functools import lru_cache

    @lru_cache(maxsize=1000)
    def c(n,k): 
        return 1 if(k<=0 or n<=k) else ( c(n-1, k-1) + c(n-1, k) ) %4

    ans = 0
    for i in s.values():
        if i == 1:
            continue
        ans += c(i, 2)
    
    print(int(ans))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
import collections
import math

l = int(input())
st = []
for i in range(l):
    x = ''.join(sorted(input()))
    st.append(x)
c = collections.Counter(st)
cv = c.values()
sum = 0
for i in cv:
    if int(i) > 1:
        sum = sum + math.factorial(int(i))/2

print(math.floor(sum))

Submission status: Runtime Error

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
import pandas as pd
import math

print(sum([math.factorial(i-1) for i in pd.DataFrame(anagrams, columns=["word"]).groupby("word")["word"].count().values]))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())

str_array = [input() for i in range(N)]
  
alpha2num = lambda c: ord(c) - ord('a') + 1

array=np.zeros((N,26))

for i,sent in enumerate(str_array):
  for char in sent:
    array[i,alpha2num(char)]+=1
    
print(N-np.linalg.matrix_rank(array))

Submission status: Runtime Error

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return a

def lcm(a, b): #最小公倍数
  return a * b // gcd (a, b)

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#input stock
"""
n = int(input())

#list
a = map(int, input().split())
a,b = map(int, input().split())

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

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""

def strnum(st):
  st = list(st)
  for i in range(len(st)):
    tmp = st[i] + str(st[i:].count(st[i]))
    st[i] = str(tmp)
  return st

def strsort(st):
  st = list(st)
  st = sorted(st)
  return "".join(st)

def kai(num):
  if num==1:
    return 1
  else:
  	return num * kai(num-1)

def choose(num):
  return int(kai(num)/2)
  
import collections
#######################################
n = int(input())
s = [""]*n
for i in range(n):
  s[i] = strsort(input())

#s = sorted(s)
c = collections.Counter(s)
count=0
for k,v in c.items():
  count += choose(v)

print(count)

Submission status: Runtime Error

Solution code:
n = int(stdin.readline().rstrip())
a= [stdin.readline().rstrip() for _ in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if intersect_list(a[i],a[j])==len(col):
            count+=1
print(count)

Submission status: Runtime Error

Solution code:
import pandas as pd
N = int(input())
hoge = list(input())
"df = pd.DataFrame([], columns=["words"])
print(hoge)

Submission status: Runtime Error

Solution code:
from math import factorial

N = int(input())
ss = []
for i in range(1,N+1):
  ss.append(input())

sorted_ss     = []
sorted_ss_uni = []
for s in ss:
  sorted_s = []
  for char in s:
    sorted_s.append(char)
  sorted_s.sort()
  sorted_ss.append(sorted_s)
  if sorted_s not in sorted_ss_uni:
    sorted_ss_uni.append(sorted_s)
    
n_anagrams = 0
for sorted_s_uni in sorted_ss_uni:
  nana     = sorted_ss.count(sorted_s_uni)
  if nana > 1:
    nanapair = factorial(nana) / factorial(2) / factorial(nana - 2)
    n_anagrams += nanapair

print(int(n_anagrams))

Submission status: Runtime Error

Solution code:
n = int(input())
anagrams = ["".join(sorted(input())) for i in range(n)]
print(sum([math.factorial(i-1) for i in pd.DataFrame(anagrams, columns=["word"]).groupby("word")["word"].count().values]))

Submission status: Runtime Error

Solution code:
from math import factorial
import collections

n = int(input())

ss = []
for i in range(n):
	s = list(input())
	s.sort()
	ss.append("".join(s))

cs = collections.Counter(ss)
l = list(cs.values())
l.sort(reverse=True)

c = 0
for i in l:
	if i == 1:
		print(int(c))
		exit()
	else:
		a = factorial(i) / factorial(2) / factorial(i - 2)
		c+=a
print(int(c))

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:
        ans += comb(temp,2)
        pre = d
        temp = 1

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

Submission status: Runtime Error

Solution code:
# coding: utf-8
import sys
import collections

# import bisect
# import math
# import numpy as np
# from fractions import gcd

"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)

    def lcm(self, x, y):
        return (x * y) // self.gcd(x, y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    s = [input() for _ in range(n)]
    ans = []
    for x in s:
        memo = collections.Counter(x)
        ans.append(s)
    # print(ans)
    # print(set(ans))
    print(int((len(ans) - len(list(set(ans))) / 2)))


main()

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
import itertools

N = int(input())

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

check = np.zeros((N, N))


for i in range(N):
    c = []
    x = collections.Counter(moji[i])

    c.append(i)

    for j in range(i + 1, N):
        if check[i, j] == 1:
            continue

        y = collections.Counter(moji[j])

        if x == y:
            c.append(j)

    for v in itertools.combinations(c, 2):
        check[v] = 1

print(int(np.sum(check)))

Submission status: Runtime Error

Solution code:
_, *S=open(0).read().split()
a={}
for s in S:
    x = sum([ord(c) for c in s])
    if x in a:
        a[x] += 1
    else:
        a[x] = 1
import math

def z(x):
    if x==1:
        return 0
    if x==2:
        return 1
    if x==3:
        return 3
    return (x - 1) * a(x-1)
print(sum(map(z, a.values())))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
#import copy

n = int(input())

#l = [i for i in range(n)]

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

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

print(count)

Submission status: Runtime Error

Solution code:
n = int(stdin.readline().rstrip())
a= [stdin.readline().rstrip().split() for _ in range(n)]
count=0
for i in range(len(a)):
    for j in range(i+1,len(a)):
        if intersect_list(a[i],a[j])==len(col):
            count+=1
print(count)

Submission status: Runtime Error

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

dic=[]

for i,s in enumerate(S):
    dic.append({})
    for x in s:
        try:
            dic[i][x]=+dic[i][x]+1
        except:
            dic[i][x]=1
    #dic[i].sort()

cnt=0
for i in range(len(dic)):
    for j in range(i+1,len(dic)):
        if dic[i]==dic[j]:
            cnt+=1

print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
X =[]
for i in range(N):
    Y =list(input())
    Y.sort()
    X.append(Y)
    X.sort()
    
ans = 0
count = 1 
for i in range(N-1):
    if X[i] == X[i+1]:
        count += 1
    else:
        if count != 1:
            Z = 1/2
            for i in range(1,count+1):
                Z = Z * i
            ans = ans + Z
            count = 1

if count != 1:
    Z = 1/2
    for i in range(1,count+1):
        Z = Z * i
    ans = ans + Z
        
print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
from math import factorial
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = np.int64(0)
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          ans += np.int64(factorial(n) / factorial(r) / factorial(n - r))
          #ans +=  scipy.special.comb(n, r, exact=True)
    print(ans)
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n=int(input())

l=[]
for _ in range(n):
  a=soretd([i for i in str(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])

print(sum(ans))

Submission status: Runtime Error

Solution code:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    String[] s = new String[n];
    for(int i = 0;i<n;i++){
      s[i] = in.next();
    }
    int ans = 0;
    for(int i = 0;i<n;i++){
      for(int j = i+1;j<n;j++){
        int xor = 0;
        for(int k = 0;k<10;k++){
          xor = xor ^ (int)s[i].charAt(k);
          xor = xor ^ (int)s[j].charAt(k);
        }
        if(xor==0){
          ans++;
        }
      }
    }
    System.out.println(ans);
  }
}

Submission status: Runtime Error

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

res = []
for i in l:
    li = list(i)
    li.sort()
    res.append(''.join(li))

a = list(set(res))
t = 0
for i in a:
    t += res.count(i) - 1

print(t)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [sorted(list(input())) for i in range(N)]
b = set(a)
ans = len(a) - len(b)
print(ans)

Submission status: Runtime Error

Solution code:
A = []
B = []
N = int(input())

for i in range(N):
	t = input()
	t = sorted(t)
	
	flag = True
	for i in range(len(A)):
		if A[i] == t:
			B[i] += 1
			flag = False
			break
	
	if flag:
		A.append(t)
		B.append(1)
		
ans = 0
for b in B:
	if b==2:
		ans += 1
	elif b!=1:
		t = 1
		for i in range(2,b+1):
			t*=i
		ans += int(t/2)
		
print(ans)

Submission status: Runtime Error

Solution code:
for _ in range(n):
  si = str(input())
  di = {}
  for i in range(10):
    if si[i] in di.keys():
      di[si[i]] += 1
    else:
      di[si[i]] = 1
  frag = True
  for j,st in enumerate(li[0]):
    if di == st:
      li[1][j] += 1
      frag = False
  if frag:
    li[0].append(di)
    li[1].append(1)
sm = 0
for j in li[1]:
  sm += j*(j-1)//2
print(sm)

Submission status: Runtime Error

Solution code:
from scipy.special import comb
n = int(input())
s = []
ans = 0
for i in range(n):
    sn = input()
    sn = sorted(sn)
    sn = ''.join(sn)
    s.append(sn)
str_set = set(s)
for i in str_set:
    n = s.count(i)
    if n > 1:
        ans += comb(n, 2, exact=True)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
a = [sorted(list(input())) for i in range(N)]
b = set(a)
print(len(a) - len(b))

Submission status: Runtime Error

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

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
for i in range(n):
    for j in range(n-i-1):
        if lss[i] == lss[j]:
            ans+=1

print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from collections import Counter
from math import factorial
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = 0
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          ans += factorial(n) / factorial(r) / factorial(n - r)
          #ans +=  scipy.special.comb(n, r, exact=True)
    print(np.int64(ans))
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

def get_sum(num):
    return num*(num-1)/2


N = int(input())
S = []
D = defaultdict(int)
ans = 0
for _ in range(N):
    inp = input()
    inp.sort()
    s = str(inp)
    D[s] += 1

for k, v in D.items():
    ans += get_sum(v)


print(int(ans))

Submission status: Runtime Error

Solution code:
from math import factorial
import collections

n = int(input())

ss = []
for i in range(n):
	s = list(input())
	s.sort()
	ss.append("".join(s))

cs = collections.Counter(ss)
l = list(cs.values())

c = 0
for i in l:
	if i == 1:
		print(int(c))
		exit()
	else:
		a = factorial(i) / factorial(2) / factorial(i - 2)
		c+=a
print(int(c))

Submission status: Runtime Error

Solution code:
#import sys
import math

def nCr(n,r):
    f = math.factorial
    return int(f(n) / f(r) / f(n-r))

N = int(input())
#A, B = list(map(int,input().split()))
S = [''.join(sorted(input())) for _ in range(N)]
D = {}
for s in S :
    if s in D :
        D[s] += 1
    else :
        D[s] = 1
V = list(D.values())
count = 0
for v in V :
    if v == 1 :
        count += 0
    elif v == 2 :
        count += 1
    elif v >= 3 :
        count += nCr(v,2)
print(count)

Submission status: Runtime Error

Solution code:
import collections
import numpy as np
# import math
import itertools

N = int(input())

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

check = np.zeros((N, N))


for i in range(N):
    c = []
    x = collections.Counter(moji[i])

    c.append(i)

    for j in range(i + 1, N):
        if check[i, j] == 1:
            continue

        y = collections.Counter(moji[j])

        if x == y:
            c.append(j)

    for v in itertools.combinations(c, 2):
        check[v] = 1

# print(check)
print(int(np.sum(check)))

Submission status: Runtime Error

Solution code:
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

from math import factorial

if __name__ == "__main__":
    N = int(sys.stdin.readline())
    #mng = [][]
    sl = []
    for _ in range(N):
        sl.append(sorted(sys.stdin.readline().rstrip()))

    ans = 0
    while True:
        if sl == []:
            break
        e = sl[0]
        cnt = sl.count(e)
        if cnt > 1:
            n = cnt
            r = 2
            ans += factorial(n) / factorial(r) / factorial(n - r)
        sl = [x for x in sl if x != e]

    print(int(ans))

    """
    sl = []
    mng = []
    for _ in range(N):
        s = set(sys.stdin.readline().rstrip())
        if s in sl:
            i = sl.index(s)
            mng[i] += 1
        else:
            sl.append(s)
            mng.append(0)

    ans = 0
    r = 2
    #print(mng)
    for n in mng:
        if n > 0:
            n += 1
            ans += factorial(n) / factorial(r) / factorial(n - r)

    print(int(ans))
    """

Submission status: Runtime Error

Solution code:
num = int(input())
data = []
for _ in range(num):
    tmp = input()
    data.append(tmp.sort())
data = data.sort()
count = 0
for i in range(num):
    tmp = data[i]
    for j in range(i+1,num):
        if tmp == data[j]:
            count+=1
        else:
            break
print(count)

Submission status: Runtime Error

Solution code:
from collections import Counter
import math
n = int(input())
s = list(map(lambda x: ''.join(sorted(x)) ,[list(input()) for i in range(n)]))
ans = 0
for i in Counter(s).values():
    ans += int(math.factorial(i) / 2)
print(ans)

Submission status: Runtime Error

Solution code:
def sumsun(n):
  ret = 0
  for i in range(n,0,-1):
    ret = ret + i
    
  return ret

N = int(input())
hoge = input().split()
s = []
for i in range(N):
  s.append("".join(sorted(hoge[i])))

ans = 0
itr = 0
while(1==1):
  fin = len(s) 
  if fin == 0:
    break
  is_google = s[itr]
  indexes = [i for i, x in enumerate(s) if x == is_google]
  ans = ans + sumsun(len(indexes)-1)
  while indexes:
    s.pop(indexes.pop())
  
print(ans)

Submission status: Runtime Error

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

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(cnt)
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
import math
n = int(input())
h = {}
for _ in range(n):
    s = list(input().strip())
    s.sort()
    s = ''.join(s)
    if h.get(s) is None:
        h[s] = 1
    else:
        h[s] += 1


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


count = 0
for k, v in h.items():
    count += combinations_count(v, 2)

print(count)

Submission status: Runtime Error

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

  d = {}
  tmp = []
  for i in range(N):
    s = input()
    x = sorted(s)
    if x in tmp:
      d[tmp.index(x)] += 1
    else:
      d[i] = 1 
      tmp.append(x)
  cnt = 0
  for k, v in d.items():
    if v == 1:
      continue
    if v == 2:
      cnt += 1
    elif v == 3:
      cnt += v
    else:
      cnt += sum(list(range(1,v)))

  print(d)
  print(cnt)
if __name__ == "__main__":
  main()

Submission status: Runtime Error

Solution code:
from collections import Counter
N = int(input())
S = [input() for _ in range(N)]
from math import factorial
chars = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
result = []
for n in range(N):
    res = {}
    for char in chars:
        res[char] = S[n].count(char)
    result.append(res)
result2 = Counter([str(i) for i in result ])
cnt = 0
for key in result2.keys():
    if result2[key] == 1:
        pass
    else:
        comb = factorial(result2[key]) / factorial(2) / factorial(result2[key] - 2)
        cnt += comb
print(int(cnt))

Submission status: Runtime Error

Solution code:
from math import factorial
n = int(input())
s = []
#10**5
for i in range(n):
    s.append(input())
count = 0
#10*5
for i in range(n):
    s[i] = ''.join(sorted(s[i]))
set_s = set(s)
if len(set_s) != len(s):
    for i in set_s:
        if s.count(i) >= 2:
            count += int(factorial(s.count(i)) / factorial(2) / factorial(s.count(i) - 2))
print(count)

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+=int(kaijyo(times)*kaijyo(times-2)/2)
    
print(count)

Submission status: Runtime Error

Solution code:
n=int(input())

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

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

print(sum(ans))

Submission status: Runtime Error

Solution code:

    N = int(input())
    s = [sorted([x for x in input()]) for i in range(N)]
     
    check = [False] * N
    cnt = 0
    for i in range(N - 1):
        part = 0
        if check[i]:
            continue
        for j in range(i + 1, N):
            if check[j]:
                continue
            if s[i] == s[j]:
                part += 1
                check[j] = True
        cnt += (part + 1) * part // 2
     
    print(cnt)

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(100000000)
N = int(input())
ll = []

for i in range(N):
    l = list(input())
    l.sort()
    s = ''.join(l)
    ll.append(s)
ll.sort()
k = 0
ans = 0
for j in range(N-1):
    if ll[j]==ll[j+1]:
        k += 1
    elif k>0:
        ans += math.factorial(k+1)/math.factorial(2)/math.factorial(k+1-2)
        k = 0
if k>0:
    ans += math.factorial(k+1)/math.factorial(2)/math.factorial(k+1-2)
print(int(ans))

Submission status: Runtime Error

Solution code:
import collections
N = int(input())
s = []
for i in range(N):
    ss = input()
    s.append(ss)
t= []
for i in range(N):
    tt= sorted(s[i])
    t.append(tt)
#s.sort()
#print(t)

count = 0
for i in range(N):
    a = tt.count(tt[i])
    count = count+a
print(count-N)

Submission status: Runtime Error

Solution code:
コード 

Copy
Copy
from collections import Counter
 
N=int(input())
s=[input() for _ in range(N)]
 
def anagrams(word1,word2):
    def get_counter(s):
        return Counter(s)
    return get_counter(word1)==get_counter(word2)
 
num=0
for i in range(N):
    for j in range(i+1,N):
        if anagrams(s[i],s[j]):
            num+=1
 
print(num)

Submission status: Runtime Error

Solution code:
import my_method as my


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

check = [False] * N
cnt = 0
for i in range(N - 1):
    part = 0
    if check[i]:
        continue
    for j in range(i + 1, N):
        if check[j]:
            continue
        if s[i] == s[j]:
            part += 1
            check[j] = True
    cnt += (part + 1) * part // 2

print(cnt)