C - Max Even Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

長さ NN の非負整数列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) が与えられます。

AA の異なる 22 要素の和として表せる値の中に偶数が存在するか判定し、存在する場合その最大値を求めてください。

制約

  • 2N2×1052\leq N \leq 2\times 10^5
  • 0Ai1090\leq A_i\leq 10^9
  • AA の要素は相異なる
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN
A1A_1 A2A_2 \ldots ANA_N

出力

AA の異なる 22 要素の和として表せる値の中に偶数が存在しない場合、-1 を出力せよ。

偶数が存在する場合、その最大値を出力せよ。


入力例 1Copy

Copy
3
2 3 4

出力例 1Copy

Copy
6

AA の異なる 22 要素の和として表せる値は 5,6,75,6,7 です。この中に偶数は存在し、その最大値は 66 です。


入力例 2Copy

Copy
2
1 0

出力例 2Copy

Copy
-1

AA の異なる 22 要素の和として表せる値は 11 です。この中に偶数は存在しないので、 -1 を出力してください。

Score : 300300 points

Problem Statement

You are given a sequence A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N) of length NN consisting of non-negative integers.

Determine if there is an even number represented as the sum of two different elements of AA. If it exists, find the maximum such number.

Constraints

  • 2N2×1052\leq N \leq 2\times 10^5
  • 0Ai1090\leq A_i\leq 10^9
  • The elements of AA are distinct.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN
A1A_1 A2A_2 \ldots ANA_N

Output

Print -1 if there is no even number represented as the sum of two different elements of AA.

If such an even number exists, print the maximum such number.


Sample Input 1Copy

Copy
3
2 3 4

Sample Output 1Copy

Copy
6

The values represented as the sum of two distinct elements of AA are 55, 66, and 77. We have an even number here, and the maximum is 66.


Sample Input 2Copy

Copy
2
1 0

Sample Output 2Copy

Copy
-1

The value represented as the sum of two distinct elements of AA is 11. We have no even number here, so -1 should be printed.



2025-04-25 (Fri)
22:29:40 +00:00