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

Fixed submission:
N=int(input())
print(((N-1)*N)//2)

Buggy submission (verdict: Runtime Error):
print(((N-1)*N)/2)

Buggy submission (verdict: Runtime Error):
N=int(input())
n=list(range(N-1))
print(sum(n))
Problem p02945 (python)

Fixed submission:
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):
a,b=int(input().split())
print(max(a+b,a-b,a*b))
Problem p02947 (python)

Fixed submission:
from collections import Counter

N=int(input())
dic={}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]+=1
    else:
        dic[sorted_s]=1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N=int(input())
dic＝{}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]+=1
    else:
        dic[sorted_s]=1

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

N=int(input())
dic＝{}

ans=0

for i in range(N):
    si=input()
    # ci=Counter(si)
    # c=sorted(ci.elements())
    # c=sorted(Counter(si).elements())
    sorted_s=''.join(sorted(Counter(si).elements()))
    if sorted_s in dic:
        ans+=dic[sorted_s]
        dic[sorted_s]]+=1
    else:
        dic[sorted_s]=1

print(ans)
Problem p03151 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()

p=0

ori_d=[]
for i in range (N):
    _d=a[i]-b[i]
    ori_d.append([i,_d])

d=sorted(ori_d,key=lambda x: x[1])
d2=[0]*N
for j in range (N):
    if d[j][1]>=0:
        break
    else:
        p+=abs(d[j][1])
        d2[j]+=1

for k in range (N-1,0,-1):
    if p==0:
        break
    elif d[k][1]<p:
        p-=d[k][1]
        d[k][1]=0
        d2[k]+=1
    else:
        d[k][1]-=p
        p=0
        d2[k]+=1

print(sum(d2))

Buggy submission (verdict: Runtime Error):
N=input()
a=list(map(int,input().split()))
b=list(map(int,input().split()))
if sum(a)<sum(b):
    print(-1)
    exit()

count=0

d=[]
for i in range (N):
    _d=a[i]-b[i]
    d.append(_d,i)
print(d)
Problem p03261 (python)

Fixed submission:
N=int(input())
Ws=[]
for n in range(N):
    W=input()
    Ws.append(W)

for w in range(len(Ws)):
    if Ws.count(Ws[w])>=2:
        print("No")
        exit()
        
for x in range (1,len(Ws)):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()

print("Yes")

Buggy submission (verdict: Runtime Error):
N=int(input())
Ws=[]
for n in range(N):
    W=input()
    Ws.append(W)

for w in range(len(Ws)):
    if Ws.count(w)>=2:
        print('No')
        exit()

for x in range (1,N+1):
    if Ws[x][0] != Ws[x-1][-1]:
        print("No")
        exit()
print("Yes")
Problem p03338 (python)

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



ans=0

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)

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

ans=1

for i in range(1,N):
    X=S[:i]
    Y=S[i:]
    setX=set(X)
    setY=set(Y)
    intersectionXY=setX & setY
    _temp=len(intersectionXY)
    if _temp>ans:
        ans=_temp
    else:
        pass
print(ans)
Problem p03611 (python)

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

l=[0]*((10**5)+2)

for v in a:
    l[v]+=1
    l[v+1]+=1
    l[v+2]+=1

print(max(l))

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

l=[0]*10**5+2

for v in a:
    l[v]+=1
    l[v+1]+=1
    l[v+2]+=1

print(max(l))

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

l=sorted(a)

# N=10
# l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if N>=10**4:
    math.
else:
    pass

ans=1

for i in range(N):
    if i>=1 and l[i]==l[i-1]:
        continue
    else:
        t=l[i]
        for j in range(N-i):
            c=l[i+j]
            if abs(c-t)<=2:
                continue
            else:
                _ans=j
                if _ans>ans:
                    ans=_ans
                else:
                    pass
                break
print(ans)

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

l=sorted(a)

# N=10
# l=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if N>=10**3:
    math.


ans=1

for i in range(N):
    if i>=1 and l[i]==l[i-1]:
        continue
    else:
        t=l[i]
        for j in range(N-i):
            c=l[i+j]
            if abs(c-t)<=2:
                continue
            else:
                _ans=j
                if _ans>ans:
                    ans=_ans
                else:
                    pass
                break
print(ans)

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

l=sorted(a)

ans=1
targetindex=0
t=l[targetindex]

for i in range (N-targetindex):
    c=l[targetindex+i]
    _ans=1
    if c-t<=2:
        pass
    else:
        _ans=i
    
        if _ans>ans:
            ans=_ans
            targetindex=targetindex+i
            t=[targetindex]
        else:
            pass
print(ans)

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

l=sorted(a)

ans=1
targetindex=0
t=l[targetindex]

for i in range (N-targetindex):
    c=l[targetindex+i]
    _ans=1
    if c-t<=2:
        pass
    else:
        _ans=i
        
    if _ans>ans:
        ans=_ans
        targetindex=targetindex+i
        t=[targetindex]
    else:
        pass
print(ans)
Problem p03971 (python)

Fixed submission:
N,A,B=map(int,input().split())
S=input()

nowA=0
nowB=0

for s in S:
    if s=='c':
        print('No')
    elif s=='a':
        if nowA+nowB<A+B:
            print('Yes')
            nowA+=1
        else:
            print('No')
    else:
        if nowA+nowB<A+B and nowB<B:
            print('Yes')
            nowB+=1
        else:
            print('No')

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input(),())
S=input()

nowA=0
nowB=0

for s in S:
    if s=='c':
        print('No')
    elif s=='a':
        if nowA+nowB<=A+B:
            nowA+=1
            print('Yes')
        else:
            print('No')
    else:
        if nowA+nowB<=A+B and nowB<=B:
            nowB+=1
            print('Yes')
            nowB+=1
        else:
            print('No')
Problem p02641 (python)

Fixed submission:
x,n = map(int,input().split())

if n != 0:
    p = list(map(int,input().split()))
else:
    print(x)
    exit()

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)

Buggy submission (verdict: Runtime Error):
x,n = map(int,input().split())

p = [int(input()) for i in range(n)]
s = 1000000000

for i in range(1,101):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)
Problem p02702 (python)

Fixed submission:
s=input()
s=s[::-1]

t=0

x=1
cnt=[0]*2019
cnt[0]=1


for i in s:
    t += int(i)*x
    t %= 2019
    x *= 10
    x %= 2019
    cnt[t]+=1

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

print(ans)

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

a=[""]*(len(s)+1)

for i in range(len(s)):
    a[i+1]=a[i]+s[i]

a.pop(0)
ans=0
for i in range(len(s)):
    for j in a:
        if j[i:]!="":
            b=int(j[i:])
            if b%2019==0:
                ans+=1
                
print(ans)
Problem p02732 (python)

Fixed submission:
import collections

n=int(input())
A=list(map(int,input().split()))

a=collections.Counter(A)

total=0
for v in a.values():
    if v>1:
        c=(v*(v-1))//2
        total+=c

for i in A:
    ans=total-(a[i]*(a[i]-1))//2+((a[i]-1)*(a[i]-2))//2
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
 
a = list(map(int,input().split()))
 
total = 0
 
cnt = [0]*n
for i in range(n):
    cnt[a[i]] += 1
    
for i in cnt:
    if i > 0:
        total += (i*(i-1))//2
 
for i in range(n):
    ans = 0
    before = (cnt[a[i]]*(cnt[a[i]]-1))//2
    after = ((cnt[a[i]]-1)*(cnt[a[i]]-2))//2
    
    ans = total - before + after
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())

a = list(map(int,input().split()))

total = 0

cnt = [0]*n
for i in range(n):
    cnt[a[i]] += 1
    
for i in cnt:
    if i > 0:
        total += (i*(i-1))//2

for i in range(n):
    ans = 0
    before = (cnt[a[i]]*(cnt[a[i]]-1))//2
    after = ((cnt[a[i]]-1)*(cnt[a[i]]-2))//2
    
    ans = total - before + after
    print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())

a = list(map(int,input().split()))

total = 0

cnt = [0]*n
for i in range(n):
    cnt[a[i]] += 1
    
for i in cnt:
    total += (i*(i-1))//2

for i in range(n):
    ans = 0
    before = (cnt[a[i]]*(cnt[a[i]]-1))//2
    after = ((cnt[a[i]]-1)*(cnt[a[i]]-2))//2
    
    ans = total - before + after
    print(ans)
Problem p02772 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
   if i%2==0:
       b.append(i)

ans=True       
for i in b:
    if i%3==0 or i%5==0:
        ans=True
    else:
        ans=False
        break
        
if ans:
    print('APPROVED')
else:
    print('DENIED')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

b=[i//2 for i in a if i%2==0]

for j in b:
    if j%3==0 :
        ans=True
    elif j%5==0:
        ans=True
    else:
        ans=False
        break
if ans:
    print('APPROVED')
else:
    print('DENIED')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

b=[i for i in a if i%2==0]

for j in b:
    if j%3==0 or j%5==0:
        ans=True
    else:
        ans=False
        break
if ans:
    print('APPROVED')
else:
    print('DENIED')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))

b=[i for i in a if i%2==0]

for j in b:
    if j%3==0 or j%5==0:
        ans=True
    else:
        print('DENIED')
        exit()
if ans:
    print('APPROVED')
Problem p02995 (python)

Fixed submission:
import fractions

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

a,b,c,d=map(int,input().split())
d1=b//c
d2=b//d
d3=b//lcm(c,d)

d4=(a-1)//c
d5=(a-1)//d
d6=(a-1)//lcm(c,d)

ansb=b-(d1+d2-d3)
ansa=a-1-(d4+d5-d6)
print(ansb-ansa)

Buggy submission (verdict: Runtime Error):
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

a,b,c,d=map(int,input().split())
d1=math.floor(b/c)
d2=math.floor(b/d)
d3=math.floor(b/lcm(c,d))

d4=math.floor((a-1)/c)
d5=math.floor((a-1)/d)
d6=math.floor((a-1)/lcm(c,d))

ansb=b-(d1+d2-d3)
ansa=a-1-(d1+d2-d3)
print(ansb-ansa)

Buggy submission (verdict: Runtime Error):
import math

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

def cnt(x,y,z):
    if x%z==0:
        return (y//z)-(x//z)+1
    else:
        return (y//z)-(x//z)
        
a,b,c,d=map(int,input().split())
s=lcm(c,d)
d1=cnt(a,b,c)
d2=cnt(a,b,d)
d3=cnt(a,b,s)

ans=(b-a+1)-(d1+d2-d3)
print(ans)
Problem p03001 (python)

Fixed submission:
W,H,x,y=map(int,input().split())

if W == x+x and H == y+y:
    print(W*H/2,1)
else:
    print(W*H/2,0)

Buggy submission (verdict: Runtime Error):
W,H,x,y=map(int,input().split())

s=0
if (W-x)*H >= (H-y)*W:
    s=(W-x)*H
else:
    s=(H-y)*W

if W%x==0 and H%y==0:
    print(s,"1")
else:
    print(s,"0")
Problem p03076 (python)

Fixed submission:
l=[]
total=0
a=0
for i in range(5):
    t=int(input())
    if t%10 == 0:
        total +=t
    else:    
        total +=(t//10+1)*10
        a=max(a,10-(t%10))
print(total-a)

Buggy submission (verdict: Runtime Error):
l=[]
total=0
for i in range(5):
    t=int(input())
    if t%10 == 0:
        total +=t
    else:    
        total +=(t//10+1)*10
        b=(t//10+1)*10-t
        l.append(b)
a=max(l)
print(total-a)

Buggy submission (verdict: Runtime Error):
l=[]
total=0
for i in range(5):
    t=int(input())
    if t%10 == 0:
        total +=t
    else:    
        total +=(t//10+1)*10
        l.append((t//10+1)*10-t)
a=max(l)
print(total-a)

Buggy submission (verdict: Runtime Error):
l=[]
total=0
for i in range(5):
    t=int(input())
    if t%10 !=0:
        total +=(t+9)//10*10
        l.append((t+9)//10*10-t)
    else:
        total +=t
a=max(l)
print(total-a)

Buggy submission (verdict: Runtime Error):
l=[]
max=0
total=0
for i in range(5):
    t=int(input())
    if t%10 !=0:
        total +=((t//10)+1)*10
        l.append(t)
    else:
        total +=t
a=min(l,key=lambda x:x%10)

print(total-(10-a%10))
Problem p03087 (python)

Fixed submission:
n,Q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(2,n+1):
    if s[i-2]=='A' and s[i-1]=='C':
        a[i]=a[i-1]+1
    else:
        a[i]=a[i-1]

for i in range(Q):
    l,r=map(int,input().split())
    print(a[r]-a[l])

Buggy submission (verdict: Runtime Error):
n,Q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        a[i+1]=a[i]+1
    else:
        a[i+1]=a[i]

for i in range(Q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy submission (verdict: Runtime Error):
n,Q=map(int,input().split())
s=input()

a=[0]*(n+1)
for i in range(n):
    if s[i]=='A' and s[i+1]=='C':
        a[i+1]=a[i]+1
    else:
        a[i+1]=a[i]

print(a)
for i in range(Q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy submission (verdict: Runtime Error):
n,Q=map(int,input().split())
s=input()

a=['']*(n+1)
for i in range(n):
    a[i+1]=a[i]+s[i]    

for i in range(Q):
    l,r=map(int,input().split())
    q=a[r][l-1:]
    print(q.count('AC'))
Problem p03377 (python)

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

if A <=X  and A+B >= X:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
,B,X=map(int,input().split())

if A <=X  and A+B >= X:
    print('YES')
else:
    print('NO')
Problem p03425 (python)

Fixed submission:
import itertools

n = int(input())

l = [0]*5
for i in range(n):
    s = input()
    if s[0] == "M":
        l[0] += 1
    if s[0] == "A":
        l[1] += 1
    if s[0] == "R":
        l[2] += 1
    if s[0] == "C":
        l[3] += 1
    if s[0] == "H":
        l[4] += 1 

ans = 0
for a,b,c in itertools.combinations(l,3):
    ans += a*b*c

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

n = int(input())

l = [0]*n
for i in range(n):
    s = input()
    if s[0] == "M":
        l[0] += 1
    if s[0] == "A":
        l[1] += 1
    if s[0] == "R":
        l[2] += 1
    if s[0] == "C":
        l[3] += 1
    if s[0] == "H":
        l[4] += 1 

ans = 0
for a,b,c in list(itertools.combinations(l,3)):
    ans += a*b*c

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

n = int(input())

l = [0]*n
for i in range(n):
    s = input()
    if s[0] == "M":
        l[0] += 1
    if s[0] == "A":
        l[1] += 1
    if s[0] == "R":
        l[2] += 1
    if s[0] == "C":
        l[3] += 1
    if s[0] == "H":
        l[4] += 1 

ans = 0
for a in list(itertools.combinations(l,3)):
    c = 1
    for i in a:
        c *=i
    ans += c

print(ans)
Problem p03611 (python)

Fixed submission:
n = int(input())

a = list(map(int,input().split()))

l = [0]*100005 

for i in a:
    l[i] += 1
    
ans = 0
for i in range(1,99999):
    ans = max(ans,l[i] + l[i-1] + l[i+1])

print(ans)

Buggy submission (verdict: Runtime Error):
import collections
n = int(input())

a = list(map(int,input().split()))

a = sorted(a)
b = list(set(a))
c=collections.Counter(a)

ans = 1
for i in range(1,n-1):
    cnt = 0
    if abs(b[i]-b[i-1]) <= 1 and abs(b[i]-b[i+1]) <= 1:
        cnt += c[b[i]] + c[b[i-1]] + c[b[i+1]]
        
    ans = max(ans,cnt)

print(ans)
Problem p03644 (python)

Fixed submission:
n=int(input())

for i in range(8):
    if 2**i <= n:
        ans=2**i

print(ans)

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

max=0
for i in range(1,n+1):
    count=0
    x=i
    while i%2 == 0:
        count +=1
        i /=2
        
    if count > max:
        max=count
        ans=x
        
print(ans)
Problem p03695 (python)

Fixed submission:
n = int(input())

a = list(map(int,input().split()))

l = [0]*9


for i in a:
    if i >= 3200:
        l[8] +=1
    else:    
        l[i//400] +=1

b = [i for i in l[:8] if i > 0]
mx = 0
mn = 0

if len(b) >= 1:
    mx = len(b)+l[8]
    mn = len(b)
else:
    mx = len(b)+l[8]
    mn = 1
    
print(mn,mx)

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

a = list(map(int,input().split()))

l = [0]*9

for i in a:
    
    l[i//400] +=1

b = [i for i in l[:8] if i > 0]

mx = len(b)+l[8]
mn = len(b)
print(mn,mx)
Problem p02741 (python)

Fixed submission:
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(l[k-1])

Buggy submission (verdict: Runtime Error):
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(l[k+1])
Problem p02807 (python)

Fixed submission:
import math

n = int(input())
x = [0] + list(map(int, input().split()))
mod = 10**9 + 7

s = [pow(i, mod-2, mod) for i in range(0,n+1)]
for i in range(n):
    s[i+1] = (s[i+1] + s[i]) % mod

ans = 0
for i in range(1,n):
    ans += ((x[i+1] - x[i]) * s[i]) % mod
ans = int(ans * math.factorial(n-1)) % mod
print(ans)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
x = [0] + list(map(int, input().split()))
mod = 10**9 + 7

f = [1] * (n+1)
for i in range(1,n+1):
    f[i] = f[i-1] * i % mod

s = [0] + [pow(i, mod-2, mod) for i in range(1,n+1)]
for i in range(n):
    s[i+1] = (s[i+1] + s[i]) % mod

ans = 0.0
for i in range(1,n):
    ans += ((x[i+1] - x[i]) * s[i]) % mod
ans = int(ans * math.factorial(n-1)) % mod
print(ans)
Problem p02814 (python)

Fixed submission:
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def f(x):
    res = 0
    while x % 2 == 0:
        res += 1
        x /= 2
    return res

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = lcm(*[a // 2 for a in A])
ans = math.floor((m + l) / (2*l))
if len(set([f(a) for a in A])) != 1:
    print(0)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = lcm(*[a // 2 for a in A])
if l <= 0 or any([(2*l / a - 1) % 2 != 0 and a % 2 == 0 for a in A]):
    print(0)
else:
    ans = math.floor((m + l) / (2*l))
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = lcm(*[a // 2 for a in A])
if l <= 0 or any([(2*l / a - 1) % 2 != 0 for a in A]):
    print(0)
else:
    ans = math.floor((m + l) / (2*l))
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
A = list(map(int, input().split()))

l = lcm(*[a // 2 for a in A])
ans = math.floor((m + l) / (2*l))
if any([(2*l / a - 1) % 2 != 0 for a in A]):
    print(0)
else:
    print(ans)
Problem p02837 (python)

Fixed submission:
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xys[i].append((x-1, y))

def digitsum(x, base=2):
    ret = 0
    while x>0:
        ret += x % base
        x = x // base
    return ret

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, digitsum(i))
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
xys = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        xys[i].append((x-1, y))

ans = 0
for i in range(1<<n):
    ok = True
    for j in range(n):
        # if jth person may be honest, verify testimony of him.
        if (i>>j) & 1 == 1:
            for xy in xys[j]:
                x, y = xy
                if (i>>x) & 1 != y:
                    ok = False
                    break
        if not ok:
            break
    if ok:
        ans = max(ans, bin(x).count('1'))
print(ans)
Problem p03081 (python)

Fixed submission:
n, q = map(int, input().split())
s = input()
ts, ds = [], []
for _ in range(q):
    t, d = input().split()
    ts.append(t)
    ds.append(d)

def reachable(n, dest):
    for t, d in zip(ts, ds):
        if s[n] == t:
            n = n - 1 if d == 'L' else n + 1
        if n == dest:
            return True
        elif not 0 <= n <= len(s) - 1:
            return False
    return False


l, r = -1, n
while r - l > 1:
    m = l + (r - l) // 2
    if reachable(m, -1):
        l = m
    else:
        r = m
ldel = l + 1

l, r = -1, n
while r - l > 1:
    m = l + (r - l) // 2
    if reachable(m, n):
        r = m
    else:
        l = m
rdel = n - r

print(max(n - (ldel + rdel), 0))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
s = input()
ts, ds = [], []
for _ in range(q):
    t, d = input().split()
    ts.append(t)
    ds.append(d)

def reachable(n, dest):
    for t, d in zip(ts, ds):
        if s[n] == t:
            n = n - 1 if d == 'l' else n + 1
        if n == dest:
            return true
        elif not 0 <= n <= len(s) - 1:
            return false
    return false

l, r = -1, n
while r - l > 1:
    m = l + (r - l) // 2
    if reachable(m, -1): l = m
    else: r = m
ldel = l + 1

l, r = -1, n
while r - l > 1:
    m = l + (r - l) // 2
    if reachable(m, n): r = m
    else: l = m
rdel = n - r

print(max(n - (ldel + rdel), 0))

Buggy submission (verdict: Runtime Error):
10 15
SNCZWRCEWB
B R
R R
E R
W R
Z L
S R
Q L
W L
B R
C L
A L
N L
E R
Z L
S L
Problem p03280 (python)

Fixed submission:
a, b = map(int, input().split())
if a == 2 or b == 2:
    print(1)
else:
    print(a*b - (a + b - 1))

Buggy submission (verdict: Runtime Error):
aa, b = map(int, input().split())
if a == 2 or b == 2:
    print(1)
else:
    print(a*b - (a + b - 1))
Problem p03293 (python)

Fixed submission:
import sys

s = input()
t = input()
n = len(s)
for i in range(n):
    for j in range(n):
        if s[j] == t[(i + j) % n]:
            continue
        else:
            break
    else:
        print('Yes')
        sys.exit(0)
    continue
print('No')

Buggy submission (verdict: Runtime Error):
import sys

s = input()
t = input()
for i in range(len(s)):
    s = s[-1] + s[:-1]
    if t == s:
        print('Yes')
        sys.exit(1)
print('No')

Buggy submission (verdict: Runtime Error):
import sys

s = input()
t = input()
for i in range(len(s)):
    s = s[-1] + s[:-1]
    print(s)
    if t == s:
        print('Yes')
        sys.exit(1)
print('No')