CODECHEF
Chef built a binary string
that has exactly hills and valleys.
A hill is any index such that both its neighbors are strictly smaller than it, i.e, and .
A valley is any index such that both its neighbors are strictly larger than it, i.e, and .
Chef thinks that his string is the shortest among all binary strings with hills and valleys. You don't quite trust his words, so to verify his claim you would like to find the shortest binary string with exactly hills and valleys.
If there are multiple possible binary strings of the least length satisfying the given condition, you may print any of them.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains two space-separated integers and , the required number of hills and valleys respectively.
Output Format
For each test case, output two lines.
- The first line contains the length of the binary string you constructed to satisfy the given conditions.
- The second line contains the string itself.
Constraints
- The sum of lengths of the answer strings across all test cases does not exceed
Subtasks
Subtask 1 (10 points):
- You may output any string of length not exceeding containing exactly hills and valleys: it need not be shortest by length. It is guaranteed that at least one such string with length exists.
Subtask 2 (90 points):
- Original constraints
- The binary string you construct must be shortest by length.
Sample Input 1
3
3 2
2 3
3 3
Sample Output 1
7
0101010
7
1010101
8
01010101
Explanation
Test case : The given string has hills at indices and valleys at indices . It can be verified that there is no string of length or less with hills and valleys. Note that for subtask , a binary string like will also be accepted as a valid output, even though it is not shortest by length.
Test case : Apart from the given string, another possible string of length that has hills and valleys is . You may print any of them.
ConversionConversion EmoticonEmoticon