No.437 cww Game
Problem Statement
C is playing a certain game that uses numbers.
In this game, a positive number $N$ is given first.
The goal of the game is to skillfully extract several "cww numbers" from $N$ and make their sum as large as possible.
The details are as follows.
- A cww number is a number whose decimal representation is $cww$, where $c \neq 0, c \neq w$.
- Example: 355 and 700 are cww numbers, but 123, 551, and 099 are not cww numbers.
- The game proceeds as follows.
$N = a_0 a_1 \dots a_{L-1}$ (10進数表記)
$I = \{0, 1, ..., L-1\}$
$score = 0$
while true:
Iから異なる3つの要素i, j, kを選ぶ $( i < j < k )$
x = a_i a_j a_k がcww数であるとき
score += x
Iからi, j, kを除く
xがcww数となるようなi,j,kの選び方がなければ終了
What is the maximum score that C can finally obtain?
Input
N
The input consists of a single line containing a positive integer $N$ ($1 \leq N \leq 10^{12}$).
Output
Output the maximum score that C can obtain on a single line, followed by a newline.
Sample
Sample 1
Input
133144
Output
344
For example, taking (2, 4, 5) as the first (i, j, k) produces the cww number 344. No cww number can be made from the remaining part. This gives the maximum score.
Taking (0, 1, 2) and then (3, 4, 5) as (i, j, k) produces two cww numbers 133 and 144, but their sum is 277, which is smaller than 344.
Sample 2
Input
11
Output
0
No cww number can be made, so the answer is 0.
Sample 3
Input
2718281828
Output
1821
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
🍡yurahuna
moti