eolymp
bolt
Try our new interface for solving problems
Problems

Ones and Zeroes

Ones and Zeroes

Consider two binary sequences \textbf{a} and \textbf{b} of length \textbf{n} each. Let us call these sequences \textit{compatible} if \textbf{a xor b = a + b}, where \textbf{xor} is the element-wise "\textbf{exclusive OR}" operation. Given an integer \textbf{n} and a pair of binary sequences \textbf{p} and \textbf{q}, find the pair of compatible binary sequences \textbf{a} and \textbf{b} which comes first after the pair \textbf{(p, q)}. Pair \textbf{(a, b)} is said to be lexicographically less that \textbf{(c, d)} if \textbf{a} is lexicographically less than \textbf{c}, or \textbf{a} and \textbf{c} are equal and \textbf{b} is lexicographically less than \textbf{d}. If there is no pair of compatible binary sequences lexicographically greater than \textbf{(p, q)}, output the lexicographically first compatible pair. \InputFile There is a single integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}). on the first line of the input. The sequence \textbf{p} is given on the second line, and the sequence \textbf{q} is on the third one. There are no spaces or other delimiters inside the sequences; however, there could be trailing whitespace on these two lines. \OutputFile Output the sequences \textbf{a} and \textbf{b} on the first two lines of the output, correspondingly. Use the same format as the input.
Time limit 1 second
Memory limit 64 MiB
Input example #1
1
0
0
Output example #1
0
1
Author Dmitry Gozman
Source Dmitry Gozman Contest 1, Petrozavodsk training camp, January 2007