get_string(String) :-
  current_input(Input),
  read_string(Input, '\n', '', _, String).

get_number(Number) :-
  get_string(String),
  number_string(Number, String).

dp([], -1000000000000, -1000000000000, -1000000000000, 0, -1000000000000, -1000000000000).
dp([XS|TL], A, B, C, D, E, F) :-
  number_string(X, XS),
  dp(TL, A1, B1, C1, D1, E1, F1),
  A is D1 + X,
  B is E1 + X,
  C is F1 + X,
  D is A1,
  E is max(B1, D1),
  F is max(C1, E1).

main :-
  get_number(N),
  get_string(S),
  split_string(S, ' ', '', L),
  dp(L, A, B, C, D, E, F),
  (N mod 2 =:= 0 ->
    X is max(B, D);
    X is max(C, E)),
  write(X).