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

Fixed submission:

M,K = list(map(int,input().split()))

if M==0:
    if K==0:
        print("0 0")
    else:
        print(-1)
elif M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K==0:
        ans = []
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
        #ans = list(map(str,ans))
        print(*ans)
    elif K<2**M:
        ans = [0,K,0]
        ansc = []
        for i in range(1,2**M):
            if i!=K:
                ansc.append(i)
                
        ans =ans+ansc + [K] +ansc[::-1]
        #ans = list(map(str,ans))
        print(*ans)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):

M,K = list(map(int,input().split()))

if M==0:
    if K==0:
        print("0 0")
    else:
        print(-1)
elif M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K==0:
        ans = []
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
        ans = list(map(str,ans))
        print(*ans)
    elif K<2**M:
        ans = [0,K,0]
        ansc = []
        for i in range(1,2**M):
            if i!=K:
                ansc.append(i)
                
        ans =ans+ansc + [K] + ansb +ansc[::-1]
        ans = list(map(str,ans))
        print(*ans)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):

M,K = list(map(int,input().split()))

if M==0:
    if K==0:
        print("0 0")
    else:
        print(-1)
elif M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K==0:
        ans = []
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
        print(*ans)
    elif K<2**M:
        ans = [0,K,0]
        ansc = []
        for i in range(1,2**M):
            if i!=K:
                ansc.append(i)
                
        ans =ans+ansc + [K] + ansb +ansc[::-1]
        
        print(*ans)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):

M,K = list(map(int,input().split()))

if M==0:
    if K==0:
        print("0 0")
    else:
        print(-1)
elif M==1:
    if K==0:
        print("0 0 1 1")
    else:
        print(-1)
else:
    if K==0:
        ans = []
        for i in range(2**M):
            ans.append(i)
            ans.append(i)
        print(*ans)
    elif K<2**M:
        ans = [0,K,0]
        ansc = ""
        for i in range(1,2**M):
            if i!=K:
                ansc.append(i)
                
        ans =ans+ansc + [K] + ansb +ansc[::-1]
        
        print(*ans)
    else:
        print(-1)
Problem p03061 (python)

Fixed submission:
def gcd(a,b):
	a,b = max(a,b),min(a,b)
	while a%b!=0:
   		a,b = b,a%b
	return b

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

S1 = [A[0]]
s = A[0]
for i in range(1,N-1):
    s=gcd(s,A[i])
    S1.append(s)

S2 = [A[N-1]]
s = A[N-1]
for i in range(1,N-1):
    s=gcd(s,A[N-i-1])
    S2.append(s)

max_gcd = 1
for i in range(N):
    if i==0:
        max_gcd=max(max_gcd,S2[N-2])
    elif i==N-1:
        max_gcd=max(max_gcd,S1[N-2])
    else:
        max_gcd=max(max_gcd,gcd(S1[i-1],S2[N-2-i]))

print(max_gcd)

Buggy submission (verdict: Runtime Error):

def gcd(a,b):
    c=max(a,b)
    d=min(a,b)
    while True:
        if c%d==0:
            return d
        c,d=d,c%d

def gcd_list(A):
    if len(A)==2:
        return gcd(A[0],A[1])
    elif len(A)==1:
        return A[0]
    else:
        return gcd(gcd_list(A[len(A)//2:]),gcd_list(A[:len(A)//2]))
max_gcd=1
for i in range(N):
    max_gcd=max(gcd_list(A[:i]+A[i+1:]),max_gcd)
    
print(max_gcd)

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

def gcd(a,b):
    c=max(a,b)
    d=min(a,b)
    while True:
        c,d=d,c%d
        if c%d==0:
            return d

def gcd_list(A):
    if len(A)==2:
        return gcd(A[0],A[1])
    elif len(A)==1:
        return A[0]
    else:
        return gcd(gcd_list(A[len(A)//2:]),gcd_list(A[:len(A)//2]))
max_gcd=1
for i in range(N):
    max_gcd=max(gcd_list(A[:i]+A[i+1:]),max_gcd)
    
print(max_gcd)
Problem p03095 (python)

Fixed submission:

N=int(input())
S=input()

def atoi(a):
    alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o',
                'p','q','r','s','t','u','v','w','x','y','z']
    return alphabet.index(a)

a_list = [0 for i in range(26)]
for i in range(N):
    a_list[atoi(S[i])]+=1
ans = 1
for i in range(26):
    ans *= (a_list[i]+1)
    ans = ans%(10**9 + 7)
if ans>0:
    ans-=1
else:
    ans=10**9 + 6
print(ans)

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

ans = [0 for i in range(N)]
for i in range(N):
    for j in range(N-i):
        if b[N-i-j-1]==N-i-j:
            del b[N-i-j-1]
            #print(b)
            ans[N-i-1]=N-i-j
            break

for a in ans:
    if a==0:
        flg=False
        break
#print(ans)
if flg:
    for a in ans:
        print(a)
else:
    print(-1)
Problem p03166 (python)

Fixed submission:
import sys

sys.setrecursionlimit(500000)


N,M = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    x,y = list(map(int,input().split()))
    x,y = x-1,y-1
    e_list[x].append(y)

memo = [-1]*N

def DFS(v):
    if memo[v]!=-1:
        return memo[v]
    if len(e_list[v])==0:
        memo[v] = 0
        return 0
    res = 0
    for v1 in e_list[v]:
        res1 = DFS(v1)
        if res<res1+1:
            res = res1+1
    memo[v] = res
    return res

ans = 0
for i in range(N):
    res = DFS(i)
    if res>ans:
        ans = res
print(ans)

Buggy submission (verdict: Runtime Error):

N,M = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    x,y = list(map(int,input().split()))
    x,y = x-1,y-1
    e_list[x].append(y)

memo = [-1]*N

def DFS(v):
    if memo[v]!=-1:
        return memo[v]
    if len(e_list[v])==0:
        memo[v] = 0
        return 0
    res = 0
    for v1 in e_list[v]:
        res1 = DFS(v1)
        if res<res1+1:
            res = res1+1
    memo[v] = res
    return res

ans = 0
for i in range(N):
    res = DFS(i)
    
    if res>ans:
        ans = res
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

N,M = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    x,y = list(map(int,input().split()))
    x,y = x-1,y-1
    e_list[x].append(y)

@lru_cache(maxsize=500000)
def DFS(v):
    if len(e_list[v])==0:
        return 0
    res = 0
    for v1 in e_list[v]:
        res1 = DFS(v1)
        if res<res1+1:
            res = res1+1
    return res

ans = 0
for i in range(N):
    res = DFS(i)
    
    if res>ans:
        ans = res
print(ans)

Buggy submission (verdict: Runtime Error):
from functools import lru_cache

N,M = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    x,y = list(map(int,input().split()))
    x,y = x-1,y-1
    e_list[x].append(y)

@lru_cache(maxsize=200000)
def DFS(v):
    if len(e_list[v])==0:
        return 0
    res = 0
    for v1 in e_list[v]:
        res1 = DFS(v1)
        if res<res1+1:
            res = res1+1
    return res

ans = 0
for i in range(N):
    res = DFS(i)
    
    if res>ans:
        ans = res
print(ans)
Problem p03210 (python)

Fixed submission:
X = int(input())
if X==3 or X==5 or X==7:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
X = int(raw_input())
if X==3 or X==5 or X==7:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
X = int(raw_input())
if X==3 or X==5 or X==7:
    print("Yes")
else:
    print("No")
Problem p03241 (python)

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

if N==1:
    print(M)
else:
    ans = 1
    for i in range(1,10**5):
        if i*i>M:
            break
        if M%i==0:
            j=0
            k=0
            if M//i>=N:
                j=i
            if i>=N:
                k=M//i
            ans = max(j,k,ans)

    print(ans)

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

if N==1:
    print(M)
else:
    ans = 1
    for i in range(1,10**5):
        if i*i>M:
            break
        if M%i==0:
            j = max(i.M//i)
            if j>=N:
                ans = max(j,ans)

    print(ans)
Problem p03246 (python)

Fixed submission:
import numpy as np

n = int(raw_input())
v = map(int,raw_input().split())

seta= [0 for i in range(1,10**5 +1)]
setb= [0 for i in range(1,10**5 +1)]


for i in range(n/2):
    seta[v[2*i]-1]+=1
    setb[v[2*i+1]-1]+=1
seta = np.array(seta)
setb = np.array(setb)

argseta=seta.argsort()[::-1]
argsetb=setb.argsort()[::-1]


if argseta[0]!=argsetb[0]:
    print n - max(seta) - max(setb)
else:
    if setb[argseta[0]]-seta[argseta[1]]<setb[argsetb[0]]-setb[argsetb[1]]:
        print n - max(setb) - seta[argseta[1]]
    else:
        print n - max(seta) - setb[argsetb[1]]

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

n = int(raw_input())
v = map(int,raw_input().split())

seta= [0 for i in range(1,10**5 +1)]
setb= [0 for i in range(1,10**5 +1)]


for i in range(n/2):
    seta[v[2*i]]+=1
    setb[v[2*i+1]]+=1
seta = np.array(seta)
setb = np.array(setb)

argseta=seta.argsort()[::-1]
argsetb=setb.argsort()[::-1]

if argseta[0]!=argsetb[0]:
    print n - max(seta) - max(setb)
else:
    if setb[argseta[0]]-seta[argseta[1]]<setb[argsetb[0]]-setb[argsetb[1]]:
        print n - max(setb) - seta[argseta[1]]
    else:
        print n - max(seta) - setb[argsetb[1]]
Problem p03262 (python)

Fixed submission:
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
  
def gcd_list(y):
    if len(y)==1:
        return y[0]
    if len(y)==2:
        return gcd(y[0],y[1])
    else:
        return gcd(gcd_list(y[:len(y)/2]),gcd_list(y[len(y)/2:]))

N,X= map(int,raw_input().split())

x = map(int,raw_input().split())

for i in range(N):
    x[i]= abs(x[i]-X)

print gcd_list(x)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    while b > 0:
        a, b = b, a%b
    return a
  
def gcd_list(y):
    if len(y)==1:
        return y[0]
    if len(y)==2:
        return gcd(y[0],y[1])
    else:
        return gcd(y[0],gcd_list(y[1:]))

N,X= map(int,raw_input().split())

x = map(int,raw_input().split())

for i in range(N):
    x[i]= abs(x[i]-X)

print gcd_list(x)
Problem p03273 (python)

Fixed submission:

H,W= map(int,raw_input().split())

M = []
for i in range(H):
	M.append(raw_input())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	if flag_list_H[i]:
		answer = ""
		for j in range(W):
			if flag_list_W[j]:
				answer+=M[i][j]
		print answer

Buggy submission (verdict: Runtime Error):

H,W= map(int,raw_input().split())

M = []
for i in range(H):
	M.append(raw_input().split())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	answer = ""
	for j in range(W):
		if flag_list_H[i] and flag_list_W[j]:
			answer+=M[i][j] + " "
	print answer[:-1]

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

M = []
for i in range(H):
	M.append(raw_input().split())
	
flag_list_H = []
for i in range(H):
	if '#' in M[i]:
		flag_list_H.append(True)
	else:
		flag_list_H.append(False)

flag_list_W = []
for i in range(W):
	flag = False
	for j in range(H):
		if M[j][i]=='#':
			flag=True
	flag_list_W.append(flag)

for i in range(H):
	answer = ""
	for j in range(W):
		if flag_list_H[i] and flag_list_W[j]:
		answer+=M[i][j] + " "
	print answer[:-1]
Problem p03294 (python)

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

s=0
for i in a:
  s+=i-1
print s

Buggy submission (verdict: Runtime Error):

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

ans = 0
for aa in a:
    ans+=a-1
    
print(ans)
Problem p03308 (python)

Fixed submission:
N = int(raw_input())

A = map(int,raw_input().split())

print max(A)-min(A)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

A = map(int,raw_input().split())

print max(A)-min(B)
Problem p03337 (python)

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

M = max([A+B,A-B,A*B])
print M

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
A = map(int,raw_input().split())

all_count = 0
for i in range(N):
	a_x = A[i]
	a_s = A[i]
	count=1
	flag = True
	for j in range(N-i-1):
		if flag:
			a_x = a_x ^ A[i+j+1]
			a_s = a_x | A[i+j+1]
			if a_x == a_s:
				count+=1
			else:
				flag=False
	all_count += count
	
print all_count

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

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if i==0:
	
		if S[i]=='W':
			num+=1
	else:
		if S[i]=='W':
			num+=1
		else:
			num-=1
	score_list.append(num)
	
print min(score_list)
Problem p03339 (python)

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

num = S[1:].count('E')
score_list = []
score_list.append(num)

for i in range(N-1):
	if S[i]=='W':
		num+=1
	if S[i+1]=='E':
		num-=1
	score_list.append(num)
	
print min(score_list)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())

S = raw_input()

num = S.count('E')
score_list = []
score_list.append(num)

for i in range(N-1)
	if S[i]=='W':
		num+=1
	else:
		num-=1
	score_list.append(num)
print min(score_list)
Problem p03361 (python)

Fixed submission:
H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
				if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
				if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
				if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag==False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

Buggy submission (verdict: Runtime Error):
H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
				if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
				if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
				if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag=False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

Buggy submission (verdict: Runtime Error):

H,W = map(int,raw_input().split())
 
s = []
for i in range(H):
	s.append(raw_input())
 
flag=True
for i in range(H):
	for j in range(W):
 
		if s[i][j]=='#':
			local_flag=False
			if i+1<H:
			  if s[i+1][j]=='#':
					local_flag=True
			if j+1<W:
			  if s[i][j+1]=='#':
					local_flag=True
			if i-1>=0:
			  if s[i-1][j]=='#':
					local_flag=True
			if j-1>=0:
				if s[i][j-1]=='#':
					local_flag=True
			if local_flag=False:
				flag=False
if flag:
	print 'Yes'
else:
	print 'No'

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

s = []
for i in range(H):
  s.append(raw_input())

flag=True
for i in range(H):
  for j in range(W):

    if s[i][j]=='#':
    	local_flag=False
		if i+1<H:
          if s[i+1][j]=='#':
            local_flag=True
        if j+1<W:
          if s[i][j+1]=='#':
            local_flag=True
        if i-1>=0:
          if s[i-1][j]=='#':
            local_flag=True
        if j-1>=0:
          if s[i][j-1]=='#':
            local_flag=True
        if local_flag=False:
          flag=False
if flag:
  print 'Yes'
else:
  print 'No'
Problem p03482 (python)

Fixed submission:

S = input()
l=len(S)
if l%2==0:
    count=0
    s=S[int(l/2)]
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+i]!=s:
            break
        count+=1
    print(int(l/2)+count)
else:
    s=S[int(l/2)]
    count=0
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+1+i]!=s:
            break
        count+=1
    print(int(l/2)+1+count)

Buggy submission (verdict: Runtime Error):

S = input()
l=len(S)
if l%2==0:
    s=S[int(l/2)]
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+i]!=s:
            break
    print(int(l/2)+i)
else:
    s=S[int(l/2)]
    for i in range(int(l/2)):
        if S[int(l/2)-1-i]!=s or S[int(l/2)+1+i]!=s:
            break
    print(int(l/2)+1+i)
Problem p03502 (python)

Fixed submission:

N=input()
s=0
for i in N:
    s+=int(i)
    
if int(N)%s==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):

N=input()
s=0
for i in N:
    s+=int(i)
    
if N%s==0:
    print("Yes")
else:
    print("No")
Problem p03504 (python)

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

P = [[] for i in range(C)]

for i in range(N):
    s,t,c = list(map(int,input().split()))
    P[c-1].append([s,"S"])
    P[c-1].append([t,"T"])

P = [sorted(sorted(P[i],key=lambda x:x[1]),key=lambda x: x[0]) for i in range(C)]
#print(P)
P2 = []

for i in range(C):
    for j in range(len(P[i])):
        if P[i][j][1]=="T":
            if j!=0:
                if P[i][j][0]!=P[i][j-1][0]:
                    P2.append(P[i][j])
            else:
                P2.append(P[i][j])
        else:
            if j!=len(P[i])-1:
                if P[i][j][0]!=P[i][j+1][0]:
                    P2.append([P[i][j][0]-0.5,P[i][j][1]])
            else:
                P2.append([P[i][j][0]-0.5,P[i][j][1]])

P = P2
P = sorted(P,key=lambda x:x[0])

count=0
max_count=0
s_buf = 0
t_buf = 0

prev = -1
for i in range(len(P)):
    if prev!=P[i][0]:
        prev=P[i][0]
        count+=s_buf-t_buf
        s_buf=0
        t_buf=0
        max_count=max(count,max_count)
    if P[i][1]=="S":
        s_buf+=1
    else:
        t_buf+=1
#print(P)
count+=s_buf-t_buf
max_count=max(count,max_count)

print(max_count)

Buggy submission (verdict: Runtime Error):

N,C = list(map(int,input().split()))

prog = [[] for i in range(C)]

for i in range(N):
    s,t,c = list(map(int,input().split()))
    prog[c].append([s,t])

ttable = [0 for i in range(2*(10**5)+2)]
for i in range(C):
    table = [0 for i in range(2*(10**5)+2)]
    for p in prog[i]:
        table[2*p[0]-1]+= 1
        table[2*p[1]]+= -1
    tsum = 0
    for i in range(2*(10**5)+2):
        tsum+=table[i]
        ttable[i]+=tsum
print(max(ttable))
Problem p03569 (python)

Fixed submission:
S = input()

T = []

x_list = []

temp = 0
for i in range(len(S)):
    if S[i]!="x":
        T.append(S[i])
        x_list.append(temp)
        temp=0
    else:
        temp+=1
x_list.append(temp)

U = T[::-1]
flag=False
for i in range(len(T)):
    if T[i]!=U[i]:
        flag=True
        break

if flag:
    print(-1)
else:
    count=0
    for i in range(len(x_list)//2):
        count+=abs(x_list[i]-x_list[len(x_list)-1-i])

    print(count)

Buggy submission (verdict: Runtime Error):

S = input()

T = []

x_list = []

temp = 0
for i in range(len(S)):
    if S[i]!="x":
        T.append(S[i])
        x_list.append(temp)
        temp=0
    else:
        temp+=1
x_list.append(temp)

U = T[::-1]
flag=False
for i in range(len(T)):
    if T[i]!=U[i]:
        flag=True
        break

if flag:
    print(-1)
else:
    count=0
    for i in range(len(x_list)//2):
        count+=abs(x_list[i]-x_list[len(x_list)-i])

    print(count)
Problem p03607 (python)

Fixed submission:
N=int(raw_input())
A = []
for i in range(N):
    A.append(int(raw_input()))

A.sort()
prev=A[0]
count=1
all_count=0
for i in range(1,N):
    if prev==A[i]:
        count+=1
    else:
        prev=A[i]
        all_count+=count%2
        count=1
all_count+=count%2

print all_count

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
A = [0 for i in range(10**9)]

for i in range(N):
    a=int(raw_input())
    A[a-1]=(A[a-1]+1)%2

print(sum(A))

Buggy submission (verdict: Runtime Error):
N=int(raw_input())
A = [0 for i in range(10000000000)]

for i in range(N):
    a=int(raw_input())
    A[a-1]=(A[a-1]+1)%2

print(sum(A))

Buggy submission (verdict: Runtime Error):
N=int(raw_input())

A = [0 for i in range(N)]

for i in range(N):
    a=int(raw_input())
    A[a-1]=(A[a-1]+1)%2

print sum(A)

Buggy submission (verdict: Runtime Error):
N=int(raw_input())

A = [0 for i in range(N)]

for i in range(N):
    a=int(raw_input())
    A[a-1]=(a-1]+1)%2

print sum(A)

Buggy submission (verdict: Runtime Error):
N=int(raw_input())

A = [0 for i in range(N)]

for i in range(N):
    A[int(raw_input())-1]=(A[int(raw_input())-1]+1)%2

print sum(A)
Problem p03645 (python)

Fixed submission:
N,M = list(map(int,input().split()))
path = [[False,False] for i in range(N)]
flag=False
for i in range(M):
    a,b = list(map(int,input().split()))
    if a==N:
        if path[b-1][0]:
            flag=True
            
        path[b-1][1]=True
    if a==1:
        if path[b-1][1]:
            flag=True
            
        path[b-1][0]=True
    if b==N:
        if path[a-1][0]:
            flag=True
            
        path[a-1][1]=True
    if b==1:
        if path[a-1][1]:
            flag=True
            
        path[a-1][0]=True

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):

N,M = list(map(int,input().split()))
path = [[False,False] for i in range(N)]
flag=False
for i in range(M):
    a,b = list(map(int,input().split()))
    if a=N-1:
        if path[b-1][0]:
            flag=True
            
        path[b-1][1]=True
    if a=0:
        if path[b-1][1]:
            flag=True
            
        path[b-1][0]=True
    if b=N-1:
        if path[a-1][0]:
            flag=True
            
        path[a-1][1]=True
    if b=0:
        if path[a-1][1]:
            flag=True
            
        path[a-1][0]=True

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):

N,M = list(map(int,input().split()))
path = [[False,False] for i in range(N)]
flag=False
for i in range(M):
    a,b = list(map(int,input().split()))
    if a=N-1:
        if path[b-1][0]:
            flag=True
            break
        path[b-1][1]=True
    if a=0:
        if path[b-1][1]:
            flag=True
            break
        path[b-1][0]=True
    if b=N-1:
        if path[a-1][0]:
            flag=True
            break
        path[a-1][1]=True
    if b=0:
        if path[a-1][1]:
            flag=True
            break
        path[a-1][0]=True

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")