cswork / OAOpen practice workspace

MicrosoftOA #44

Maximum Sum After Merges

Estimated MediumJudge-ready

Topics (AI-labelled)DP Basics

Two originally adjacent elements may be concatenated in decimal, but each original element can be used at most once, and a concatenated result cannot be concatenated again. Find the maximum possible sum of the final elements.

This site uses a standard input/output protocol.

Input

The first line contains N (1..10000), and the second line contains N integers in 0..200. 0 also takes up one digit, and concatenating 02 gives the value 2.

Output

Output a single integer, the answer.

Example 1

Input:

6
2 2 3 5 4 0

Output:

97

Example 2

Input:

5
3 19 191 91 3

Output:

20107

Example 3

Input:

3
0 0 1

Output:

1

Example notes

Example 1: 22+35+40=97. Example 2: keep 3 and form 19191 and 913, for a total of 20107. Example 3: 01 can be formed, but its value is still 1, so the maximum sum is 1.

Editorial

Loading solution…