eolymp
bolt
Try our new interface for solving problems
Problems

I Speak Whales

I Speak Whales

According to Wikipedia, a Walsh matrix is a specific square matrix, with dimensions equal to a power of \textbf{2}, the entries of which are \textbf{+1} or \textbf{-1}, and the property that the dot product of any two distinct rows (or columns) is zero. Below are the first three Walsh Matrices. (The gray lines are imaginary lines for illustration purpose only). \includegraphics{https://static.e-olymp.com/content/cf/cfdd9707d355a76e4f772a55bfc15ebef290839f.jpg} A Walsh Matrix of size \textbf{2N}+\textbf{1} can be constructed as the "union" of \textbf{4} Walsh Matrices of size \textbf{2N} arranged such that the lower right matrix is inverted whereas the other \textbf{3} matrices are not, i.e.: \includegraphics{https://static.e-olymp.com/content/4f/4f4752fed2a0a990527c456f34e25acea1562cb1.jpg} Let's number the rows of a given Walsh Matrix from the top starting with row 0. Similarly, let's number the columns of the matrix from the left starting with column \textbf{0}. Given the four integers \textbf{N}, \textbf{R}, \textbf{S}, and \textbf{E}, write a program that will construct a Walsh Matrix of size \textbf{2N} and will print the sum of all the numbers in row \textbf{#R} between columns \textbf{#S} and \textbf{#E} (inclusive). \InputFile Your program will be tested on one or more test cases. Each test case is specified using a single line listing four integers in the following order: \textbf{N}, \textbf{R}, \textbf{S}, and \textbf{E}, where \textbf{0} ≤ \textbf{N} ≤ \textbf{60}, \textbf{0} ≤ \textbf{R} < \textbf{2^N}, \textbf{0} ≤ \textbf{S} ≤ \textbf{E} < \textbf{2^N}, and \textbf{E}-\textbf{S} ≤ \textbf{10000}. The last line of the input file has four \textbf{-1}'s and is not part of the test cases. \OutputFile For each test case, print the output on a single line.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2  1 0 1
48 0 0 47
-1 -1 -1 -1
Output example #1
0
48