#include #include #include "tree.h" using namespace std; int solve(tree *&t) { int count = 0; if (t->left == NULL && t->right != NULL) count++; if (t->left != NULL) count += solve(t->left); if (t->right != NULL) count += solve(t->right); return count; } void create(tree *&t, int n) { if (n > 0) { int x; cin >> x; t = node(x); // Дерево строится справа налево, чтобы ситуация из задания могла // случиться (иначе, ответ всегда будет 0) int nr = n / 2; int nl = n - nr - 1; create(t->right, nr); create(t->left, nl); } } int main() { int n; cin >> n; tree *t = new tree; create(t, n); // Ответ всегда 0 или 1 int x = solve(t); cout << x << endl; return 0; }