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: Accepted

Solution code:
from collections import defaultdict
from math import factorial
if __name__ == "__main__":
    n = int(input())
    lst = []
    count = 0
    words = defaultdict(lambda: 0)
    for i in range(n):
        words[''.join(sorted(input()))] += 1
    sum = 0
    for word in words:
        sum += int(factorial(words[word]) / (factorial(2) * factorial(abs(words[word] - 2))))
    print(sum)

Submission status: Accepted

Solution code:
N = int(input())

mem = dict()
for _ in range(N):
    s = ''.join(sorted(input()))
    if s in mem.keys():
        mem[s] += 1
    else:
        mem[s] = 1

ans = 0
for i in mem.values():
    ans += i * (i-1) // 2
print(ans)

Submission status: Accepted

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


def main():
    N = int(input().strip())
    s_list = [sorted(input().strip()) for _ in range(N)]
    s_list = sorted(s_list)
    ans = 0
    duplicate_num = 0
    for index in range(len(s_list)-1):
        if s_list[index] == s_list[index+1]:
            duplicate_num += 1
        else:
            ans += duplicate_num * (duplicate_num+1) // 2
            duplicate_num = 0
    ans += duplicate_num * (duplicate_num+1) // 2
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import collections
import math

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

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

ans = 0
Y=[]
for s in S:
    X = []
    for w in s:
        X.append(w)
        X.sort()
        y = ''.join(X)
    Y.append(y)

c = collections.Counter(Y)
C = c.most_common()
len_C = len(C)

for n in range(len_C):
    if C[n][1] > 1:
        ans += combination(C[n][1], 2)
    else:
        pass

print(round(ans))

Submission status: Accepted

Solution code:
n = int(input())
col = {}
for i in range(n):
  s = list(input())
  s.sort()
  s2 =''.join(s)
  if s2 in col:
    col[s2]+=1
  else:
  	col[s2] = 1
com = lambda x : x*(x-1)/2
print(int(sum(com(col[k]) for k in col)))

Submission status: Accepted

Solution code:
N=int(input())
S=[''.join(sorted((input()))) for i in range(N)]
P={}
for i in range(N):
    if S[i] in P:
        P[S[i]]+=1
    else:
        P[S[i]]=0
for i in P.keys():
    if P[i]>=2:
        P[i]=P[i]*(P[i]+1)/2
print(int(sum(P.values())))

Submission status: Accepted

Solution code:
n=int(input())
s=[input() for i in range(n)]
for i in range(n):
    s[i]=''.join(sorted(s[i]))
t = {}
for i in range(n):
  if s[i] in t:
    t[s[i]] += 1
  else:
    t[s[i]] = 1
print(sum(t[k] * (t[k] -1) // 2 for k in t))

Submission status: Accepted

Solution code:
n=int(input())

d={}
for i in range(n):
      tx="".join(sorted(input()))
      if tx in d:
            d[tx] += 1
      else:
            d[tx] = 1


ans=0
for i in d.values():
      ans += (i*(i-1))//2
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
from collections import Counter

c = Counter(s)
print(sum((x * (x - 1)) // 2 for x in c.values()))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 08:58:11 2019

@author: avina
"""

n = int(input())
d = {}
for i in range(n):
  a = list(input())
  a.sort()
  a = ''.join(a)
  if a not in d:
    d[a] = 1
  else:
    d[a]+=1
ans = 0
for i in d:
    ans += ((d[i])*(d[i]-1))//2
print(ans)

Submission status: Accepted

Solution code:
N=int(input())

import sys
input = sys.stdin.readline

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

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

out=0

d={}

for i in range(N):
    if str(s[i]) in d:
        out+=d[str(s[i])]
        d[str(s[i])]+=1
    else:
        d[str(s[i])]=1

print(out)

Submission status: Accepted

Solution code:
from collections import Counter
import itertools

N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
print(sum((x * (x - 1)) // 2 for x in Counter(S).values()))

Submission status: Accepted

Solution code:

import collections
n=int(input())
Words = [input() for t in range(n)]

Words2=[]
for i in Words:
        i=''.join(sorted(i))
        Words2.append(i)

c = collections.Counter(Words2)

values, counts = zip(*c.most_common())

ans=0
for j in counts:
        ans+=j*(j-1)//2
print(ans)

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    s = collections.Counter(["".join(sorted(str(input().rstrip('\n')))) for _ in range(n)])
    t = 0
    for k, v in s.items():
        for i in range(1, v):
            t += i
    print(t)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
N=int(input())
s = [''.join(sorted(input())) for _ in range(N)]
from collections import Counter
c = Counter(s)
print(sum((x*(x-1))//2 for x in c.values()))

Submission status: Accepted

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

s_srt = []
for i in range(n):
    s_srt.append(''.join(sorted(s[i])))
s_srt.sort()

tmp = [0,]
k = 0
next = False
for i in range(n - 1):
    if s_srt[i] == s_srt[i + 1]:
        tmp[k] += 1
        next = True
    else:
        if next:
            tmp.append(0)
            k += 1
if tmp[-1] == 0:
    tmp.remove(0)

ans = 0
m = len(tmp)
if m != 0:
    for i in range(m):
        ans += int((tmp[i] + 1) * tmp[i] / 2)

print(ans)

Submission status: Accepted

Solution code:
import collections as co
n=int(input())
cnt=0
s=[''.join(sorted(input())) for _ in range(n)]
m=co.Counter(s)
for item in m:
    cnt += m[item]*(m[item]-1)/2
print(int(cnt))

Submission status: Accepted

Solution code:
import collections as co
n=int(input())
cnt=0
s=[''.join(sorted(input())) for _ in range(n)]
m=co.Counter(s)
for item in m:
    cnt += m[item]*(m[item]-1)/2
print(int(cnt))
'''
for i in range(1,n):
    for j in range(i):
        if s[j] == s[i]:
            cnt+=1
print(cnt)
'''

Submission status: Accepted

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

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]
dup = collections.Counter(s).values()

ans = sum(c*(c-1)//2 for c in dup)
print(ans)

Submission status: Accepted

Solution code:
import collections, math

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

for idx in range(N):
    s_l[idx] = "".join(sorted(s_l[idx]))

c = collections.Counter(s_l)
ans = 0

for i in c.values():
    if i >= 2:
        ans += math.factorial(i) / (math.factorial(i - 2) * math.factorial(2))

print(int(ans))

Submission status: Accepted

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

N=int(input())

D={}
ans=0
for i in range(N):
    s =".".join(sorted(input()))
    if s in D.keys():
        ans+=D[s]
        D[s] += 1
    else:
        D[s]=1

print(ans)

Submission status: Accepted

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

s_sorted = sorted([sorted(si) for si in s])

ans = 0
for i, si in enumerate(s_sorted):
    if i == 0:
        cnt = 1
        si_prev = si
    else:
        if si != si_prev:
            ans += (cnt * (cnt - 1) // 2)
            cnt = 1
        else:
            cnt += 1
        # print("#", i, si, cnt)
        si_prev = si
else:
    ans += (cnt * (cnt - 1) // 2)
    
print(ans)

Submission status: Accepted

Solution code:
import collections
N=int(input())
su=["".join(sorted(list(input()))) for _ in range(N)]

C=list(collections.Counter(su).values())

ans=0
for i in C:
  if i>1:
    ans+=i*(i-1)//2

print(ans)

Submission status: Accepted

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

a=[]

for j in s:
    a.append("".join(sorted(j)))

import collections
c = collections.Counter(a)

ans=0
for i in c.values():
    ans+=i*(i-1)/2
print(int(ans))

Submission status: Accepted

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

ans = 0
count = 1
s_pre = s[0]

for i in range(1, n):
    if s_pre == s[i]:
        count += 1
    else:
        ans += int(count * (count - 1) / 2)
        s_pre = s[i]
        count = 1

ans += int(count * (count - 1) / 2)
print(int(ans))

Submission status: Accepted

Solution code:
N=int(input())

count=0
dic=dict()

for i in range(N):
    s="".join(sorted(input()))
#    print(s)

    if s in dic:
        count+=dic[s]
#        print(dic[s])
        dic[s]+=1
    else:
        dic[s]=1
#        print(dic)

print(count)

Submission status: Accepted

Solution code:
import collections

n = int(input())

a = [str(sorted(input())) for _ in range(n)]
a.sort()
s = set(a)

c = collections.Counter(a)

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

print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
#K,X = map(int,input().split())
N = int(input())
S = [''.join(sorted(input())) for i in range(N)]
result = 0
c = {}
for s in S:
    if c.get(s) is None:
        #print('None')
        c[s] = 1
    else:
        result += c[s]
        c[s] += 1
print(result)

Submission status: Accepted

Solution code:
from collections import  Counter

N=int(input())

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

ctr= Counter()

ans=0

for s in S:
    a = ''.join(sorted(list(s)))
    if a in ctr:
        ans += ctr[a]
    ctr[a] +=1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


def main():
    s = ["".join(sorted(i)) for i in open(0).read().split()[1:]]
    d = defaultdict(lambda: 0)
    ans = 0
    for i in s:
        ans += d[i]
        d[i] += 1
    print(ans)
    return


main()

Submission status: Accepted

Solution code:
from collections import Counter
# バージョン0.14.0まで scipy.misc.comb()
# バージョン0.14.0から scipy.special.comb()
from scipy.misc import comb
# from scipy.special import comb


def main():
    s = Counter(["".join(sorted(i)) for i in open(0).read().split()[1:]])
    ans = 0
    for v in s.values():
        ans += comb(v, 2, exact=True)
    print(int(ans))
    return


main()

Submission status: Accepted

Solution code:
N = int(input())
l = {}
result = 0

for i in range(N):
  s = "".join(sorted(list(input())))
  l[s] = l.get(s, 0) + 1
  
for v in l.values():
  result += v * (v - 1) / 2

print(int(result))

Submission status: Accepted

Solution code:
N = int(input())
dic = {}

for i in range(N):
  S = "".join(sorted(input()))
  if S in dic:
    dic[S] += 1
  else:
    dic[S] = 1

ans = 0

for val in dic.values():
  ans += val * (val - 1) / 2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())

s = {}
for i in range(n):
      text ="".join(sorted(input()))
      if text in s:
            s[text] += 1
      else:
            s[text] = 1

accum = 0
for v in s.values():
      accum += (v * (v-1))//2
print(accum)

Submission status: Accepted

Solution code:
n = int(input())

ans = 0
ans_dict = {}

for i in range(n):
    s = input()
    s = ''.join(sorted(s))
    if(s in ans_dict):
        ans += ans_dict[s]
        ans_dict[s] += 1
    else:
        ans_dict[s] = 1
        
print(int(ans))

Submission status: Accepted

Solution code:
import collections

n=int(input())
s=[]
set={}
for i in range(n):
    s.append(input())
for i in range(n):
    temp=list(s[i])
    temp.sort()
    s[i]=''.join(temp)
count=0
ans=collections.Counter(s)
countlist=ans.most_common()
for i in range(len(countlist)):
    if countlist[i][1]<=1:
        break
    else:
        temp=countlist[i][1]-1
        count+=(temp+1)*temp//2

print(count)

Submission status: Accepted

Solution code:
from collections import Counter
from math import factorial
n = int(input())
s = [''.join(sorted(input())) for i in range(n)]

c = Counter(s)
counter = 0


def kza(a, b):
    return (factorial(a) / factorial(a-b)) / factorial(b)


for i in c.values():
    if i == 1:
        continue
    counter += kza(i, 2)


print(int(counter))

Submission status: Accepted

Solution code:
from math import factorial as fac


def binomial(x, y):
    try:
        binom = fac(x) // fac(y) // fac(x - y)
    except ValueError:
        binom = 0
    return binom

n = int(input())
arr = []
for i in range(n):
    arr.append("".join(sorted(input())))

dct = {}
for i in range(n):
    if arr[i] not in dct.keys(): 
        dct[arr[i]] = 1
    else:
        dct[arr[i]] += 1
        
cnt = 0
l = len(dct.keys())
dctlist = list(dct.keys())
for i in range(l):
    el = dctlist[i]
    if dct[el] > 1:
        cnt += binomial(dct[el],2)
print(cnt)

Submission status: Accepted

Solution code:
from operator import mul
from functools import reduce
from collections import defaultdict
import sys
input = sys.stdin.readline


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


def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        l = sorted(list(input()[:-1]))
        s = ''.join(l)
        d[s] += 1
    # print(d)

    cnt = 0
    for key in d:
        cnt += cmb(d[key], 2)
    
    print(cnt)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = {}
for i in range(n):
  text = ''.join(sorted(input()))
  if text in s:
    s[text] += 1
  else:
    s[text] = 1

sum = 0
for v in s.values():
  sum += (v*(v-1)//2)
print(sum)

Submission status: Accepted

Solution code:
n = int(input())
s = []
for i in range(n):
  text = ''.join(sorted(input()))
  s.append(text)

count = {}
for i in s:
  if i in count:
    count[i] += 1
  else:
    count[i] = 1

sum = 0
for v in count.values():
  int(v)
  sum += (v*(v-1)//2)

print(sum)

Submission status: Accepted

Solution code:
from collections import defaultdict
from math import factorial
N = int(input())
d = defaultdict(int)
for i in range(N):
    s = ''.join(sorted(input()))
    d[s] += 1
t = 0
for c in d.values():
    if 1 < c:
        t += c * (c-1) // 2
print(t)

Submission status: Accepted

Solution code:
n=int(input())
L={}
for i in range(n):
    l=''.join(sorted(list(input())))
    if l in L:
        L[l]+=1
    else:
        L[l]=1
c=0
for v in L.values():
    if v>=2:
        c+=v*(v-1)//2
print(c)

Submission status: Accepted

Solution code:
N = int(input())
S = dict()
for i in range(N):
    r = 0
    s = input()
    s = "".join(sorted(s))
    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
res = 0
for s in S:
    if S[s] > 1:
        res += (S[s]-1)*S[s] // 2
print(res)

Submission status: Accepted

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

Submission status: Accepted

Solution code:
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = int(input())

S = list()
num = {}
ans = 0

for i in range(N):
    S.append(list(input()))
    S[i].sort()
    if "".join(S[i]) in num:
        num["".join(S[i])] += 1
        ans += num["".join(S[i])]
    else:
        num["".join(S[i])] = 0

print(ans)

Submission status: Accepted

Solution code:
import collections

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

for i in range(N):
  s = input()
  ss = [i for i in s]
  ss.sort()
  s = ''.join(ss)
  S.append(s)
  
c = collections.Counter(S)
ans = 0

for b in c:
  ans += c[b] * (c[b] - 1) // 2
  
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
d = {}
x = 0
for i in [0]*N:
    s = ''.join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 0
for p in d.values():
    x += (p+1) * p // 2
print(x)

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
 
for i in range(N):
    s = list(input())
    s.sort()
    key = str(s)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1
 
ans = 0
for value in dic.values():
    ans += value*(value-1) / 2
print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = list(input() for _ in range(n))
ans = 0
d = {}
for i in range(n):
    s[i] = "".join(sorted(s[i]))
    if s[i] not in d.keys():
        d[s[i]] = 0
    else:
        d[s[i]] += 1
        ans += d[s[i]]

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    n = f.read_int()
    d = collections.defaultdict(int)
    for _ in xrange(n):
        s = f.read_str()
        ss = "".join(sorted(list(s)))
        d[ss] += 1

    ans = 0
    for k, v in d.items():
        ans += v*(v-1)/2

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
s_dict = {}
sum = 0
for i in range(N):
    if s[i] in s_dict.keys():
        sum +=s_dict[s[i]]
        s_dict[s[i]] += 1
    else:
        s_dict[s[i]] = 1
print(sum)

Submission status: Accepted

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

ans = 0
count = {}
for i in range(n):
    c = ''.join(sorted(s[i]))
    count.setdefault(c,0)
    count[c] += 1
    if(count[c] > 0):
        ans += count[c] -1

print(ans)

Submission status: Accepted

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

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

N = int(input())
s_list = []
for _ in range(N):
    s = ''.join(sorted(list(input())))
    s_list.append(s)

b = 0
for i in Counter(s_list).values():
  if i==1:
    pass
  else:
    b += combinations_count(i,2)
print(b)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import *
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    print(max(a + b, a - b, a * b))
    return

#B
def B():
    k, x = LI()
    ans = []
    for i in range(x - k + 1, x + k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    n = II()
    d = defaultdict(int)
    for _ in range(n):
        s = S()
        s.sort()
        d[tuple(s)] += 1
    ans = 0
    for i in d.values():
        ans += i * (i - 1) // 2
    print(ans)
    return

#D
def D():
    n, m = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: (x[1], x[0]), reverse=True)
    ans = 0
    for i in range(n):
        if m >= ab[i][0]:
            ans += ab[i][1]
            m -= 1
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

Solution code:
N=int(input())
lst=[]
for i in range(N):
  text=input()
  lst.append([sorted(text)])
lst=sorted(lst)      
count=0
i=0
while(i<N-1):
  j=1
  while(lst[i]==lst[i+j]):
    count=count+j
    j=j+1
    if (i+j >= N):
      break
  i=i+j
print(count)

Submission status: Accepted

Solution code:
from collections import defaultdict

d = defaultdict(int)
n = int(input())
s = [input() for _ in range(n)]

for tmp in s:
    tmp =sorted(tmp)
    tmp = "".join(tmp)
    d[tmp] += 1

result = 0
for c in d.values():
    result += c*(c-1) // 2

print(result)

Submission status: Accepted

Solution code:
N = int(input())
dic = {}

for i in range(N):
    s = list(input())
    s.sort()
    key = str(s)
    if key in dic:
        dic[key] += 1
    else:
        dic[key] = 1

ans = 0
for value in dic.values():
    ans += value*(value-1) / 2
print(int(ans))

Submission status: Accepted

Solution code:
n=int(input())
dic={}
for i in range(n):
  hoge=list(input())
  hoge.sort()
  hoge=str(hoge)
  if(hoge in dic):
    dic[hoge]+=1
  else:
    dic[hoge]=1


ans=0
for i in dic.values():
  ans+=i*(i-1)//2
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(input())
S = ["".join(sorted(list(input()))) for _ in range(N)]

cnt = Counter(S)
print(sum(v*(v-1)//2 for v in cnt.values()))

Submission status: Accepted

Solution code:
n = int(input())
dic = {}
ans = 0
for i in range(n):
  li_1 = list(input())
  li_1.sort()
  word = "".join(li_1)
  if word in dic:
    dic[word] += 1
  else:
    dic[word] = 1
for key in dic:
  s = dic[key]
  ans += s*(s-1)//2
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N, *sl = map(lambda x:''.join(sorted(x)), open(0).read().split())
    dic = {}
    ans = 0
    
    for s in sl:
        if s in dic:
            ans += dic[s]
            dic[s] += 1
        else:
            dic[s] = 1
    
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
N = int(input())

result = 0
moji = {}
for i in range(N):
    val = str(sorted(str(input())))
    if (val in moji):
        moji[val].append(i)
    else:
        moji[val] = [i]

result = 0
for val in moji.values():
    result += int((len(val)*(len(val)-1))/(2))

print(result)

Submission status: Accepted

Solution code:
#C問題
N = int(input())
S = []
for i in range(N):
    s = list(str(input()))
    s.sort()
    S.append(s)
S.sort()

count = 0
now = 0
nows = 0
for i in range(N):
    if i == 0:
        nows = S[0]
        now = 1
    else:
        if nows != S[i]:
            nows = S[i]
            count += ((now*(now-1))//2)
            now = 1
        else:
            now+=1
            
count += ((now*(now-1))//2)
print(count)

Submission status: Accepted

Solution code:
n = int(input())
d = {}

for _ in range(n):
    s = ''.join(sorted(input()))
    if s in d:
        d[s] += 1
    else:
        d[s] = 1

ans = 0
for k, v in d.items():
    ans += (v * (v - 1)) / 2

print(int(ans))

Submission status: Accepted

Solution code:
n = int(input())
s = {}
cnt = 0
for i in range(n):
    ss = input()
    t = []
    
    for j in ss:
        t.append(j)
    # print(t)
    # print(t.sort)
    t = sorted(t)
    # print(t)
    # u = []
    # for q in t:
    #     u.append(q)
    # print(u)
    u = "".join(t)
    # print(u)
    if u in s.keys():
        s[u] += 1
    else:
        s[u] = 1
# print(s)
for i in s.values():
    cnt += i * (i-1) // 2
print(cnt)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    s = ["".join(sorted(input())) for _ in range(n)]
    ans = 0
    dic = {}
    for i in s:
        if i not in dic:
            dic[i] = 0
        else:
            dic[i] += 1
            ans += dic[i]
        # print(ans)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

dic = {}
count = 0
for i in range(n):
    s = list(input().strip())
    s.sort()
    s = "".join(s)
    if s not in dic:
        dic[s] = 0
    else:
        dic[s] += 1
        count += dic[s]

print(count)

Submission status: Accepted

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

s_dict ={}
ans = 0
for i in range(N) :
    if s[i] in s_dict.keys() :
        ans += s_dict[s[i]]
        s_dict[s[i]] += 1
    else :
        s_dict[s[i]] = 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
import math
N = int(input())
S = ["".join(sorted(input())) for _ in range(N)]
ans = 0
for v in Counter(S).values():
    if v>1:
        ans += math.factorial(v)/(math.factorial(2)*math.factorial(v-2))
print(int(ans))

Submission status: Accepted

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

s_dic = {}
ans = 0

for si in range(N):
    if s[si] in s_dic.keys():
        ans += s_dic[s[si]]
        s_dic[s[si]] += 1
    else:
        s_dic[s[si]] = 1
print(ans)

Submission status: Accepted

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

Sdic = {}
ans = 0

for i in range(N):
    if S[i] not in Sdic.keys():
        Sdic[S[i]] = 1
    else:
        ans += Sdic[S[i]]
        Sdic[S[i]] += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter as co
from operator import mul
from functools import reduce

def combinations_count(n, r):
  r = min(r, n - r)
  numer = reduce(mul, range(n, n - r, -1), 1)
  denom = reduce(mul, range(1, r + 1), 1)
  return numer//denom


n=int(input())
a=0
l=[''.join(list(map(str,sum(sorted(list(map(list,co(input()).items()))),[])))) for i in range(n)]
for d,s in co(l).items():
  if s>=2:a+=combinations_count(s, 2)
print(a)

Submission status: Accepted

Solution code:
import collections

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

c = collections.Counter(s)
ans = 0
for si in set(s):
    n = c[si]
    ans += n * (n - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):

    result = 0
    str_dict = dict()
    for s_i in s:

        s_i = list(s_i)
        s_i.sort()
        s_i = "".join(s_i)

        if s_i in str_dict:
            result += str_dict[s_i]
            str_dict[s_i] += 1
        else:
            str_dict[s_i] = 1

    print(result)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, s)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
N=int(input())

dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
 
N=int(input())
dic={}
sum=0
for i in range(N):
    s=list(input())
    s.sort()
    s = "".join(s)
    if s in dic:
        sum+=dic[s]
        dic[s]+=1
    else:
        dic[s]=1
print(sum)

Submission status: Accepted

Solution code:
import math


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

n = int(input())
ans_dict = {}

for _ in range(n):
    s = list(input())
    s.sort()
    s = ''.join(s)
    try:
        ans_dict[s] += 1
    except:
        ans_dict[s] = 1

ans = 0
for key in ans_dict:
    if ans_dict[key] >= 2:
        ans += combinations_count(ans_dict[key], 2)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for _ in range(n):
  s = input()
  k = tuple(sorted(list(s)))
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
ans = 0
for k in d:
  n = d[k]
  ans += n * (n - 1) // 2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = dict()

for _ in range(n):
  value = input()
  key = ''.join(sorted(value))
  
  if key in s:
    s[key] += 1
  else:
    s[key] = 1
          
sum = 0

for value in s.values():
  sum += value*(value-1)//2
  
print(sum)

Submission status: Accepted

Solution code:
n=int(input())
dicts={}
nums=0
for x in range(n):
    s=str(input())
    sorting=sorted(s)
    sorting="".join(sorting)
    if sorting not in dicts.keys():
        dicts[sorting]=1
    else:
        dicts[sorting]+=1
for x in  dicts.values():
    nums+=int(x*(x-1)/2)
print(nums)

Submission status: Accepted

Solution code:
n= int(input())
l = []
for _ in range(n):
    l.append(''.join(sorted(input())))
#print(l)
d = dict()
cnt = 0
for e in l:
  #print("e=",e)
  if e in d:
    #print(e,"in",d)
    d[e] += 1
    cnt += d[e]
    #print('d[',e,']=',d[e],'cnt=',cnt)
  else:
    #print(e,'not in',d)
    d[e] = 0
    #print('d[',e,']=',d[e],'cnt=',cnt)
print(cnt)
#print(d)

Submission status: Accepted

Solution code:
from collections import Counter

N = int(raw_input())
s = []
for i in range(0,N):
  K = (''.join(sorted(raw_input())))
  s.append(K)
ans = 0

for i in Counter(s).values():
  if i > 1:
    for j in range(1,i):
      ans = ans + j
print ans