Menger Sponge

Problem ID: mengersponge

Time Limit: 2 seconds

The Menger sponge is a simple 3D fractal. Its level-$L$ approximation can be constructed with the following algorithm:

The points in the level-$L$ Menger sponge are those that remain after running the above algorithm. Points exactly on the boundary of cubes that remain in the sponge are part of the sponge.

The picture below shows the result for $L = 0$ through $L = 3$:

\includegraphics[width=0.7\textwidth ]{menger.jpg}

Given a level $L$ and a point in space given by three rational coordinates, determine if the point is in the level-$L$ Menger sponge.

Input

The single line of input contains seven integers $L$, $x_{\text {num}}$, $x_{\text {denom}}$, $y_{\text {num}}$, $y_{\text {denom}}$, $z_{\text {num}}$, $z_{\text {denom}}$:

where $L$ is the level of the Menger Sponge and the point in question is $\left(\frac{x_{\text {num}}}{x_{\text {denom}}},\frac{y_{\text {num}}}{y_{\text {denom}}},\frac{z_{\text {num}}}{z_{\text {denom}}}\right)$.

Output

Output a single integer, which is $1$ if the point is in the level-$L$ Menger Sponge, or $0$ if not.

Sample Input 1 Sample Output 1
1000 1 3 1 3 1 3
1
Sample Input 2 Sample Output 2
2 49 81 5 6 20 81
1
Sample Input 3 Sample Output 3
3 49 81 5 6 20 81
0