Consider a string of length n made only of the characters 0 and 1. It has exactly n−1 pairs of adjacent characters, and each pair is one of 00, 01, 10, 11.
You are given four integers a, b, c, d. Restore a string in which exactly a adjacent pairs are 00, exactly b are 01, exactly c are 10, and exactly d are 11. Its length is always n=a+b+c+d+1.
Several strings can satisfy the counts, so print the lexicographically smallest one. All candidates have the same length, so comparing them character by character from the first position is enough.