#K95417. Sum of Two Largest Distinct Integers

    ID: 38859 Type: Default 1000ms 256MiB

Sum of Two Largest Distinct Integers

Sum of Two Largest Distinct Integers

You are given a list of integers. Your task is to compute the sum of the two largest distinct integers in the list.

If the list contains fewer than two distinct integers, output the single largest integer. If the list is empty, output \(-1\).

Example:

  • For the input [4, 1, 7, 7, 3, 3, 5], the two largest distinct integers are \(7\) and \(5\), so the output is \(7+5=12\).

inputFormat

The input is read from stdin and is formatted as follows:

  1. The first line contains a single integer \(n\), representing the number of elements in the list.
  2. The second line contains \(n\) space-separated integers.

If \(n=0\), it means the list is empty.

outputFormat

Output a single integer to stdout following the rules described above.

## sample
7
4 1 7 7 3 3 5
12