#!/usr/bin/python3

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)

t1, t2 = F(1, 3), F(2, 3)

def scale(x):
    if x < t1:
        return x * 3
    elif x < t2:
        return (x - t1) * 3
    else:
        return (x - t2) * 3

def menger_sponge_non_recursive(L, x, y, z):
    while True:
        if L == 0: 
            return 1

        if (t1 < x < t2 and t1 < y < t2) or (t1 < x < t2 and t1 < z < t2) or (t1 < y < t2 and t1 < z < t2):
            return 0

        L, x, y, z = L-1, scale(x), scale(y), scale(z)

print (menger_sponge_non_recursive(L, x, y, z))
