include <bits/stdc++.h>
include
using namespace std;
vector v;
char a[100000];
//class node
class node{
public:
int data;
node *left,*right;
public:
node(int val){
data = val;
*left = *right = NULL;
}
};
//string to int from single line of space chars
void stringToInt(){
char *ans = strtok(a," ");
while(ans != NULL){
v.push_back(stoi(ans));
ans = strtok(NULL," ");
}
}
//create tree
node* createTree(){
if(v.size()==0){return NULL;}
int no = v[0];
node* root = new node(no);
int i=0;
int flag = 0;
queue<node*> q;
while(!q.empty() && i<v.size()){
node* temp = q.front();
q.pop();
no = v[i++];
if(no!=-1){
temp->left = new node(no);
q.push(temp->left);
}
if(i>=v.size()){ break;}
no = v[i++];
if(no!=-1){
temp->right = new node(no);
q.push(temp->right);
}
if(i>=v.size()){ break; }
}
return root;
}
//mirror tree
bool isMirror(node* root){
if(root->left == NULL && root->right == NULL){ return true;}
if(root->left == NULL || root->right == NULL){ return false;}
return (root->left->data == root->right->data)&&(isMirror(root->left))&&(isMirror(root->right));
}
//main fn
int main(){
cin.ignore();
cin.getline(a,' ');
stringToInt();
node* root = createTree();
cout << isMirror(root) << endl;
return 0;
}
