#P9500. Constructing a Digit String with Specified Forward and Reverse Decimal Values

    ID: 22649 Type: Default 1000ms 256MiB

Constructing a Digit String with Specified Forward and Reverse Decimal Values

Constructing a Digit String with Specified Forward and Reverse Decimal Values

Given three integers a, b and c, you are to construct a string s consisting of digits (0–9) with length n satisfying the following conditions:

  • The weight of s is defined as \[ f(s)=\sum_{i=1}^{n}10^{n-i}s_i, \] i.e. the number in its usual decimal notation (possibly with leading zeros). For example, if s = "0321" then f(s)=321 (note: the weight ignores any extra zeros in the front).
  • The reverse string \( \overline{s} \) is defined as the string obtained by reversing s (for example, if s = "0321" then \( \overline{s} = "1230" \)). Its weight is defined in the same way:
  • \[ f(\overline{s})=\sum_{i=1}^{n}10^{n-i}\overline{s_i}. \]

Your task is to construct a string s such that

  • |s| \le 114514 (its length does not exceed 114514),
  • f(s) \equiv a \pmod{998244353}, and
  • f(\overline{s}) \equiv b \pmod{998244353}.

If c = 0, you must also ensure that the first and the last digit of s are not 0.

If there is no solution, simply output -1 (without quotes).

Note: All computations are done modulo \(998244353\). In this problem, the numbers a and b are given modulo \(998244353\). In your construction you are free to choose any length \(1 \le n \le 114514\) and any digit string that meets the conditions.

inputFormat

The input consists of a single line with three integers separated by spaces: a, b and c.

  • a: the required value of f(s) modulo \(998244353\).
  • b: the required value of f(\overline{s}) modulo \(998244353\).
  • c: if c = 0 then the first and last digit of s must be nonzero; otherwise, there is no such restriction.

outputFormat

If a valid string s exists, output it. Otherwise, output -1.

sample

101 101 0
101