electicode
HomeCoursesResourcesProblemsNational OlympiadContestsLeaderboard
...

Binary String

Time Limit: 1000msMemory Limit: 256MB
View Submissions

Problem Description

Komil loves working with perfect binary strings.

One day he wanted to create a binary string satisfying the following conditions:

  • If you cut out any contiguous substring of length NNN, then the difference between the number of ones and the number of zeros in it equals KKK, i.e.: (number of 1)−(number of 0)=K(\text{number of } 1) - (\text{number of } 0) = K(number of 1)−(number of 0)=K
  • If you cut out any contiguous substring of length N+2N + 2N+2, then the difference between the number of ones and the number of zeros in it is not equal to KKK, i.e.: (number of ones)−(number of zeros)≠K(\text{number of ones}) - (\text{number of zeros}) \neq K(number of ones)−(number of zeros)=K

The longer Komil’s string is, the happier he is. If there are several strings of the same length, he chooses the lexicographically smallest one.

Your task is to find the perfect string using the given NNN and KKK.

Input Format

The first line contains two integers NNN and KKK.

Constraints:

  • 2≤N≤1042 \leq N \leq 10^42≤N≤104
  • 0≤K<N0 \leq K < N0≤K<N
  • It is guaranteed that such a binary string exists for the given NNN and KK.

Output Format

Print the lexicographically smallest of the longest binary strings satisfying the conditions.

Scoring

SubtaskAdditional constraintsPointsRequired subtasks
000Sample tests000-
111K=0K = 0K=

Examples

Example 1
Input
2 0
Output
010

© 2026 Electicode. All rights reserved.

K
0
505050
000
222No additional constraints505050000, 111