Problem:


Score : 700 points

Problem Statement

You have an integer sequence of length N: a_1, a_2, ..., a_N.

You repeatedly perform the following operation until the length of the sequence becomes 1:

First, choose an element of the sequence.

If that element is at either end of the sequence, delete the element.

If that element is not at either end of the sequence, replace the element with the sum of the two elements that are adjacent to it. Then, delete those two elements.

You would like to maximize the final element that remains in the sequence.

Find the maximum possible value of the final element, and the way to achieve it.

Constraints

All input values are integers.

2 \leq N \leq 1000

|a_i| \leq 10^9

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_N

Output

In the first line, print the maximum possible value of the final element in the sequence.

In the second line, print the number of operations that you perform.

In the (2+i)-th line, if the element chosen in the i-th operation is the x-th element from the left in the sequence at that moment, print x.

If there are multiple ways to achieve the maximum value of the final element, any of them may be printed.

Sample Input 1

5
1 4 3 7 5

Sample Output 1

11
3
1
4
2

The sequence would change as follows:

After the first operation: 4, 3, 7, 5

After the second operation: 4, 3, 7

After the third operation: 11(4+7)

Sample Input 2

4
100 100 -1 100

Sample Output 2

200
2
3
1

After the first operation: 100, 200(100+100)

After the second operation: 200

Sample Input 3

6
-1 -2 -3 1 2 3

Sample Output 3

4
3
2
1
2

After the first operation: -4, 1, 2, 3

After the second operation: 1, 2, 3

After the third operation: 4

Sample Input 4

9
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

5000000000
4
2
2
2
2



Sample input:
5
1 4 3 7 5


Sample output:
11
3
1
4
2

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())

def calc(A):
    if len(A) == 1:
        return [], A[0]
    res = []
    if len(A) % 2 == 0:
        res.append(len(A))
        A = A[:-1]
    if all(a <= 0 for a in A[::2]):
        ma = max(A[::2])
        i = 0
        while A[i] != ma:
            i += 1
            res.append(1)
        j = len(A)
        while i < j-1:
            res.append(j-i)
            j -= 1
        return res, ma

    l = 0; r = len(A)
    while A[0] < 0:
        res.append(1)
        res.append(1)
        A = A[2:]
    v = 0
    while len(A) > 2:
        if A[2] < 0:
            res.append(3)
            if len(A) > 4:
                A = A[:1] + A[4:]
            else:
                A = A[:2]
        else:
            res.append(2)
            A[2] += A[0]
            A = A[2:]
    if len(A) > 1:
        res.append(2)
    return res, A[0]
r, v = calc(A)
if len(A) > 1:
    r0, v0 = calc(A[1:])
    if v < v0:
        r = [1] + r0
        v = v0
print(v, len(r), *r, sep='\n')

Submission status: Wrong Answer

Solution code:
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def E():
    N = ii()
    a = lii()
    even_sum, odd_sum = 0, 0
    for i in range(N):
        if i % 2:
            odd_sum += max(0, a[i])
        else:
            even_sum += max(0, a[i])

    ix = []

    if max(odd_sum, even_sum) > 0:
        if odd_sum > even_sum:
            print(odd_sum)
            ix.append(1)
            a = a[1:]
        else:
            print(even_sum)

        while a[0] < 0:
            ix.append(1)
            ix.append(1)
            a = a[2:]

        while len(a) >= 3:
            if a[2] >= 0:
                ix.append(2)
                a = a[2:]
            else:
                ix.append(3)
                a = [a[0]] + a[3:]

        if len(a) == 2:
            ix.append(2)

    else:
        maxi = np.argmax(a)
        ix = [1] * maxi
        for i in range(N-maxi, 1, -1):
            ix.append(i)

    print(len(ix))
    for i in ix:
        print(i)


if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def E():
    N = ii()
    a = lii()
    even_sum, odd_sum = 0, 0
    for i in range(N):
        if i % 2:
            odd_sum += max(0, a[i])
        else:
            even_sum += max(0, a[i])

    ix = []

    if max(odd_sum, even_sum) > 0:
        if odd_sum > even_sum:
            print(odd_sum)
            ix.append(1)
            a = a[1:]
        else:
            print(even_sum)

        while a[0] < 0:
            ix.append(1)
            ix.append(1)
            a = a[2:]

        while len(a) >= 3:
            if a[2] >= 0:
                ix.append(2)
                a = a[2:]
            else:
                ix.append(3)
                a = [a[0]] + a[3:]

        if len(a) == 2:
            ix.append(2)

    else:
        maxi = np.argmax(a)
        print(a[maxi])
        ix = [1] * maxi
        for i in range(N-maxi, 1, -1):
            ix.append(i)

    print(len(ix))
    for i in ix:
        print(i)


if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def E():
    N = ii()
    a = lii()
    even_sum, odd_sum = 0, 0
    for i in range(N):
        if i % 2:
            odd_sum += max(0, a[i])
        else:
            even_sum += max(0, a[i])

    ix = []

    if max(odd_sum, even_sum) > 0:
        if odd_sum > even_sum:
            print(odd_sum)
            ix.append(1)
            a = a[1:]
        else:
            print(even_sum)

        while a[0] < 0:
            ix.append(1)
            ix.append(1)
            a = a[2:]

        while len(a) >= 3:
            if a[2] > 0:
                ix.append(2)
                a = a[2:]
            else:
                ix.append(3)
                a = [a[0]] + a[3:]

        if len(a) == 2:
            ix.append(2)

    else:
        maxi = np.argmax(a)
        print(a[maxi])
        ix = [1] * maxi
        for i in range(N-maxi, 1, -1):
            ix.append(i)

    print(len(ix))
    for i in ix:
        print(i)


if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def E():
    N = ii()
    a = lii()
    even_sum, odd_sum = 0, 0
    for i in range(N):
        if i % 2:
            odd_sum += max(0, a[i])
        else:
            even_sum += max(0, a[i])

    ix = []
    if odd_sum > even_sum:
        print(odd_sum)
        ix.append(1)
        a = a[1:]
    else:
        print(even_sum)

    while len(a) >= 3:
        if a[2] > 0:
            ix.append(2)
            a = a[2:]
        else:
            ix.append(3)
            a = [a[0]] + a[3:]

    if len(a) == 2:
        ix.append(2)

    print(len(ix))
    for i in ix:
        print(i)


if __name__ == '__main__':
    E()

Submission status: Wrong Answer

Solution code:
N = int(input())
src = list(map(int,input().split()))

use = [a >= 0 for a in src]
all_negative = False
if not any(use):
    all_negative = True
    i = src.index(max(src))
    use[i] = True

opes = []
end = N-1
while not use[end]:
    opes.append(end + 1)
    end -= 1

start = 0
while not use[start]:
    opes.append(1)
    start += 1

arr = [[a,u] for a, u in zip(src[start:end+1], use[start:end+1])]

if not all_negative:
    sum1 = sum(a for a,u in arr[::2] if u)
    sum2 = sum(a for a,u in arr[1::2] if u)
    for i in range(int(sum1>sum2),len(arr),2):
        arr[i][1] = False

if not arr[-1][1]:
    opes.append(len(arr))
    arr.pop()

if not arr[0][1]:
    opes.append(1)
    arr = arr[1:]

def merge_at(i):
    a1,u1 = arr[i-1]
    a2,u2 = arr[i+1]
    #assert u1 == u2
    arr[i] = [a1+a2, u1]
    del arr[i+1]
    del arr[i-1]
    opes.append(i+1)

while True:
    for i in range(2,len(arr)-1,2):
        if not arr[i][1]:
            merge_at(i)
            break
    else:
        break

while len(arr) >= 3:
    merge_at(1)

print(arr[0][0])
print(len(opes))
print(*opes, sep='\n')

Submission status: Wrong Answer

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

sum_even = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(1, N, 2)))
sum_odd  = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(0, N, 2)))

if sum_even == 0 and sum_odd == 0:
    max_ = max(A)
    print(max_)
    index = A.index(max_)
    print(len(A)-1)
    for _ in range(index):
        print(1)
    for j in range(N-index-1):
        print(N - index - j)
    exit()

print(max(sum_even, sum_odd))
EVEN = sum_even >= sum_odd
ans = []

if EVEN:
    A = A[1:]
    ans.append(1)
if len(A)%2 == 0:
    ans.append(len(A))
    A = A[:-1]

while len(A) > 1:
    if A[0] <= 0:
        ans.append(1)
        ans.append(1)
        A = A[2:]
    else:
        if A[2] <= 0:
            ans.append(3)
            A.pop(2)
            if len(A) == 2:
                ans.append(2)
                A.pop(1)
            else:
                ans.append(3)
                A.pop(2)
        else:
            ans.append(2)
            A.pop(1)
            A[0] += A.pop(1)
print(len(ans))
for a in ans:
    print(a)

Submission status: Wrong Answer

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

sum_even = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(1, N, 2)))
sum_odd  = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(0, N, 2)))

if sum_even == 0 and sum_odd == 0:
    max_ = max(A)
    print(max_)
    index = A.index(max_)
    print(len(A)-1)
    for _ in range(index):
        print(1)
    for _ in range(N-index-1):
        print(2)
    exit()

print(max(sum_even, sum_odd))
EVEN = sum_even >= sum_odd
ans = []

if EVEN:
    A = A[1:]
    ans.append(1)
if len(A)%2 == 0:
    ans.append(len(A))
    A = A[:-1]

while len(A) > 1:
    if A[0] <= 0:
        ans.append(1)
        ans.append(1)
        A = A[2:]
    else:
        if A[2] <= 0:
            ans.append(3)
            A.pop(2)
            if len(A) == 2:
                ans.append(2)
                A.pop(1)
            else:
                ans.append(3)
                A.pop(2)
        else:
            ans.append(2)
            A.pop(1)
            A[0] += A.pop(1)
print(len(ans))
for a in ans:
    print(a)

Submission status: Wrong Answer

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

sum_even = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(1, N, 2)))
sum_odd  = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(0, N, 2)))

if sum_even == 0 and sum_odd == 0:
    max_ = max(A)
    print(max_)
    index = A.index(max_)
    print(len(A)-1)
    for _ in range(index):
        print(1)
    for _ in range(N-index-1):
        print(2)
    exit()

print(max(sum_even, sum_odd))
EVEN = sum_even >= sum_odd
print("EVEN", EVEN)
ans = []

if EVEN:
    A = A[1:]
    ans.append(1)
print(ans, A)
if len(A)%2 == 0:
    ans.append(len(A))
    A = A[:-1]
print(ans, A)

while len(A) > 1:
    if A[0] <= 0:
        ans.append(1)
        ans.append(1)
        A = A[2:]
    else:
        if A[2] <= 0:
            ans.append(3)
            A.pop(2)
            if len(A) == 2:
                ans.append(2)
                A.pop(1)
            else:
                ans.append(3)
                A.pop(2)
        else:
            ans.append(2)
            A.pop(1)
            A[0] += A.pop(1)
    print(ans, A)
print(len(ans))
for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mx = max(a)
if mx < 0:
    print(mx)
    i = a.index(mx)
    res = [1]*i + [2]*(n-i-1)
else:
    evn = sum(max(0, i) for i in a[::2])
    odd = sum(max(0, i) for i in a[1::2])
    print(max(evn, odd))
    oe = int(evn < odd)
    res = []
    beg = 0
    while beg%2!=oe or a[beg]<0:
        res.append(1)
        beg += 1
    end = n-1
    while end%2!=oe or a[end]<0:
        res.append(end-beg+1)
        end -= 1
    while beg < end:
        if a[end-2] < 0:
            res.append(end-beg-1)
        else:
            res.append(end-beg)
        end -= 2
print(len(res))
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
use = [False]*n
mx = max(a)
if mx < 0:
    print(mx)
    use[a.index(mx)] = True
else:
    evn = sum(max(i, 0) for i in a[::2])
    odd = sum(max(i, 0) for i in a[1::2])
    print(max(evn, odd))
    for i in range(int(evn<odd), n, 2):
        if a[i] > 0:
            use[i] = True
beg = 0
while not use[beg]:
    beg += 1
res = [1]*beg
end = n-1
while beg < end:
    if use[end]:
        res.append(end-beg)
        end -= 2
        use[end] = True
    else:
        res.append(end-beg+1)
        end -= 1
print(len(res))
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
dp = [0]*(n+2)
cho = [False]*n
mx = max(a)
if mx < 0:
    cho[a.index(mx)] = True
    dp[0] = mx
else:
    for i in range(n)[::-1]:
        if a[i]+dp[i+2] > dp[i+1]:
            dp[i] = a[i]+dp[i+2]
            cho[i] = True
        else:
            dp[i] = dp[i+1]
print(dp[0])
use = [False]*n
i = 0
while i < n:
    if cho[i]:
        use[i] = True
        i += 2
    else:
        i += 1
beg = 0
while not use[beg]:
    beg += 1
res = [1]*beg
end = n-1
while beg < end:
    if use[end]:
        res.append(end-beg)
        end -= 2
        use[end] = True
    else:
        res.append(end-beg+1)
        end -= 1
print(len(res))
for i in res:
    print(i)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

Ae=A[:: 2]
Ao=A[1:: 2]

e=(N+1)//2
o=N//2


a=-10**9-2
p=0
q=0
for i in range(e):
    wa = Ae[i]
    if a < wa:
        a = wa
        p=i
        q=i
    for j in range(i+1,e):
#        print(wa)
        wa+=Ae[j]
        if a < wa:
            a = wa
            p=i
            q=j
#print(a,p,q)

b=-10**9-2
r=0
s=0
for i in range(o):
    wa = Ao[i]
    if b < wa:
        b = wa
        r=i
        s=i
    for j in range(i+1,o):
#        print(wa)
        wa+=Ao[j]
        if b < wa:
            b = wa
            r=i
            s=j
#print(b,r,s)
if a>b:
#    print(a,p,q)
    print(a)
    print(N-2*q+2*p+(q-p)-1)
    for i in range(N-2*q-1):
        print(N-i)
    for i in range(2*p):
        print(1)
    for i in range(q-p):
        print(2)
else:
#    print(b,r,s)
    print(b)
    print(N-2*s-2-1+2*r+s-r+2)
    for i in range(N-2*s-2):
        print(N-i)
    for i in range(2*r+1):
        print(1)
    for i in range(s-r):
        print(2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

Ae=A[:: 2]
Ao=A[1:: 2]

e=(N+1)//2
o=N//2

a=-10**9-2
p=0
q=0
for i in range(e):
    wa = Ae[i]
    for j in range(i+1,e):
        wa+=Ae[j]
#        print(wa)
        if a < wa:
            a = wa
            p=i
            q=j
#print(a,p,q)

b=-10**9-2
r=0
s=0
for i in range(o):
    wa = Ao[i]
    for j in range(i+1,o):
        wa+=Ao[j]
#        print(wa)
        if b < wa:
            b = wa
            r=i
            s=j
#print(b,r,s)
if a>b:
#    print(a,p,q)
    print(a)
    print(N-2*q+2*p+(q-p)-1)
    for i in range(N-2*q-1):
        print(N-i)
    for i in range(2*p):
        print(1)
    for i in range(q-p):
        print(2)
else:
#    print(b,r,s)
    print(b)
    print(N-2*s-2-1+2*r+s-r+2)
    for i in range(N-2*s-2):
        print(N-i)
    for i in range(2*r+1):
        print(1)
    for i in range(s-r):
        print(2)

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  s0=1
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
        s=s0
    else:
      x=0
      s0=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)- 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a) - 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

Ae=A[:: 2]
Ao=A[1:: 2]

e=(N+1)//2
o=N//2

a=0
p=0
q=0
for i in range(e):
    wa = Ae[i]
    for j in range(i+1,e):
        wa+=Ae[j]
#        print(wa)
        if a < wa:
            a = wa
            p=i
            q=j
#print(a,p,q)

b=0
r=0
s=0
for i in range(o):
    wa = Ao[i]
    for j in range(i+1,o):
        wa+=Ao[j]
#        print(wa)
        if b < wa:
            b = wa
            r=i
            s=j
#print(b,r,s)
if a>b:
#    print(a,p,q)
    print(a)
    print(N-2*q+2*p+(q-p)-1)
    for i in range(N-2*q-1):
        print(N-i)
    for i in range(2*p):
        print(1)
    for i in range(q-p):
        print(2)
else:
#    print(b,r,s)
    print(b)
    print(N-2*s-2-1+2*r+s-r+2)
    for i in range(N-2*s-2):
        print(N-i)
    for i in range(2*r+1):
        print(1)
    for i in range(s-r):
        print(2)

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  s0=1
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
        s=s0
    else:
      s0=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)- 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a) - 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

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

Ae=A[:: 2]
Ao=A[1:: 2]

e=(N+1)//2
o=N//2

a=0
p=0
q=0
for i in range(e):
    wa = Ae[i]
    for j in range(i+1,e):
        wa+=Ae[j]
#        print(wa)
        if a < wa:
            a = wa
            p=i
            q=j
#print(a,p,q)

b=0
r=0
s=0
for i in range(o):
    wa = Ao[i]
    for j in range(i+1,o):
        wa+=Ao[j]
#        print(wa)
        if b < wa:
            b = wa
            r=i
            s=j
#print(b,r,s)
if a>b:
    print(a,p,q)
    print(a)
    print(N-2*q+2*p+(q-p)-1)
    for i in range(N-2*q-1):
        print(N-i)
    for i in range(2*p):
        print(1)
    for i in range(q-p):
        print(2)
else:
#    print(b,r,s)
    print(b)
    print(N-2*s-2-1+2*r+s-r+2)
    for i in range(N-2*s-2):
        print(N-i)
    for i in range(2*r+1):
        print(1)
    for i in range(s-r):
        print(2)

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  s0=0
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
        s=s0
    else:
      s0=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)- 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a) - 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
    else:
      s=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)- 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a) - 1 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
    else:
      s=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)-2 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n-1
    for i in range(len(a)-2 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
n=input()
a=[int(i) for i in input().split() ]

def maxa(a):
  x=0
  m=0
  s=1
  g=1
  n=1
  for i in a:
    if x + i >=0:
      x += i
      if x>m:
        m =x
        g=n
    else:
      s=n+1
    n+=1
  return [m,s,g]

if max(a)<=0:
  print(max(a))
  print(len(a)-1)
  f=0
  n=len(a)
  for i in range(len(a)):
    if a[i] ==max(a) and f==0:
      f=1
    else:
      if f==0:
        print(1)
      else:
        print(n)
      n-=1

if maxa(a[0::2])[0]>maxa(a[1::2])[0]:
  print(maxa(a[0::2])[0])
  if maxa(a[0::2])[2]-maxa(a[0::2])[1]>=1:
    print(len(a)-(1+maxa(a[0::2])[2]-maxa(a[0::2])[1]))
    n=0
    for i in range(2*maxa(a[0::2])[1]-2):
      print(1)
      n+=1
    for i in range(maxa(a[0::2])[2]-maxa(a[0::2])[1]):
      print(2)
      n+=2
    m=len(a)-n
    for i in range(len(a)-2 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[0::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1
else:
  print(maxa(a[1::2])[0])
  if maxa(a[1::2])[2]-maxa(a[1::2])[1]>=1:
    print(len(a)-(1+maxa(a[1::2])[2]-maxa(a[1::2])[1]))
    n=0
    for i in range(2*maxa(a[1::2])[1]-1):
      print(1)
      n+=1
    for i in range(maxa(a[1::2])[2]-maxa(a[1::2])[1]):
      print(2)
      n+=2
    m=len(a)-n-1
    for i in range(len(a)-2 -n):
      print(m)
      m-=1
  else:
    print(len(a)-1)
    f=0
    n=len(a)
    for i in range(len(a)):
      if a[i] ==maxa(a[1::2])[0] and f==0:
        f=1
      else:
        if f==0:
          print(1)
        else:
          print(n)
        n-=1

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
par = [(i, a[i]) for i in range(n) if i % 2 == 0]
nepar = [(i, a[i]) for i in range(n) if i % 2 == 1]

def f(b):
    i, tmp = b[0]
    maks = tmp
    pamti = (i, i)
    beg = i
    for it in range(1, len(b)):
        i, val = b[it]
        if tmp > 0:
            tmp += val
        else:
            tmp = val
            beg = i
        if maks < tmp:
            maks = tmp
            pamti = (beg, i)
    return (maks, pamti)

m1, p1 = f(par)
m2, p2 = f(nepar)
print(max(m1, m2))

if m1 > m2:
    i1, i2 = p1
else:
    i1, i2 = p2

op = []
while n - 1 > i2:
    op.append(n - 1)
    n -= 1
while i2 > i1:
    op.append(i2 - 1)
    i2 -= 2
while i1 > 0:
    op.append(0)
    i1 -= 1

print(len(op))
for x in op:
    print(x + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
par = [(i, a[i]) for i in range(n) if i % 2 == 0]
nepar = [(i, a[i]) for i in range(n) if i % 2 == 1]

def f(b):
    i, tmp = b[0]
    maks = tmp
    pamti = (i, i)
    beg = i
    for it in range(1, len(b)):
        i, val = b[it]
        if tmp >= 0:
            tmp += val
        else:
            tmp = val
            beg = i
        if maks < tmp:
            maks = tmp
            pamti = (beg, i)
    return (maks, pamti)

m1, p1 = f(par)
m2, p2 = f(nepar)
print(max(m1, m2))

if m1 > m2:
    i1, i2 = p1
else:
    i1, i2 = p2

op = []
while n - 1 > i2:
    op.append(n - 1)
    n -= 1
while i2 > i1:
    op.append(i2 - 1)
    i2 -= 2
while i1 > 0:
    op.append(0)
    i1 -= 1

print(len(op))
for x in op:
    print(x + 1)