Codeforces Round 880 (Div. 2)
C
k-th equality
Codeforces
未评级
原题
← BD →
翻译中…

Consider all equalities of form $a + b = c$, where $a$ has $A$ digits, $b$ has $B$ digits, and $c$ has $C$ digits. All the numbers are positive integers and are written without leading zeroes. Find the $k$-th lexicographically smallest equality when written as a string like above or determine that it does not exist.

翻译中…

For example, the first three equalities satisfying $A = 1$, $B = 1$, $C = 2$ are

翻译中…
  • $1 + 9 = 10$,
  • $2 + 8 = 10$,
  • $2 + 9 = 11$.
翻译中…

An equality $s$ is lexicographically smaller than an equality $t$ with the same lengths of the numbers if and only if the following holds:

翻译中…
  • in the first position where $s$ and $t$ differ, the equality $s$ has a smaller digit than the corresponding digit in $t$.
翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases. The description of test cases follows.

翻译中…

The first line of each test case contains integers $A$, $B$, $C$, $k$ ($1 \leq A, B, C \leq 6$, $1 \leq k \leq 10^{12}$).

翻译中…

Each input file has at most $5$ test cases which do not satisfy $A, B, C \leq 3$.

翻译中…

Output

翻译中…

For each test case, if there are strictly less than $k$ valid equalities, output $-1$.

翻译中…

Otherwise, output the $k$-th equality as a string of form $a + b = c$.

翻译中…

Note

翻译中…

In the first test case, the first $9$ solutions are: $\langle 1, 1, 2 \rangle, \langle 1, 2, 3 \rangle, \langle 1, 3, 4 \rangle, \langle 1, 4, 5 \rangle, \langle 1, 5, 6 \rangle, \langle 1, 6, 7 \rangle, \langle 1, 7, 8 \rangle, \langle 1, 8, 9 \rangle, \langle 2, 1, 3 \rangle$.

翻译中…

Int the third test case, there are no solutions as the smallest possible values for $a$ and $b$ are larger than the maximal possible value of $c$ — $10 + 10 = 20 \gt 9$.

翻译中…

Please note that whitespaces in the output matter.

翻译中…

样例

Input #1
7
1 1 1 9
2 2 3 1
2 2 1 1
1 5 6 42
1 6 6 10000000
5 5 6 3031568815
6 6 6 1000000000000
Output #1
2 + 1 = 3
10 + 90 = 100
-1
9 + 99996 = 100005
-1
78506 + 28543 = 107049
-1
InputCopy OutputCopy
题目信息
题号
1836C
时间限制
1 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。