問題一覧 > 通常問題

No.437 cww Game

レベル : / AI推定難易度 : 850 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 227
作問者 : 🍡yurahuna / テスター : moti
お気に入りにしたユーザー ProblemId : 1126 / 自分の提出
問題文最終更新日: 2026-06-28 13:26:22
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 152 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。