Problem: 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.

Submission attempts (in order):
n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a[i] = x

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
for _ in range(n):
  s = str(input())
  freqency = [0 for _ in alphabet]
  for __ in s:
    freqency[alphabet.index(__)] += 1
    freq = "".join(freqency)
    if freq not in res:
      res[freq] = 1
    else:
      res[freq] += 1

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

n = int(input())
s = []
for i in range(n):
  tmp = str(input())
  tmp = "".join(sorted(tmp))
  s.append(tmp)
 
a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
 
# print("s:", s)
ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**5):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

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

a = [0 for i in range(10**3)]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a[i] = x

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
ans = 0
for _ in range(n):
    s = str(input())
    s.sort()
    if s not in res.keys():
      res[s] = 1
    else:
      ans += res[s]
      res[s] += 1
print(ans)
      

n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**5):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

n = int(intput())
s = []
for i in range(n):
  tmp = str(input())
  tmp.sort()
  s.append(tmp)

a = [0, 0]
for i in range(2, 10**3):
  x = a[i-1] + (i-1)
  a.append(x)

ans = 0
for _ in list(set(s)):
  ans+= a[s.count(_)]
  
print(ans)

alphabet = "abcdefghijklmnopqrstuvwxyz"


n = int(input())
res = dict()
ans = 0
for _ in range(n):
    s = str(input())
    s = "".join(sorted(s))
    if s not in res.keys():
      res[s] = 1
    else:
      ans += res[s]
      res[s] += 1
print(ans)
      

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted