C - Goodish or Not Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

問題文

良い数 を次のように定義します。

  • 正整数 x が以下の条件を満たすとき、またその時に限って x良い数 と呼びます。
    • x の隣接する桁の差は高々 1 である。
    • 厳密には、 xk 桁の整数であり、 x を十進表記で書き下すと d_1d_2 \dots d_k となる時、 1 \le i < k なる全ての整数 i について |d_i - d_{i+1}| \le 1 が満たされる。

例えば 1,56,777,3234 は良い数ですが、 13,1235,909 は良い数ではありません。

良さそうな数 を次のように定義します。

  • 正整数 x が以下の条件を満たすとき、またその時に限って x良さそうな数 と呼びます。
    • x の桁を高々 1 つ書き換えることで、 x を良い数にすることができる。 但し、この書き換えで先頭の桁を 0 にすることは許されない。
    • 厳密には、 xk 桁の整数であり、 x を十進表記で書き下すと d_1d_2 \dots d_k となる時、以下の条件を全て満たす整数組 (p,q) が存在する。
      • 1 \le p \le k
      • 0 \le q \le 9
      • (p,q) \neq (1,0)
      • x のうち d_pq にすると、 x が良い数となる。
    • 良い数は、必ず良さそうな数でもあることに注意してください。

例えば 7176d_28 にすることで 7876 とでき、 7876 は良い数なので 7176 は良さそうな数です。

整数 N が与えられるので、 N が良さそうな数かどうか判定してください。

制約

  • N1 \le N < 10^{18} を満たす整数

入力

入力は以下の形式で標準入力から与えられる。

N

出力

N が良さそうな数なら Yes 、そうでないなら No と出力せよ。


入力例 1

7176

出力例 1

Yes

問題文中の例と同じです。


入力例 2

2020

出力例 2

No

2020 は良さそうな数ではありません。


入力例 3

3728

出力例 3

No

入力例 4

987654321012345678

出力例 4

Yes

N32bit 符号付き整数に収まらない場合もあります。
また、 N 自身が良い数である場合もあります。

Problem Statement

A good number is defined as follows.

  • A positive integer x is said to be a good number if and only if:
    • every pair of adjacent digits in x has a difference of 1 or less.
    • Formally, if x has k digits and its decimal representation is d_1d_2 \dots d_k, then |d_i - d_{i+1}| \le 1 for all integers i with 1 \le i < k.

For example, 1,56,777, and 3234 are good numbers, but 13,1235, and 909 are not.

A goodish number is defined as follows.

  • A positive integer x is said to be a goodish number if and only if:
    • one can modify at most one digit of x to make it a good number. Here, it is disallowed to produce a leading zero.
    • Formally, if x has k digit and its decimal representation is d_1d_2 \dots d_k, there exists an integer pair (p,q) such that:
      • 1 \le p \le k,
      • 0 \le q \le 9,
      • (p,q) \neq (1,0), and
      • setting d_p in x to q makes x a good number.
    • Note that a good number is always a goodish number.

For example, given 7176, one can set d_2 to 8 to make it 7876, which is a good number, so 7176 is a goodish number.

Given an integer N, determine if N is a goodish number.

Constraints

  • N is an integer such that 1 \le N < 10^{18}.

Input

The input is given from Standard Input in the following format:

N

Output

Print Yes if N is a goodish number, and No otherwise.


Sample Input 1

7176

Sample Output 1

Yes

This is the same as the example in the problem statement.


Sample Input 2

2020

Sample Output 2

No

2020 is not a goodish number.


Sample Input 3

3728

Sample Output 3

No

Sample Input 4

987654321012345678

Sample Output 4

Yes

N may not fit into a 32-bit signed integer.
Also, N itself may be a good number.