import sys from itertools import combinations def generate_v(n): """Generate the cumulative hierarchy V_n as a list of frozensets.""" if n == 0: return [frozenset()] prev = generate_v(n-1) subsets = set() for r in range(len(prev) + 1): for subset in combinations(prev, r): subsets.add(frozenset(subset)) return list(subsets) def main(): input = sys.stdin.read().split() N = int(input[0]) A = list(map(int, input[1:7])) A0, A1, A2, A3, A4, A5 = A # Generate V_N try: vn = generate_v(N) except RecursionError: print("NO") return # Precompute all elements of V_N elements = vn # Iterate all possible m0, m1, m2 in V_N found = False for m0 in elements: for m1 in elements: for m2 in elements: # Map A0-A5 to the corresponding m variables ma0 = [m0, m1, m2][A0] ma1 = [m0, m1, m2][A1] ma2 = [m0, m1, m2][A2] ma3 = [m0, m1, m2][A3] ma4 = [m0, m1, m2][A4] ma5 = [m0, m1, m2][A5] # Check condition 1: ∀x3 ∈ V_N, x3 ∈ ma0 → x3 ∈ ma1 cond1 = True for x3 in elements: if x3 in ma0: if x3 not in ma1: cond1 = False break # Check condition 2: ma1 ∈ ma2 cond2 = (ma1 in ma2) # Check condition 3: ma3 ∈ ma2 cond3 = (ma3 in ma2) # Check condition 4: ma4 ∈ ma2 cond4 = (ma4 in ma2) # Check condition 5: ma5 ∈ ma0 cond5 = (ma5 in ma0) if cond1 and cond2 and cond3 and cond4 and cond5: found = True break if found: break if found: break print("YES" if found else "NO") if __name__ == "__main__": main()