Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02801 (python)

Fixed submission:
C=input()
print(chr(ord(C)+1))

Buggy submission (verdict: Runtime Error):
import numpy as np
from collections import deque

h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
#s = np.array(s)
#s = (s == ".") * 1
def neext(a):
    l, m = a[0], a[1]
    return [(l, m+1), (l, m-1), (l+1, m), (l-1, m)]
def solve(i, j):
    if s[i][j] == '#':
        return 0
    else:
        pre = 0
        p = np.full((h, w), -1)
        check = deque([((i, j), 0)])#(from,now, dist)
        while check:
            now, d = check.popleft()
            p[now[0]][now[1]] = d
            pre = max(pre, d)
            for b, c in neext((now[0], now[1])):
                if b < 0 or c < 0 or b >= h or c >= w:
                    continue 
                if p[b][c] != -1 or s[b][c] == '#':
                    continue
                else:
                    check.append(((b, c), d + 1))
        return pre
ans = 0
for H in range(len(s)):
    for W in range(len(s[0])):
        ans = max(ans, solve(H, W))
print(ans)

Buggy submission (verdict: Runtime Error):
N, M=map(int,input().split())
if M==0:
	print("0 0")
else:
	A=[]
	for i in range(M):
		a=list(map(str,input().split()))
		A.append(a)
	ch=[]
	ac=0
	pe=0
	for i in range(M):
		if A[i][0] in ch:
			continue
		elif A[i][1]=="AC":
			ch.append(A[i][0])
			ac+=1
		else:
			pe+=1
	print(ac,pe)
Problem p02802 (python)

Fixed submission:
N, M=map(int,input().split())
if M==0:
	print("0 0")
else:
	ac=0
	pe=0
	ch=[0]*N
	Ch=[0]*N
	for i in range(M):
		a, b=input().split()
		a=int(a)-1
		if ch[a]==1:
			continue
		elif b=="WA":
			Ch[a]+=1
		else:
			ch[a]=1
			ac+=1
			pe+=Ch[a]
	print(ac,pe)

Buggy submission (verdict: Runtime Error):
N, M=map(int,input().split())
if M==0:
	print("0 0")
else:
	ac=0
	pe=0
	ch=[0]*N
    Ch=[0]*N
	for i in range(M):
		a, b=input().split()
		a=int(a)-1
		if ch[a]==1:
			continue
		elif b=="WA":
			Ch[a]+=1
		else:
			ch[a]=1
			ac+=1
			pe+=Ch[a]
	print(ac,pe)

Buggy submission (verdict: Runtime Error):
N, M=map(int,input().split())
if M==0:
	print("0 0")
else:
	ac=0
	pe=0
	ch=[]
	for i in range(M):
		a, b=input().split()
        a=int(a)
		if a in ch:
			continue
		elif b=="AC":
			ch.append(a)
			ac+=1
		else:
			pe+=1
	print(ac,pe)
Problem p02806 (python)

Fixed submission:
n=int(input())
a=[]
for i in range(n):
	b, c= input().split()
	a.append([b,int(c)])
x=input()
ans=0
for i in range(n):
	if a[n-i-1][0]==x:
		break
	ans+=a[n-i-1][1]
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[]
for i in range(n):
	b = input().split()
	a+=[b]
x=input()
ans=0
for i　in range(n):
	if a[n-i-1][0]=x:
    	break
    ans+=a[n-i-1][1]
print(ans)
Problem p02885 (python)

Fixed submission:
a, b= map(int, input().split())
if a<=2*b:
	print('0')
else:
	print(a-2*b)

Buggy submission (verdict: Runtime Error):
a, b= map(int, intput().split())
if a<=2*b:
	print('0')
else:
	print('a-2*b')
Problem p02898 (python)

Fixed submission:
N, K=map(int, input().split())
A=list(map(int, input().split()))
a=0
for i in A:
	if i>=K:
		a+=1
print(a)

Buggy submission (verdict: Runtime Error):
N, K=map(int, input())
A=list(map(int, input()))
a=0
for i in A:
	if i>=K:
		a+=1
print(a)

Buggy submission (verdict: Runtime Error):
N, K=map(int, input())
a=1
T=0
if a<=N:
	a+=1
	P=input()
    if P>=K:
		T+=1
print(T)
Problem p02899 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
ans=[0]*N
for i in range(N):
	b=a[i]-1
	ans[b]=i+1
for i in range(N):
	print(ans[i])

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input()))
b=a
c=1
if c<=N:
	d=a[c-1]
	b[d-1]='c'
	c+=1
''.join(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input()))
b=a
c=1
if c<=N:
	d=a[c-1]
    b[d-1]=c
    c+=1
' '.join(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c<=N:
	d=a[c-1]
    b[d-1]=c
    c+=1
' '.join(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c<=N:
	d=a[c]
    b[d]=c
    c+=1
' '.join(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c<=N:
	d=a[c]
    b[d]=c
    c+=1
''.join(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c<=N:
	d=a[c]
    b[d]=c
    c+=1
print(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c<=N:
	d=a[c]
    b[d]=1
    c+=1
print(b)

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int, input().split()))
b=a
c=1
if c>=N:
	d=a[c]
    b[d]=1
    c+=1
print(b)
Problem p02909 (python)

Fixed submission:
S=input()
if S=='Sunny':
	print('Cloudy')
elif S=='Cloudy':
	print('Rainy')
else:
	print('Sunny')

Buggy submission (verdict: Runtime Error):
if S=='Sunny':
  print('Cloudy')
elif S=='Cloudy':
  print('Rainy')
else:
  print('Sunny')

Buggy submission (verdict: Runtime Error):
if S=='Sunny':
	print('Cloudy')
elif S=='Cloudy':
	print('Rainy')
else:
	print('Sunny')

Buggy submission (verdict: Runtime Error):
if S=='Sunny':
	print('Cloudy')
elif S=='Cloudy':
	print('Rainy')
else:
	print('Sunny')
Problem p02910 (python)

Fixed submission:
S=input()
a=S[::2]
b=S[1::2]
if 'L' not in a:
	if 'R' not in b:
		print('Yes')
	elif 'R' in b:
		print('No')
elif 'L' in a:
	print('No')

Buggy submission (verdict: Runtime Error):
S=input()
a=S[::2]
b=S[1::2]
if 'L' not in a:
	if 'R' not in b:
		print('Yes')
    else:
		print('No')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
S=input()
a=S[::2]
b=S[1::2]
if 'L' not in a:
	if 'R' not in b:
		print('Yes')
    else:
    	print('No')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
S
a=S[::2]
b=S[1::2]
if 'L' not in a:
	pass
	if 'R' not in b:
		print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
a=S[::2]
b=S[1::2]
if 'L' not in a:
	pass
	if 'R' not in b:
		print('Yes')
else:
	print('No')
Problem p02921 (python)

Fixed submission:
S=input()
T=input()
ans=0
if S[0]==T[0]:
    ans+=1
if S[1]==T[1]:
    ans+=1
if S[2]==T[2]:
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
int(ans)=0
if S[0]==T[0]:
	ans += 1
if S[1]==T[1]:
	ans += 1
if S[2]==T[2]:
	ans += 1
ans

Buggy submission (verdict: Runtime Error):

ans=0
if S[0]==T[0]:
	ans += 1
if S[1]==T[1]
	ans += 1
if S[2]==T[2]
	ans += 1
ans

Buggy submission (verdict: Runtime Error):
S=input()
T=input()
ans=0
if S[0]==T[0]:
	ans += 1
if S[1]==T[1]
	ans += 1
if S[2]==T[2]
	ans += 1
ans
Problem p02922 (python)

Fixed submission:
A, B=map(int, input().split())
a=(B-1)/(A-1)
b=(B-1)//(A-1)
if a==b:
    print(b)
else:
	print(b+1)

Buggy submission (verdict: Runtime Error):
A, B=map(int, input().split())
if (B-1)/(A-1)==(B-1)//(A-1):
	print((B-1)/(A-1))
else:
	ptint((B-1)//(A-1)+1)

Buggy submission (verdict: Runtime Error):
A,B=map(int,input())
if (B-1)/(A-1)==(B-1)//(A-1):
	print((B-1)/(A-1))
else:
	ptint((B-1)//(A-1)+1)
Problem p02972 (python)

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
ans = [0 for i in range(N)]
ans2 = []
for i in range(N):
    p = N - 1 - i
    if a[p] != sum(ans[p::p + 1]) % 2:
        ans[p] = 1
        ans2.append(str(p + 1))
print(sum(ans))
print(" ".join(ans2))

Buggy submission (verdict: Runtime Error):
import numpy as np

N = int(input())
a = list(map(int, input().split()))
ans = list(np.zores(N))
ans2 = []
for i in range(N):
    p = N - 1 - i
    if a[p] != sum(ans[p::p + 1]) % 2:
        ans[p] = 1
        ans2.append(str(p + 1))
print(sum(ans))
print(" ".join(ans2))
Problem p02783 (python)

Fixed submission:
h,a = map(int, input().split())

print((h+a-1)//a)

Buggy submission (verdict: Runtime Error):
h,a = map(input().split())

print((h+a-1)//a)
Problem p03341 (python)

Fixed submission:
def solve():
    N = int(input())
    S = input()

    AW = [0]*(N+1)
    AE = [0]*(N)

    wcount = 0
    ecount = 0
    for i in range(N):
        if S[i] == "W":
            wcount += 1
        else:
            ecount += 1
        AW[i] = wcount
        AE[i] = ecount

    MIN = 1000000

    for i in range(N):
        tmp = 0
        tmp += AW[i-1]
        tmp += AE[-1] - AE[i]
        MIN = min(MIN, tmp)
    print(MIN)

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    N = int(input())
    S = input()

    AW = [0]*(N+1)
    AE = [0]*(N)

    wcount = 0
    ecount = 0
    for i in range(N):
        if S[i] == "W":
            wcount += 1
        else:
            ecount += 1
        AW[i] = wcount
        AE[i] = ecount

    MIN = 1000000

    for i in range(N):
        tmp = 0
        tmp += AW[i-1]
        tmp += AE[-1] - AE[i]
        MIN = min(MIN, tmp)
    print(MIN)

if __name__ == "__main__":
    local_test()
    solve()
Problem p03342 (python)

Fixed submission:
import math
def solve():
    global N, A, PA, XA, i
    N = int(input())
    A = list(map(int, input().split()))

    PA = [0]*(N+1)
    XA = [0]*(N+1)
    PA[0] = A[0]
    XA[0] = A[0]

    for i in range(1,N):
        PA[i] = PA[i-1] + A[i]
        XA[i] = XA[i-1] ^ A[i]

    count = 0
    for i in range(N):
        r = bs(i, N, solver) - 1
        count += r-i+1
    print(count)

def bs(ng, ok, solver):  # binary search for integer set
    """
    input:
        ng: max number known to be ng. default -1
        ok: min number known to be ok. default max number + 1
    output:
        the number that is OK firstly
    """
    while math.fabs(ok-ng) > 1:
        mid = (ok+ng)//2
        if solver(mid):
            ok = mid
        else:
            ng = mid
    return ok

def solver(x):
    if PA[x] - PA[i-1] == XA[x] ^ XA[i-1]:
        return False
    else:
        return True

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
def solve():
    global N, A, PA, XA, i
    N = int(input())
    A = list(map(int, input().split()))

    PA = [0]*(N+1)
    XA = [0]*(N+1)

    PA[0] = A[0]
    XA[0] = A[0]

    for i in range(1,N):
        PA[i] = PA[i-1] + A[i]
        XA[i] = XA[i-1] ^ A[i]

    # print(PA)
    # print(XA)

    count = 0
    for i in range(N):
        r = bs(i, N, solver) - 1
        # print("i, r, r-i+1", i, r, r-i+1)
        count += r-i+1
    print(count)

def bs(ng, ok, solver):  # binary search for integer set
    """
    input:
        ng: max number known to be ng. default -1
        ok: min number known to be ok. default max number + 1
    output:
        the number that is OK firstly
    """
    while math.fabs(ok-ng) > 1:
        mid = (ok+ng)//2
        if solver(mid):
            ok = mid
        else:
            ng = mid
    return ok

def solver(x):
    if PA[x] - PA[i-1] == XA[x] ^ XA[i-1]:
        return False
    else:
        return True

if __name__ == "__main__":
    solve()
Problem p03363 (python)

Fixed submission:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

IN = 'sample-1.in'  # sample case for local test
def local_test():
    try:
        from pcm.utils import set_stdin
        import sys
        import os
        if len(sys.argv) == 1:
            set_stdin(os.path.dirname(__file__) + '/test/' + IN)
    except:
        pass


import sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    CS = [0]*(N+1)

    for n in range(N):
        if n >= 1:
            CS[n+1] = CS[n] + A[n]
        else:
            CS[n+1] = A[n]

    res = 0
    for v in Counter(CS).values():
        if v >= 2:
            res += v*(v-1)//2

    print(res)

if __name__ == "__main__":
    local_test()
    solve()

Buggy submission (verdict: Runtime Error):
import sys
import os
import time
import re
from pydoc import help
import string
import math
import numpy as np
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    CS = [0]*(N+1)

    for n in range(N):
        if n >= 1:
            CS[n+1] = CS[n] + A[n]
        else:
            CS[n+1] = A[n]

    res = 0
    for v in Counter(CS).values():
        if v >= 2:
            res += v*(v-1)//2

    print(res)

if __name__ == "__main__":
    local_test()
    solve()
Problem p03469 (python)

Fixed submission:
s = input()
 
print('2018' + s[4:])

Buggy submission (verdict: Runtime Error):
s = input()
 
print(2018 + s[5:])

Buggy submission (verdict: Runtime Error):
s = int(input())

print(2018 + s[5:])
Problem p03471 (python)

Fixed submission:
# input
N, Y = map(int, input().split())

def solve():
    y = Y//1000
    if Y%1000 != 0:
        print('-1 -1 -1')
        return

    flag = False
    for i in range(2*10**3+1):
        for j in range(10**3+1):
            if y - 10*i - 5*j == N - i - j and N-i-j >= 0:
                print(i, j, N - i - j)
                return

    print('-1 -1 -1')


if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
# input
N, Y = map(int, input().split())

def solve():
    y = Y//1000
    if Y%1000 != 0:
        print('-1 -1 -1')
        return

    dp = DP(N, y+1, False)
    dp[0][1] = [1,0,0]
    dp[0][5] = [0,1,0]
    dp[0][10] = [0,0,1]

    for n in range(N-1):
        for m in range(y):
            if m+1 <= y and dp[n][m]:
                tmp = dcopy(dp[n][m])
                dp[n+1][m+1] = tmp
                dp[n+1][m+1][0] += 1
            if m+5 <= y and dp[n][m]:
                tmp = dcopy(dp[n][m])
                dp[n+1][m+5] = tmp
                dp[n+1][m+5][1] += 1
            if m+10 <= y and dp[n][m]:
                tmp = dcopy(dp[n][m])
                dp[n+1][m+10] = tmp
                dp[n+1][m+10][2] += 1

    if dp[N-1][y]:
        print(' '.join(map(str, dp[N-1][y][::-1])))
    else:
        print('-1 -1 -1')


if __name__ == "__main__":
    solve()
Problem p03559 (python)

Fixed submission:
from bisect import bisect_left, bisect_right, insort_left, insort_right

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(lambda x: int(x)-1, input().split())))


    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]

    print(count)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(lambda x: int(x)-1, input().split())))


    BC = []
    for i in range(N):
        b = B[i]
        BC.append(N - bisect_left(C, b))

    Cum = []
    S = sum(BC)
    tmp = S
    for i in range(N):
        Cum.append(tmp)
        tmp -= BC[i]
    Cum.append(0)

    count = 0
    for i in range(N):
        a = A[i]
        count += Cum[bisect_right(B, a)]

    print(count)


if __name__ == "__main__":
    main()
Problem p03657 (python)

Fixed submission:
def main():
    A, B = map(int, input().split())

    if (A%3 == 0) or (B%3 == 0) or ((A+B)%3 == 0):
        print("Possible")
    else:
        print("Impossible")

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())

    tree = [[] for i in range(N)]
    for n in range(N-1):
        a, b = map(lambda x: int(x)-1, input().split())
        tree[a].append(b)
        tree[b].append(a)

    # print(np.array(tree))

    Q = [(x, [0, x], 0) for x in tree[0]]
    reached = [1] + [0]*(N-2) + [0]
    while len(Q) > 0:
        new_pos, root, cost = Q.pop()
        reached[new_pos] = 1

        if new_pos == N-1:
            break

        #add to Q
        for p in tree[new_pos]:
            new_root = root[:]
            if reached[p] == 0:
                new_root.append(p)
                Q.append((p, new_root, cost+1))

    l = math.ceil(len(root)/2) - 1
    r = l + 1

    # print(root, l, r)
    tree[root[l]].remove(root[r])
    tree[root[r]].remove(root[l])
    # print(tree, tree)

    F = tree[0]
    S = tree[N-1]

    reached = [1] + [0]*(N-2) + [1]
    while True:
        if len(F) == 0:
            print("Snuke")
            break
        else:
            pos = F.pop()
            reached[pos] = 1
            for p in tree[pos]:
                if reached[p] == 0:
                    F.append(p)

        if len(S) == 0:
            print("Fennec")
            break
        else:
            pos = S.pop()
            reached[pos] = 1
            for p in tree[pos]:
                if reached[p] == 0:
                    S.append(p)



if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N, K = map(int, input().split())
    L = list(map(int, input().split()))
    L.sort(reverse=True)

    print(sum(L[:K]))

if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()
Problem p03722 (python)

Fixed submission:
import math 
from collections import defaultdict as dd
def main():
    N, M = map(int, input().split())

    MAP = [[]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1].append((b-1, c))
        E.append((a-1,b-1,c))

    dp = [-float('inf')]*N
    dp[0] = 0
    updated = set([0])
    for count in range(1, 2*N+1):  # N
        preupdated = list(updated)
        updated = set([])
        for a in preupdated:
            for b,c in MAP[a]:
                if max(dp[b], dp[b]) < dp[a] + c:
                    updated.add(b)
                    dp[b] = dp[a] + c
        if count == N-1:
            tmp = dp[N-1]

    # print(tmp, dp[N-1])
    if dp[N-1] == tmp:
        print(tmp)
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()

Buggy submission (verdict: Runtime Error):
from collections import defaultdict as dd
def main():
    N, M = map(int, input().split())

    MAP = [[0]*N for x in range(N)]
    E = []
    for m in range(M):
        a,b,c = map(int, input().split())
        MAP[a-1][b-1] = c
        E.append((a-1,b-1,c))

    dp = [-float('inf')]*N
    dp[0] = 0
    updated = set([0])
    for count in range(1, 2*N+1):  # N
        preupdated = list(updated)
        updated = set([])
        for e in preupdated:
            a,b,c = E[e]
            if max(dp[b], dp[b]) < dp[a] + c:
                updated.add(b)
                dp[b] = dp[a] + c
        if count == N-1:
            tmp = dp[N-1]

    # print(tmp, dp[N-1])
    if dp[N-1] == tmp:
        print(tmp)
    else:
        print('inf')


if __name__ == "__main__":
    # global stime
    # stime = time.clock()
    main()
Problem p02947 (python)

Fixed submission:
from sys import stdin
import copy

n = int(input())
S = [stdin.readline()[:-1] for i in [0]*(n)]
#S.append(stdin.readline())
s = []
for i in S:
    s.append("".join(sorted(i)))
s.sort()
arr = []
temp = 1
for i in range(n-1):
    if temp>1 and s[i]!=s[i+1]:
        arr.append(temp)
        temp = 1
    if s[i]==s[i+1]:
        temp += 1
if temp>1:
    arr.append(temp)

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

Buggy submission (verdict: Runtime Error):
from sys import stdin
import copy

n = int(input())
S = [stdin.readline()[:-1] for i in [0]*(n-1)]
S.append(stdin.readline())
s = []
for i in S:
    s.append("".join(sorted(i)))
s.sort()
arr = []
temp = 1
for i in range(n-1):
    if temp>1 and s[i]!=s[i+1]:
        arr.append(temp)
        temp = 1
    if s[i]==s[i+1]:
        temp += 1
if temp>1:
    arr.append(temp)
arr.sort()
factorial = [1]
for i in range(arr[-1]+1):
    factorial.append(factorial[i]*(i+1))
comb = [0,0]
for i in range(2,arr[-1]+1):
    comb.append(factorial[i]/(2*factorial[i-2]))
ans = 0
for i in arr:
    ans += comb[i]
print(int(ans))
Problem p03031 (python)

Fixed submission:
from itertools import combinations

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            s[i][j] -= 1
    p = list(map(int,input().split()))
    return n,m,s,p 

def main(n,m,s,p):
    l = [[] for i in range(n)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            l[s[i][j]].append(i)
    ans = 0
    for i in range(n+1):
        for c in combinations(range(n),i):
            temp = [0 for i in range(m)]
            for j in c:
                for k in l[j]:
                    temp[k] += 1
                    temp[k] %= 2
            if temp==p:
                ans += 1
    print(ans)

if __name__=="__main__":
    n,m,s,p = getval()
    main(n,m,s,p)

Buggy submission (verdict: Runtime Error):
from itertools import combinations

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            s[i][j] -= 1
    p = list(map(int,input().split()))
    return n,m,s,p 

def main(n,m,s,p):
    l = [[] for i in range(n)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            l[s[i][j]].append(i)
    ans = 0
    for i in range(n+1):
        for c in combinations(range(n),i):
            temp = [0 for i in range(m)]
            for j in c:
                for k in l[j]:
                    temp[k] += 1
                    temp[k] %= 2
            if temp==p:
                ans += 1
    print(ans)

if __name__=="__main__":
    n,m,s,p = getval()
    main(n,m,s,p)from itertools import combinations

def getval():
    n,m = map(int,input().split())
    s = [list(map(int,input().split())) for i in range(m)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            s[i][j] -= 1
    p = list(map(int,input().split()))
    return n,m,s,p 

def main(n,m,s,p):
    l = [[] for i in range(n)]
    for i in range(m):
        for j in range(1,s[i][0]+1):
            l[s[i][j]].append(i)
    ans = 0
    for i in range(n+1):
        for c in combinations(range(n),i):
            temp = [0 for i in range(m)]
            for j in c:
                for k in l[j]:
                    temp[k] += 1
                    temp[k] %= 2
            if temp==p:
                ans += 1
    print(ans)

if __name__=="__main__":
    n,m,s,p = getval()
    main(n,m,s,p)