Hide

Problem I
Integer Sum

You are given an array $A$ of $N$ integers. Choose a subset of the elements (each element can be chosen at most once) such that, if you write all chosen numbers in decimal notation (without leading zeros; the number $0$ is written as 0) and count how many times each digit 09 appears, then every digit appears at most twice.

To become a Chad like “thosanquyba”, your task is to find the maximum possible sum of the chosen numbers. It is allowed to choose an empty subset (with sum $0$).

Input

The first line contains an integer $N$ ($1 \le N \le 100$). The second line contains $N$ integers $A_1, A_2, \dots , A_N$ ($0 \le A_i \le 10^9$).

Output

Output a single integer: the maximum possible sum.

Sample 1 Explanation

One optimal subset is $\{ 11, 22, 345, 909\} $ with sum $11+22+345+909=1287$. In this subset, each digit 09 appears at most twice.

Sample Input 1 Sample Output 1
6
11 12 21 22 345 909
1287

Please log in to submit a solution to this problem

Log in