#include <bits/stdc++.h>
using namespace std;
int flag = 0;
int n[10000] = {0};
int maxA;
int findMax(int index, int sum) {
  if (n[index] == -1) {
    return 0;
  }
  int a, b;
  a = findMax(2 * index, sum);
  b = findMax(2 * index + 1, sum);
  if (a >= b)
    sum += a;
  else
    sum += b;
  sum += n[index];
  return sum;
}
int traceParent(int index) {
  index = index / 2;
  int sum = 0;
  while (index >= 1) {
    sum += n[index];
    index = index / 2;
  }
  return sum;
}
int powe(int base, int power) {
  int a = base;
  if (power == 0) {
    return 1;
  }
  for (int i = 0; i < power - 1; i++) {
    a = a * base;
  }
  return a;
}
int main() {
  int d;
  for (int i = 0; i < 10000; i++) {
    n[i] = -1;
  }
  n[1] = 0;
  cin >> d;
  for (int i = 0; i <= d; i++) {
    for (int j = powe(2, i); j < powe(2, i) + powe(2, i); j++) {
      if (j == 1) break;
      cin >> n[j];
    }
  }
  maxA = findMax(1, 0);
  for (int i = 2; i < powe(2, d + 1); i++) {
    int b, y;
    while (findMax(i, 0) + traceParent(i) < maxA) {
      flag += 1;
      n[i]++;
      n;
    }
  }
  std::cout << flag;
  getchar();
  getchar();
  return 0;
}
