cswork / OAOpen practice workspace

AmazonOA #104

Calculate Max Salary

Estimated HardJudge-ready

Topics (AI-labelled)Prefix & RangesGreedy

The pay for A through E is 1, 10, 100, 1000 and 10000 respectively. If a higher level appears later than a given day, that day's pay is subtracted; otherwise it is added. Change at most one character and find the maximum pay.

Input

One line with a string containing only ABCDE. The original gives no value ranges; this site sets the length to 1..100000.

Output

Output a single integer answer.

Example 1

Input:

ABCDEEDCBA

Output:

31000

Example 2

Input:

A

Output:

10000

Example 3

Input:

EE

Output:

20000

Example notes

Example 1: change D on the fourth day to E, which reduces the negative values in the earlier part and adds 10000, for an optimum of 31000. Example 2: change A directly to E for a pay of 10000. Example 3: everything is already E, for a total pay of 20000.

Editorial

Loading solution…