Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[]
ii=0
for sss in st:
  c=s.count(sss)
  if c>1:
    tp.append(c)
    r+=(c*(c-1))//2
    
print(r)

Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
#tp.sort(reverse=True)

for jj in range(len(tp)):
  """
  if tp[jj][0]==1:
    print(r)
    exit()

  """
  r2=tp[jj][0]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
tp.sort(reverse=True)
"""
for ii in range(len(tp)):
  print(tp[ii])
"""
for jj in range(len(tp)):
  if tp[jj][0]==1:
    print(r)
    exit()
  """sss=tp[jj][1]
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  """
  r2=tp[jj][0]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

tp=[[""]*2 for ii in range(len(st))]
ii=0
for sss in st:
  tp[ii][0]=s.count(sss)
  tp[ii][1]=sss
  ii+=1
tp.sort(reverse=True)
"""
for ii in range(len(tp)):
  print(tp[ii])
"""
for jj in range(len(tp)):
  if tp[jj][0]==1:
    print(r)
    exit()
  sss=tp[jj][1]
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

for sss in st:
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
    
print(r)

Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
st=set()
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  s[ii]=ss
  st.add(ss)

for sss in st:
  ls=[]
  r2=0
  for ii in range(len(s)):
    if s[ii]==sss:
      ls.append(ii)
      r2+=1
  """print(st)
  print(ls)
  print(r2)"""
  m=len(ls)
  for ii in range(m):
    del s[ls[m-1-ii]]
  if r2>1:
    r+=(r2*(r2-1))//2      
  #print(ii)
"""  
import numpy as np
for ii in range(n-1):
  for jj in np.arange(ii+1,n):
    #print(ii,jj)
    if s[ii]==s[jj]:
      #print(s[ii],s[jj])
      r+=1
"""
print(r)


Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[""]*n
r=0
for ii in range(n):
  ss=list(input())
  ss.sort()
  s[ii]="".join(ss)
"""
for ii in range(n):
  print(s[ii])
"""
import numpy as np
for ii in range(n-1):
  for jj in np.arange(ii+1,n):
    #print(ii,jj)
    if s[ii]==s[jj]:
      #print(s[ii],s[jj])
      r+=1
print(r)


Fixed submission:
n=int(input())
s=[""]*n
st=set()
d={}
for ii in range(n):
  ss=list(input())
  ss.sort()
  ss="".join(ss)
  if ss in st:
    d[ss]+=1
  else:
    d[ss]=1
    st.add(ss)

if len(st)==n:
  print(0)
  exit()
if len(st)==1:
  print((n*(n-1))//2)
  exit()

r=0
for sss in st:
  c=d[sss]
  if c>1:
    r+=(c*(c-1))//2
    
print(r)