Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())

S=[]
S_count=dict()

total=0

for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        total+=S_count[s]
        S_count[s]+=1

    else:
        S_count[s]=1
    S.append(s)

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

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


N=int(input())

S=[]
S_count=dict()
fixed_count=dict()
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        S_count[s]+=1
    else:
        S_count[s]=1
    S.append(s)

for k in S_count.keys():
    if S_count[k]>1:
        fixed_count[k]=S_count[k]

key=fixed_count.keys()

total=0

for k in key:
    t=fixed_count[k]
    total+=cmb(t,2)

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

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


N=int(input())

S=[]
S_count=dict()
fixed_count=dict()
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        S_count[s]+=1
    else:
        S_count[s]=1
    S.append(s)

for k in S_count.keys():
    if S_count[k]>1:
        fixed_count[k]=S_count[k]

key=fixed_count.keys()

total=0

for k in key:
    t=S_count[k]
    if t>=2:
        total+=cmb(t,2)

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

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


N=int(input())

S=[]
S_count=dict()
for n in range(N):
    s=input()
    s=''.join(sorted(s))
    if s in S:
        S_count[s]+=1
    else:
        S_count[s]=1
    S.append(s)

key=list(set(S))

total=0

for k in key:
    t=S_count[k]
    if t>=2:
        total+=cmb(t,2)

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

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


N=int(input())

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

key=sorted(list(set(S)))

total=0
for k in key:
    t=S.count(k)
    if(t>=2):
        total+=cmb(S.count(k),2)

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())

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

S=sorted(S)
total=0
for i in range(len(S)):
    key=S[i]
    for j in range(i+1,N):
        if key==S[j]:
            total+=1
        else:
            break

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)

Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())

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

total=0
for i in range(len(S)):
    key=S[i]
    for j in range(i+1,N):
        if key==S[j]:
            total+=1

print(total)

Fixed submission:

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

for s in range(N):
    tmp=input()
    S.append("".join(sorted(tmp)))

S=sorted(S)
S_key=list(set(S))
count=[0]*len(S_key)
S_dict=dict(zip(S_key,count))


for s in S:
    total+=S_dict[s]
    S_dict[s]+=1

print(total)