#P5751. Constructing a Valid Binary String

    ID: 18979 Type: Default 1000ms 256MiB

Constructing a Valid Binary String

Constructing a Valid Binary String

Given seven integers \( N, A_0, B_0, L_0, A_1, B_1, L_1 \), you are required to construct a binary string \( S = s_1 s_2 \ldots s_N \) such that:

  1. For each \( 1 \leq i \leq N \), \( s_i \in \{0, 1\} \).
  2. For every contiguous substring of length \( L_0 \) (i.e. \( s_j s_{j+1} \ldots s_{j+L_0-1} \) for \( 1 \leq j \leq N-L_0+1 \)), the number of zeros is between \( A_0 \) and \( B_0 \) (inclusive).
  3. For every contiguous substring of length \( L_1 \) (i.e. \( s_j s_{j+1} \ldots s_{j+L_1-1} \) for \( 1 \leq j \leq N-L_1+1 \)), the number of ones is between \( A_1 \) and \( B_1 \) (inclusive).

It is guaranteed that there exists at least one binary string \( S \) satisfying these conditions. For example, when \( N = 6, A_0 = 1, B_0 = 2, L_0 = 3, A_1 = 1, B_1 = 1, L_1 = 2 \), the string \( S = 010101 \) is valid.

inputFormat

The input consists of a single line containing seven space-separated integers: \( N, A_0, B_0, L_0, A_1, B_1, L_1 \).

outputFormat

Output a valid binary string \( S \) of length \( N \) that satisfies all the given conditions.

sample

6 1 2 3 1 1 2
010101