There is a binary string S0 of length N whose characters are all 0. You apply U toggle operations to it. The i-th operation turns Si−1 into Si, so once all U operations are done the string is SU.
The i-th operation is given as two integers Li and Ri. It flips every character in the range [Li,Ri]. Both ends included, every 1 inside that range becomes 0 and every 0 becomes 1.
Applying all operations gives the strings S0,S1,…,SU. Write a program that finds the one that comes last in lexicographic order among these U+1 strings.