#!/usr/bin/python3 # # Depending on the chosen time out, this solution either # TLEs or RTEs (out of memory). # # Implementing this recursively in Pypy3 appears to not be # possible at this point. # import sys, resource sys.setrecursionlimit(1100000) resource.setrlimit(resource.RLIMIT_STACK, (-1, -1)) from fractions import Fraction as F L, nx, dx, ny, dy, nz, dz = map(int, input().split()) x, y, z = F(nx, dx), F(ny, dy), F(nz, dz) def menger_sponge(L, x, y, z): if L == 0: return 1 t1, t2 = F(1, 3), F(2, 3) if t1 < x < t2 and t1 < y < t2: return 0 if t1 < x < t2 and t1 < z < t2: return 0 if t1 < y < t2 and t1 < z < t2: return 0 if L == 1: return 1 if x < t1: x *= 3 elif x < t2: x = (x - t1) * 3 else: x = (x - t2) * 3 if y < t1: y *= 3 elif y < t2: y = (y - t1) * 3 else: y = (y - t2) * 3 if z < t1: z *= 3 elif z < t2: z = (z - t1) * 3 else: z = (z - t2) * 3 return menger_sponge(L-1, x, y, z) print (menger_sponge(L, x, y, z))