#P8913. [RC-06] Remake

[RC-06] Remake

Problem Description

Please construct nn positive integers a1ana_1 \sim a_n that satisfy:

  • For every even X[L,R]X \in [L,R], there exist b1bnb_1 \sim b_n such that for all 1in1 \le i \le n, bi{1,1}b_i \in \{-1,1\} and 1inaibi=X\sum_{1 \le i \le n} a_i b_i = X. The values of LL and RR are given in the Constraints.
  • Let cnticnt_i be the number of indices jj such that aj=ia_j = i. Then cnticnt_i must be either 00 or at least 22.
  • 1n401 \le n \le 40.

To verify that your aia_i indeed satisfy the conditions, QQ queries will be given. In each query, an even X[L,R]X \in [L,R] is given. You need to output one valid set of bib_i.

Input Format

The first line contains two positive integers M,QM, Q, where MM is the upper bound of XX. In the testdata, it is guaranteed that M=109M = 10^9.

In the next QQ lines, each line contains one positive even integer XX. It is guaranteed that X[L,R]X \in [L,R].

Note that LL and RR are not given in the input. You may assume that L=minXL = \min X and R=maxXR = \max X.

Output Format

The first line outputs the number of positive integers you construct, nn. (1n40)(1 \le n \le 40).

The next line outputs nn positive integers a1ana_1 \sim a_n. (1ai109)(1 \le a_i \le 10^9).

In the next QQ lines, each line contains nn characters, each being + or -. Let the ii-th character be sis_i, and let the value in this query be XX. Then it must satisfy 1inai([si=\sum_{1 \le i \le n} a_i([s_i= + ][si=]-[s_i= - ])=X]) = X, where [P][P] equals 11 if PP is true, and 00 otherwise.

The aia_i you output must satisfy the requirements in the statement.

Input Format

The first line contains two positive integers M,QM, Q, where MM is the upper bound of XX. In the testdata, it is guaranteed that M=109M = 10^9.

In the next QQ lines, each line contains one positive even integer XX. It is guaranteed that X[L,R]X \in [L,R].

Note that LL and RR are not given in the input. You may assume that L=minXL = \min X and R=maxXR = \max X.

Output Format

The first line outputs the number of positive integers you construct, nn. (1n40)(1 \le n \le 40).

The next line outputs nn positive integers a1ana_1 \sim a_n. (1ai109)(1 \le a_i \le 10^9).

In the next QQ lines, each line contains nn characters, each being + or -. Let the ii-th character be sis_i, and let the value in this query be XX. Then it must satisfy 1inai([si=\sum_{1 \le i \le n} a_i([s_i= + ][si=]-[s_i= - ])=X]) = X, where [P][P] equals 11 if PP is true, and 00 otherwise.

The aia_i you output must satisfy the requirements in the statement.

6 3
2
4
6
8
1 1 1 1 1 1 1 1
++-+-++-
++-++++-
++-+++++

Hint

This problem has three subtasks.

All testdata satisfy: 2M1092 \le M \le 10^9, 1Q1051 \le Q \le 10^5, X[L,R]X \in [L,R].

  • Subtask 11 (2525 points): L=2L = 2, R=2×105R = 2 \times 10^5.
  • Subtask 22 (55 points): L=1092×105+2L = 10^9 - 2 \times 10^5 + 2, R=109R = 10^9.
  • Subtask 33 (7070 points): L=2L = 2, R=MR = M.

Translated by ChatGPT 5