LogiQuest

189. Pairs with Equal Digit Sum

MediumHash Map

Among pairs of numbers with the same digit sum, print the maximum value of a[i] + a[j] (i ≠ j), or -1 if no two numbers share a digit sum.

Input format

Line 1: n Line 2: n positive integers

Output format

The maximum pair sum, or -1.

Example 1

Input

4
18 43 36 13

Output

54

Example 2

Input

3
10 12 19

Output

-1

Constraints

1 ≤ n ≤ 10⁵

Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.

Loading the MyLoginn IDE…