#include<bits/stdc++.h>
#define ll long long int
using namespace std;
class node{
public:
int data;
nodeleft;
noderight;
node(int d){
data = d;
left = NULL;
right = NULL;
}
};
node* buildTree(){
int d;
cin>>d;
node * root = new node(d);
root->left = buildTree();
root->right = buildTree();
return root;
}
int sumBT(node*root){
if(root==NULL){
return 0;
}
return (root->data+sumBT(root->left)+sumBT(root->right));
}
int main(){
ll n;cin>>n;
node* root;
ll sum=0;
for(ll i=0;i<n;i++){
root=buildTree();
sum=sumBT(root);
}
cout<<sum<<endl;
return 0;
}