#K48917. Max Cookie Sum

    ID: 28527 Type: Default 1000ms 256MiB

Max Cookie Sum

You are given an integer N representing the number of different cookie types and a list of N integers where each integer denotes the number of cookies available of that type. Your task is to select exactly two different types and maximize the total count of cookies collected. If there are fewer than two types available, output 0.

More formally, given a list \(a_1, a_2, \dots, a_N\), find two distinct indices \(i\) and \(j\) such that \(a_i + a_j\) is maximized. If \(N < 2\), then the answer is 0.

Example:

Input:
5
7 3 5 2 9

Output: 16

</p>

inputFormat

The input is given in two lines:

  • The first line contains a single integer N representing the number of cookie types.
  • The second line contains N space-separated integers, where each integer denotes the count of cookies for that type.

outputFormat

Output a single integer which is the maximum sum of cookies by picking two different types. If it is not possible to pick two types, output 0.

## sample
5
7 3 5 2 9
16

</p>