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: Wrong Answer

Solution code:
import sys
p = [r for r in sys.stdin.read().split('\n') if r != '']
n = int(p[0])
s = p[1:]
for i, r in enumerate(s):
    t = list(r)
    t.sort()
    s[i] = ''.join(t)
d = {}
for i in s:
    if i in d:
        d[i] += 1
    else:
        d[i] = 0
count = 0
for k, v in d.items():
    print(k, v)
    count += int((v + 1) * v / 2)
print(count)

Submission status: Wrong Answer

Solution code:



def isAnagram(s, ss):
	i = 0
	while ss != "" and i < len(s):
		ss = ss.replace(str(s[i]), "")
		i += 1
	if ss == "":
		return 1
	else:
		return 0

#print(isAnagram("abaaaaaaaa", "aaaaaaaaba"))
c = int(input())

strings = []
for i in range(c):
	strings.append(input())

count = 0
for i in range(c):
	for j in range(i+1, c):
		count += isAnagram(strings[i], strings[j])

print(count)

Submission status: Wrong Answer

Solution code:
num = int(input())
tmp = []
for i in range(num):
  tmp.append(''.join(sorted(input())))

tmp = sorted(tmp)
ans = 1
x = [i for i in set(tmp) if tmp.count(i)>1]
print(len(x))

Submission status: Wrong Answer

Solution code:
N=int(input())
S=[]
T=[]
for i in range(N):
	s=str(input())
	S.append(s)
for j in range(N):
	X=sorted(str(S[j])[k] for k in range(10))
	Y=X[0]+X[1]+X[2]+X[3]+X[4]+X[5]+X[6]+X[7]+X[8]+X[9]
	T.append(Y)
R=sorted(T)

l,r=0,1
ans=0
while r<N:
	if R[r]==R[l] and r==N-1:
		r=r+1
		ans=ans+int((r-l)*(r-l+1)/2)
	elif R[r]==R[l]:
		r=r+1
	else:
		ans=ans+int((r-l-1)*(r-l)/2)
		r=r+1
		l=r
print(int(ans))

Submission status: Wrong Answer

Solution code:
N = int(input())
S = [''.join(sorted(input())) for _ in range(0, N)]
d = {}

for s in S:
    if s[0] in d.keys():
        d[s[0]].append(s)
    else:
        d[s[0]] = [s]

result = 0

for k in d.values():
    for i, s in enumerate(k):
        for j in range(i + 1, len(k)):
            print(s, k[j])
            if s == k[j]:
                result += 1

print(result)

Submission status: Wrong Answer

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

from collections import Counter

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

c = Counter(nS)

P = 10**9+7

"""aのp乗を計算"""
def modpow(a, p):
    if p==0:
        return 1
    else:
        if p%2==0:
            return (modpow(a, p//2)**2)%P
        else:
            return (a*modpow(a, p-1))%P

"""nCkを計算"""
def comb(n, k):
    if n<k:
        return 0
    elif n==k or k==0:
        return 1
    else:
        mul = 1
        div = 1
        for i in range(1, min(k, n-k)+1):
            mul *= n-i+1
            div *= i
            mul %= P
            div %= P
        
    return mul*modpow(div, P-2)%P

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

Submission status: Wrong Answer

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

count=0
c=0
prev=ls[0]
for i,name in enumerate(ls):
    if name!=prev:
        count+=c*(c-1)/2
        c=1
        prev=name
    if i==n-1:
        count+=c*(c-1)/2
        c=1
        prev=name
    c+=1

print(int(count))

Submission status: Wrong Answer

Solution code:
N=int(input()) 
t=[[0]*10]*N
y=[[0]*10]*N

for i in range(N):
  s=input()
  for j in range(10):
    t[i][j]=s[j]
  y[i]=sorted(t[i])
  
count=0

for i in range(0,N-1):
  for j in range(i+1,N):
    #print(i,t[i])
    #print(j,t[1])

    if y[i]==y[j]:
        count+=1
    else:
      break

print(count)

Submission status: Wrong Answer

Solution code:
i=int( input())
j=[]
for k in range(i):
	l=input()
	l=(sorted(l))
	j.append(str(l))

m=i-len(set(j))
print(m)

Submission status: Wrong Answer

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)
for v in no:
  counter = 0
  counter +=result.count(v)
print(counter)

Submission status: Wrong Answer

Solution code:
import collections
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):
        if collections.Counter(string_list[i]) == collections.Counter(string_list[j]):
            counter +=1
    counter  = counter / 2
    if result <= counter:
        result = counter
        
print(int(result))

Submission status: Wrong Answer

Solution code:
n=int(input())
lista=[]
for i in range (n):
  a=input()
  aa =list(a)
  aa.sort()
  aaa=''.join(aa)
  lista.append(aaa)
lista.sort()
anss=0
for ii in range (n):
  ans=lista.count(lista[ii])
  if ans >1:
    anss +=1
if anss==0:
  print(0)
else:
  print(anss-1)

Submission status: Wrong Answer

Solution code:
#coding utf-8

n = int(input())

s = list()
for i in range(n):
    tmp = list(input())
    tmp.sort()
    # print(tmp)
    s.append(''.join(tmp))

# print(s)

ans = len(s) - len(set(s))

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = []
a = 0
b = 0
for i in range(N):
    s.append(''.join(sorted(list(input()))))
    
a = len(s)
b = len(set(s))

print(int((a - b)*2))

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
lst = []
lstn = [0] *10**5
j = 0

for i in range(n):
    s = input()
    c = Counter(s)
    if c not in lst:
        lst.append(c)
        lstn[j] = 1
        j += 1
    else:
        k = lst.index(c)
        lstn[k] += 1
        
print(sum(lstn))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
li = []
ct = 0
su = 0
alpha2num = lambda c: ord(c) - ord('a') + 1
for i in range(n):
    su = 0
    #li.append("".join(sorted(input())))
    s = input()
    for c in s:
        su += alpha2num(c)
    li.append(su)
li.append(1000000000)
lll= 1
for i in range(n):
    list.sort(li)
    if li[i] == li[i+1]:
        lll += 1
    else:
        if lll != 1:
            for j in range(1, lll):
                ct += j
        lll = 1
print(ct)

Submission status: Wrong Answer

Solution code:
n = int(input())
str_list = [input() for i in range(n)]
ans = 0
for i in range(n):
  for j in range(n-i-1):
    count = 0
    for k in range(10):
      if str_list[i][k] in str_list[j+i+1]:
        count +=1
      else:
        break
    if count == 10:
      ans +=1
print(ans)

Submission status: Wrong Answer

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


main(input())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

def judge(Si_list, Sj):
    for i in range(10):
        if Si_list[i] in Sj:
            pass
        else:
            return 0
    return 1


# 標準入力
N = int(input())

str_list = [input() for i in range(N)]

count = 0
for i in range(0,len(str_list)):
    Si_list = list(str_list[i])
    for j in range (i+1, len(str_list)):
        count = count + judge(Si_list, str_list[j])
  
print (count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
 
def get_counter(s):
    return Counter(s)

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

ans = 0
i = 0
while i < len(l):
    ans += sum([get_counter(l[i]) == get_counter(l[n]) for n in range(i+1,n)])
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

s.sort()
cnt = 0
key = s[0]
flag = 0
for i in range(n-1):
    if key == s[i] and s[i] == s[i+1]:
        cnt += 1
        flag = 1
    elif s[i] != s[i+1]:
        if flag == 1:
            cnt += 1
        key = s[i+1]
        flag = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
def encode(s):
#  r = [0]*26
#  for n in range(len(s)):
#    r[ord(s[n]) - ord('a')] += 1
#  return r
  r = list(s)
  r.sort()
  return r

N = int(input())

S = []

for n in range(N):
  s = str(input())
  S = S + [encode(s)]
print('a')
S.sort()
print('b')

ct = 0
M=1
ps=""
for cs in S:
  if cs==ps:
    M+=1
  else:
    ct += int((M**2-M)/2)
    M=1
    ps=cs
ct += int((M**2-M)/2)

print(ct)

Submission status: Wrong Answer

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

    totals = []
    count = 0
    for _ in range(N):
        inp = input()
        t = sum([ord(ci) for ci in inp])
        count += totals.count(t)
        totals.append(t)
    print(count)


main()

Submission status: Wrong Answer

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

ab = "abcdefghijklmnopqrstuvwxyz"
ab_dict = {}
for i,c in enumerate(ab):
    ab_dict[c] = i

def count_c(s):
    count_list = [0]*26
    for c in s:
        count_list[ab_dict[c]] += 1
    # for i in range(26):
    #     count_list[i] = str(count_list[i])
    return count_list

sc_list = []
for s in s_list:
    sc = count_c(s)
    # sc = ''.join(sc)
    # print(sc)
    sc_list.append(sc)

ans = 0
for i,sc in enumerate(sc_list):
    for sc2 in sc_list[i+1:]:
        for i in range(26):
            if sc[i] != sc2[i]:
                break
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import collections

n = int(input())
s = []
for i in range(n):
  s_ = sorted(input())
  s.append(s_[0]+s_[1]+s_[2]+s_[3]+s_[4]+s_[5]+s_[6]+s_[7]+s_[8]+s_[9])

c = collections.Counter(s)
count = 0

for i in c:
  if c[i] == 1:
    break
  count += c[i]*(c[i]-1)/2

print(int(count))

Submission status: Wrong Answer

Solution code:
num = int(input())
tmp = []
for i in range(num):
  tmp.append(sorted(input()))

tmp = sorted(tmp)
ans = 1
for i in range(len(tmp)-1):
  if tmp[i] == tmp[i+1]: ans += 1
  else:
    if ans>1: pass
    else: ans = 1
if ans==1: ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
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

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [set(input()) for i in range(N)]
 
a = 0
for i in range(N-1):
  for j in range(i+1,N):
    if s[i]==s[j]:
      a+=1
print(a)

Submission status: Wrong Answer

Solution code:
A = list(map(sorted,open(0).read().split()))
cnt = 0
N = int(A[0][0])
#print(N,A)
for i in range(1,N):
  for j in range(1,N-i):
    if A[i]==A[j]:
      cnt+=1
      
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
T = []
for j in range(N):
  T.append(sorted(list(S[j])))
count = 0
ans = 0
for k in range(N):
  for l in range(N):
    for m in range(10):
      if T[k][m]==T[l][m]:
        count += 1
    ans += count//10
    count = 0
print(int(ans/4))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    # a, b
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    print(process(n, s))


def process(n, s):
    count = 0
    for i in range(0, n):
        for k in range(i, n):
            print('{}, {}'.format(i, k))
            if i == k:
                # print('continue: {}, {}'.format(i, k))
                continue

        # print('pass: {}, {}'.format(i, k))
        first = s[i]
        second = s[k]
        if anagram(first, second) == True:
            # print('anagram: {}, {}'.format(i, k))
            count += 1
    return count


def anagram(a, b):
    for i in a:
        if i in b:
            a.replace(i, '')

        else:
            return False
    return True


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
sl=list([input() for i in range(n)])
def sort_str(s):
    cl = list(s)
    cl.sort()
    return ''.join(cl)
m={}
for i in range(n):
    s = sort_str(sl[i])
    if not s in m:
        m[s] = 0
    else:
        m[s] +=1
sum=0
for k,v in m.items():
    sum+=v
print(sum)

Submission status: Wrong Answer

Solution code:
def alphas(key):
    value = {}
    for char in key:
        if value.get(char) is None:
            value[char] = 1
        else:
            value[char] += 1
    return value

def main():
    N = int(input())
    anagrams = []
    for i in range(N):
        s = input()
        anagrams.append(s)
    ans = 0
    json = {}
    for key in anagrams:
        value = alphas(key)
        for json_key in json.keys():
            if json[json_key]["alphas"] == value:
                json[json_key]["num"] += 1
                ans += json[json_key]["num"]
                break
        json[key] = {"alphas": value, "num": 0}

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
import math

N = int(input())
S = [input() for i in range(N)]
sorted_S =  [''.join(sorted(s)) for s in S]
c = collections.Counter(sorted_S)

print(sum([math.factorial(n)//2 for n in  list(c.values()) if n >=2]))

Submission status: Wrong Answer

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

for i, s_i in enumerate(s):
    s_l = list(s_i)
    s_l.sort()
    a = ""
    for c in s_l:
        a += c
    s[i] = a

cnt = 0
count_dict = {}
for j in range(N):
    count_dict[s[j]] = 0
for k in range(N):
    count_dict[s[k]] += 1
# 
# for v in count_dict.values():
#     cnt += len(list(itertools.combinations(range(v), 2)))

print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import numpy as np
n = int(input())
ll = []
ans = 0
for _ in range(n):
    c = list(input())
    c.sort()
    ll.append("".join(c))
ans = np.sum([np.arange(v).sum() for v in Counter(ll).values() if v > 1])
print(ans)

Submission status: Wrong Answer

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

N = int(input())
# o(10**5 * 10**2 = 10**7)
list =  [''.join(sorted(list(input().strip("\n")))) for i in range(N)]
# o(10**5 * log(10**5) = 10**7)
list.sort()

c = collections.Counter(list)
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())

t = [str(input()) for i in range(n)]

sorted_l = []

for i in t:
    temp = ''
    temp = ''.join(sorted(i))
    sorted_l.append(temp)

count = 0

for i in sorted_l:
    count += sorted_l.count(i)-1

print(count/2)

Submission status: Wrong Answer

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

def isAnagram(s1, s2):
  return 1 if sum([int(letter in s2)for letter in s1]) == 10 else 0

print( sum([sum( [isAnagram(s[i], s[j])for j in range(i+1, N)]) for i in range(N-1)]) )

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []

for i in range(N):
    s = input()
    S.append(''.join(sorted(s)))

S.sort()
count = 0
sw = 0
for i in range(1, len(S)):
    if S[i-1]==S[i]:
        sw = 1
        count += 1
    else:
        if sw==1:
            count += 1
            sw = 0

if sw==1:
    count += 1

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(0,n):
    a = max(input())
    l.append(a)

s = 0
for i in range(n-1):
  for k in range(i+1,n):
    if l[i] == l[k]:
      s +=1

print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(str(input()) for i in range(n))
gou = []
for g in range(len(li)):
    lis = []
    moji = ""
    for k in range(len(li[g])):
        lis.append(li[g][k])
    lis.sort()
    for m in range(len(lis)):
        moji += lis[m]
    gou.append(moji)
print(len(gou)-len(list(set(gou))))

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    # if n - r < 0: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

# print(cmb(1,2))

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

for i in range(N):
    temp = ''.join(sorted(input()))
    s.append(temp)

s = sorted(s)

# print(s)
ans = 0
count = 1

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

ans += cmb(count,2)

print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
# import math

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod

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 += int(comb(v, 2, 10**9+7))
print(count)

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
s_list = []
n_list = []
ana = 0
for i in range(n):
    s = sorted(input())
    print(s)
    if len(s_list) > 0:
        for num, s_i in enumerate(s_list):
            if s_i == s:
                n_list[num] += 1
                break
        s_list.append(s)
        n_list.append(0)
    else:
        s_list.append(s)
        n_list.append(0)


for n_i in n_list:
    if n_i > 0:
        if n_i == 1:
            ana += 1
        else:
            ana += math.factorial(n_i) / math.factorial(n_i-2) / 2
print(ana)

Submission status: Wrong Answer

Solution code:
def isAnagram(s, ss):
	i = 0
	while ss != "" and i < len(s):
		ss.replace(s[i], '')
		i += 1
	if ss == "":
		return 1
	else:
		return 0


c = int(input())

strings = []
for i in range(c):
	strings.append(input())

count = 0
for i in range(c):
	for j in range(i, c):
		count += isAnagram(strings[i], strings[j])

print(count)

Submission status: Wrong Answer

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

#print(l)
cnt=0
list_set=set(l)
#for i in range(n):
#    if l.count(l[i])>1:
#        cnt=cnt+1
#    l[i]=000
#    print(i,cnt)
#
#print(cnt)

print(n-len(list_set))

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [''.join(sorted(list(input()))) for i in range(N)]
a_unique = set(a)
b = 0
for i in a_unique:
 b = b + a.count(i) - 1
print(int(b))

Submission status: Wrong Answer

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())
s=[]
a="abcdefghijklmnopqrstuvwxyz"
mojin=[0 for j in range(n)]
ans=0
cnt=1
for i in range(n):
  l=input()
  for j in l:
    for p,q in enumerate(a):
      if j==q:
        mojin[i]+=2**p

mojin.sort()

for i in range(1,n):
  if mojin[i]==mojin[i-1]:
    cnt+=1
  else:
    if cnt>1:
      ans+=cmb(cnt,2)
      cnt=1
if mojin[n-2]==mojin[n-1]:
  ans+=cmb(cnt,2)
print(ans)

Submission status: Wrong Answer

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

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

for i in range(n):
    for j in range(i+1, n):
        if (lst[i] == lst[j]):
            num = num + 1
print(num)

Submission status: Wrong Answer

Solution code:
from array import array
import math

N = int(input())

S = []

for i in range(N):
    s = input()
    slist = list(s)
    slist.sort()
    s = ''.join(slist)
    S.append(s)

#N_FAC_MAX = math.factorial(10)
#FAC = array('l', [0]*(N+1))
#FAC = array('q', [0]*(N_FAC_MAX+1))
FAC = {}
FAC[1] = 1

#for i in range(2,N_FAC_MAX+1):
for i in range(2,N+1):
    FAC[i] = FAC[i-1]*i
    
count = 0

for s in set(S):
    s_counts  = S.count(s)
    if s_counts > 1:
        #fac = math.factorial(s_counts)
        #count += fac//2
        count += FAC[s_counts]//2

print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
# o(10**5 * 10**2 = 10**7)
list =  [''.join(sorted(list(input().strip("\n")))) for i in range(N)]
# o(10**5 * log(10**5) = 10**7)
list.sort()
print(list)

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
str_list = [input() for i in range(n)]
ans = 0
for i in range(n):
  for j in range(n-i-1):
    count = 0
    for k in range(10):
      if str_list[i][k] in str_list[j+i+1]:
        count +=1
    if count == 10:
      ans +=1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [sorted(input()) for _ in range(n)]
s.sort()
count = 0
num = 0
ans = 0

for i in range(n):
    for j in range(i+1, n):
        count = 0
        for k in range(len(s[0])):
            if s[i][k] == s[j][k]:
                count += 1
                if count == len(s):
                    ans += 1
                    num += 1
            else:
                break

print(ans)

Submission status: Wrong Answer

Solution code:
def cmb(n, r):
    if n - r < 0: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

# print(cmb(1,2))

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

for i in range(N):
    temp = ''.join(sorted(input()))
    s.append(temp)

# s = sorted(s)

# print(s)
ans = 0
count = 1

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

ans += cmb(count,2)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

chars = []
for _ in range(n):
  chars.append(tuple(sorted(list(input()))))
  
print(n - len(set(chars)))

Submission status: Wrong Answer

Solution code:
n=int(input())
s=[[0 for i in range(10)] for j in range(n)]
for i in range(n):
  s[i]=list(input())
  s[i].sort()
count=0

for i in range(n):
  for j in range(n-1):
    if s[i]==s[j] and i!=j:
      count+=1

  

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
r = dict()
find = False
for i in range(n):
    l = str(sorted([c for c in input()]))
    if l not in  r:
        r[l] = 1
    else:
        r[l] = r[l] + 1
        find=True

if not find:
    print('0')

sum = 0    
def comb(n, k):
    bo = 1
    for kk in range(1, k+1):
        bo = bo * kk
    si = 1
    for kk in range(n-k+1 ,n+1):
        si = si * kk
    return int(si / bo)

for k, v in r.items():
    sum = sum + comb(v, 2)
print(sum)

Submission status: Wrong Answer

Solution code:
import math
import collections


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
    if i == 3:
        ans += 3
        continue

    ans += math.factorial(i) / math.factorial(2) / math.factorial(i - 2)
"""
ans = 0
print(ans)

Submission status: Wrong Answer

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

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

check = []

for i in range(N):
    if s[i] not in check:
        ans += s.count(s[i])
        check.append(s[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import collections

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


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


c = collections.Counter(s)

count = 0
for v in c.values():
    count += v-1
    

print(count)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = []
for i in range(n):
  word = str(input())
  lis.append({letter:word.count(letter) for letter in word})
counter = 0
while True:
  m = lis.count(lis[0])
  counter += (m*(m-1))//2
  lis.remove(lis[0])
  if len(lis) == 0:
    break
print(counter)

Submission status: Wrong Answer

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


n1_init = [0 for i in range(26)]
n2_init = [0 for i in range(26)]
counter = 0
check = 0

for i in range(N-1):
    for j in range(i+1, N):
        n1 = [0] * 26
        n2 = [0] * 26
        check = 0
        # 辞書入れ込み
        for c in str[i]:
            for l in range(26):
                if ord(c) == ord('a') + l: n1[l] += 1
        for c in str[j]:
            for l in range(26):
                if ord(c) == ord('a') + l: n2[l] += 1
        for k in range(26):
            if n1[k] != n2[k]: check=1
        if check==0: counter += 1
        print(counter)

print(counter)

Submission status: Wrong Answer

Solution code:
N = int(input())
strList = []
for i in range(N):
    inStr = input()
    inList = []
    for j in range(len(inStr)):
        inList.append(inStr[j])
        inList.sort()
    strList.append(''.join(inList))

anaglam = 0
for i in range(N):
    for j in range(i+1,N):
        if strList[i] == strList[j]:
            anaglam = anaglam + 1
            break
print(anaglam)

Submission status: Wrong Answer

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


def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

Submission status: Wrong Answer

Solution code:
N = int(input())
S = []

for i in range(N):
    s = input()
    S.append(''.join(sorted(s)))

S.sort()
count = 0
sw = 0
for i in range(1, len(S)):
    if S[i-1]==S[i]:
        sw = 1
        count += 1
    else:
        if sw==1:
            count += 1
            sw = 0

print(count)

Submission status: Wrong Answer

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

    totals = []
    count = 0
    for _ in range(N):
        inp = input()
        totals.append(sum([ord(ci) for ci in inp]))

    for i, si in enumerate(totals):
        count += totals[i+1:].count(si)
    print(count)


main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from math import factorial
import numpy as np
from scipy.misc import factorial
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: Wrong Answer

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

while len(s):
    cnt = 0
    for i in range(1, len(s)):
        if s[0] == s[i]:
            cnt += 1
        else:
            break
    cnt = int((cnt+1) * (cnt) / 2)
    cnt_ans += cnt
    s = s[cnt+1:]
print(cnt_ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
t = [str(input()) for i in range(N)]
for i in range(N):
    t[i] = list(t[i])
cnt = 0
for i in range(N-1):
    for j in range(i+1,N):
        if set(t[i])==set(t[j]):
            cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = []
for i in range(n):
    s = list(input())
    s = sorted(s)
    ls.append(s)
ans = 0
ls = sorted(ls)
for i in ls:
    ans += (ls.count(i)-1)
    if ls.count(i) == 1:
        break
    
print(round(ans/2))