Problem p03413 (python)

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

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(i,N):
        if j==i:
            test=A[i]
            if eval<test:
                eval=test
                L,R=i,i
        elif (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
print(N-1-R+L+(R-L)//2)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
        
if L!=R:
    print(2)

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

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(N):
        if (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
print(N-1-R+L+(R-L)//2)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

A=A[L:R+1]
for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
print(2)

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

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(N):
        if (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
#print(L,R)

for i in range(N-1,R,-1):
    print(i+1)

for i in range(L):
    print(1)

A=A[L:R+1]
for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
print(2)

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

even=[0 for i in range(N)]
odd=[0 for i in range(N)]
even[0]=max(0,A[0])
for i in range(1,N):
    if i%2==1:
        even[i]=even[i-1]
        odd[i]=odd[i-1]+max(0,A[i])
    else:
        even[i]=even[i-1]+max(0,A[i])
        odd[i]=odd[i-1]

eval=-10**20
L=-1
R=-1
for i in range(N):
    for j in range(N):
        if (j-i)%2==0:
            if i%2==0:
                test=even[j]-even[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j
            else:
                test=odd[j]-odd[i-1]*(i!=0)+A[j]*(A[j]<0)+A[i]*(A[i]<0)
                if eval<test:
                    eval=test
                    L,R=i,j

print(eval)
#print(L,R)

for i in range(N-1,R-1,-1):
    print(i+1)

for i in range(L-1):
    print(1)

A=A[L:R+1]
for i in range(L+2,R-1,2):
    if A[i]>0:
        print(2)
    else:
        print(3)
print(2)