n = int(input())
a = []
m0 = 0
m1 = 0
ms = 0
for i in range(6):
a.append(int(input()))
a.append(0)
for i in range(6, n):
a[6] = int(input())
if a[0] % 2 == 0 and a[0] > m0:
m0 = a[0]
if a[0] % 2 == 1 and a[0] > m1:
m1 = a[0];
s = 0;
if a[6] % 2 == 0 and m1 > 0:
s = a[6] + m1
if a[6] % 2 == 1 and m0 > 0:
s = a[6] + m0
if s > ms:
ms = s
for j in range(6):
a[j] = a[j + 1]
print(ms)
вот как пробовал на pascal, но не получается с четностью сделать
const s=6;
var
N: integer;
x: integer;
a: array[1..s] of integer;
m: integer;
sm: integer;
i: integer;
ia: integer;
begin
readln(N);
for i:=1 to s do readln(a[i]);
m:=0; sm:=0;
for i:=s+1 to N do begin
readln(x);
if a[1] > m then m := a[1];
if m+x > sm then sm := m+x;
for ia:=1 to s-1 do a[ia]:=a[ia+1];
a[s] := x
end;
writeln(sm)
end.