#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include "testlib.h"

using namespace std;

#define VI vector<int>

#define FOR(i,n) for (int i = 0; i < (int)(n); i++)

#define PB push_back
#define SZ(a) a.size()
#define MP make_pair
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<VI >
#define PII pair<int, int>

int n, res;

struct tree_elem{
	int pl, pr, val;
} a[500000];

int ptree;

set<int> used;

int scan_tree(int d)
{
	if (d >= n)
		return 0;
	int p = ++ptree;
	a[p].val = ouf.readInt();
	//for (int i = 0; i < d + d; i++) printf(" "); printf("%d\n", a[p].val); fflush(stdout);
	if (a[p].val < 1 || a[p].val >= (1<<n))
		quitf(_wa, "Wrong number %d", a[p].val);
	if (used.count(a[p].val) == 1)
		quitf(_wa, "Repeating number %d", a[p].val);
	used.insert(a[p].val);
	a[p].pl = scan_tree(d + 1);
	a[p].pr = scan_tree(d + 1);
	return p;
}

int check_tree(int p, int d)
{
	if (p == 0)
		return 0;
	//for (int i = 0; i < d + d; i++) printf(" "); printf("%d = %d\n", p, a[p].val); fflush(stdout);
	int sum_l = check_tree(a[p].pl, d + 1);
	int sum_r = check_tree(a[p].pr, d + 1);

	int diff = abs(sum_l - sum_r);

	if ((d != n - 1) && (diff != (1<<d)))
		quitf(_wa, "Wrong difference at level %d (%d): %d  %d %d", d, n, diff, sum_l, sum_r);

	return sum_l + sum_r + a[p].val;
}

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);

	n = inf.readInteger();

	int root = scan_tree(0);

	check_tree(root, 0);

	quitf(_ok, "OK %d", n);
}
