#!/usr/bin/env python3 from collections import defaultdict MOVES = [(1, 0), (0, 1), (-1, 0), (0, -1)] def main(): n = int(input()) side_len = 1 << n a = [[int(x) for x in input().split()] for _ in range(side_len)] freq = defaultdict(int) vis = [[]] valid = True for r, row in enumerate(a): for c, x in enumerate(row): freq[x] += 1 if x == 0: continue # This is the corner of a triomino if there are two "legs" that have not been visited # count the number of "legs". If it is > 2 or in a line, impossible. is_same = [0 <= r + dr < side_len and 0 <= c + dc < side_len and a[r + dr][c + dc] == x for dr, dc in MOVES] if sum(is_same) not in [1, 2] or (is_same[0] and is_same[2]) or (is_same[1] and is_same[3]): valid = False for k, v in freq.items(): exp = 1 if k == 0 else 3 valid &= (v == exp) print("1" if valid else "0") if __name__ == "__main__": main()