#P10534. Concatenated Pair Sums with Optional Zero Separators

    ID: 12552 Type: Default 1000ms 256MiB

Concatenated Pair Sums with Optional Zero Separators

Concatenated Pair Sums with Optional Zero Separators

Given a digit string \(S\) (with no leading zero), determine whether there exists an integer sequence \(A_1, A_2, \dots, A_n\) with odd length \(n\) such that if we form the following sums: \[ B_1=A_1+A_2,\quad B_2=A_2+A_3,\quad \dots, \quad B_{n-1}=A_{n-1}+A_n,\quad B_n=A_n+A_1, \] then by concatenating the decimal representations of \(B_1, B_2, \dots, B_n\) in order with an arbitrary (possibly zero) number of zeros inserted between adjacent numbers, we obtain exactly the string \(S\).

In other words, there exists a decomposition \[ S = X_1 \;||\; Z_1 \;||\; X_2 \;||\; Z_2 \;||\; \cdots \;||\; Z_{n-1} \;||\; X_n, \] where:

  • Each \(X_i\) is a nonempty string representing the number \(B_i=A_i+A_{i+1}\) in its standard decimal form (i.e. if \(X_i\) has more than one digit, it does not start with \(0\); however, a single digit \(0\) is allowed).
  • Each \(Z_i\) (if present) is a (possibly empty) string consisting only of the digit \(0\) that acts as a separator between two numbers.

It is guaranteed that \(S\) does not have any leading zeros. Note that if a valid decomposition exists, then the corresponding system of equations (which is linear and cyclic) has a solution if and only if \[ B_1 - B_2 + B_3 - \cdots + (-1)^{n-1}B_n \quad \text{is even.} \]

Your task is to print YES if such a sequence \(A_i\) exists, and NO otherwise.

inputFormat

The input consists of a single line containing the digit string \(S\) (without spaces), with \(S\) having no leading zeros.

outputFormat

Output a single line: YES if there exists an odd-length sequence \(A_i\) satisfying the described condition; otherwise, output NO.

sample

101
YES