#include<iostream>
#include<cstdio>
#include<climits>
#include<cstdlib>
using namespace std;
struct Node{
  int n,p,li,ri,s,ll,rl;
};

Node node[1000001];
int n,root,ount = 0,ndex;
int a[1000000],t = -1,success[1000000];

int bns(int);
int dfs(Node);
int cmp(const void* a, const void* b)
{  return ( *(int*)a - *(int*)b );  }

int main()
{
  scanf("%d",&n);
  for( int i=1; i<=n; ++i )
    node[i].s = node[i].p = -1;
  for( int i=1; i<=n; ++i )
    {
      scanf("%d%d%d", &node[i].n , &node[i].li , &node[i].ri);
      if( node[i].li != -1 )
	{
	  node[ node[i].li ].p = i;
	  node[ node[i].li ].s = 0;
	}
      if( node[i].ri != -1 )
	{
	  node[ node[i].ri ].p = i;
	  node[ node[i].ri ].s = 1;
	}
      a[ ++t ] = node[i].n;
    }
  qsort( a, t+1, sizeof(int), cmp );
  int p = 0,temp = a[0];
  ndex = -1;
  while( p < t )
    {

      a[ ++ndex ] = a[p];
      temp = a[p];
       while( p < t && a[++p] == temp );
      //  cout<<"u"<<a[ndex];
    }
  if( a[ndex] != a[t] )
    a[++ndex] = a[t];
  for( int i=0; i<=ndex; ++i )
    success[i] = -1;
  for( int i=1; i<=n; ++i )
    if( node[i].p == -1 )
      {
	root = i;
	break;
      }
  node[ root ].ll = INT_MIN;
  node[ root ].rl = INT_MAX;
  dfs(node[ root ]);
  //   cout<<"i"<<ndex;
  for( int i=0; i<=ndex; ++i)
    if( success[i] == -1 )
      {
  	++ount;
	//		cout<<a[i]<<" "<<success[i]<<"\n";
      }
  printf("%d",ount);
  return 0;
}

int dfs( Node v )
{
  if( v.li != -1 )
    {
      node[ v.li ].ll = v.ll;
      node[ v.li ].rl = v.n < v.rl? v.n : v.rl;
      dfs( node[ v.li ] );
    }
  if( v.ri != -1 )
    {
      node[ v.ri ].rl = v.rl;
      node[ v.ri ].ll = v.n > v.ll? v.n : v.ll;
      dfs( node[ v.ri ] );
    }
  if( !( v.n <= v.ll || v.n >= v.rl ) )
    success[ bns( v.n ) ] = 1;
  return 0;
}

int bns( int n )
{
  int beg = 0, end = ndex+1,mid;
  while( beg <= end )
    {
      mid = (beg+end)/2;
      if( a[mid] == n )
	return mid;
      else if( a[mid] > n )
	end = mid-1;
      else
	beg = mid + 1;
    }
  //  printf("dsfafsadf\n");
  return -1;
}


#include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
struct Node{
  int n,p,li,ri,s,ll,rl;
};
Node node[1000001];
int n,root,ount = 0;
int dfs(Node);
int main()
{
  scanf("%d",&n);
  for( int i=1; i<=n; ++i )
    node[i].s = node[i].p = -1;
  for( int i=1; i<=n; ++i )
    {
      scanf("%d%d%d", &node[i].n , &node[i].li , &node[i].ri);
      if( node[i].li != -1 )
	{
	  node[ node[i].li ].p = i;
	  node[ node[i].li ].s = 0;
	}
      if( node[i].ri != -1 )
	{
	  node[ node[i].ri ].p = i;
	  node[ node[i].ri ].s = 1;
	}
    }
  for( int i=1; i<=n; ++i )
    if( node[i].p == -1 )
      {
	root = i;
	break;
      }
  node[ root ].ll = INT_MIN;
  node[ root ].rl = INT_MAX;
  dfs(node[ root ]);
  printf("%d\n",ount);
  return 0;
}

int dfs( Node v )
{
  if( v.li != -1 )
    {
      node[ v.li ].ll = v.ll;
      node[ v.li ].rl = v.n < v.rl? v.n : v.rl;
      dfs( node[ v.li ] );
    }
  if( v.ri != -1 )
    {
      node[ v.ri ].rl = v.rl;
      node[ v.ri ].ll = v.n > v.ll? v.n : v.ll;
      dfs( node[ v.ri ] );
    }
  if( v.n < v.ll || v.n > v.rl )
    {
      ++ount;
      //      cout<<v.n;
    }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<climits>
#include<cstdlib>
using namespace std;
struct Node{
  int n,p,li,ri,s,ll,rl;
};

Node node[1000001];
int n,root,ount = 0,ndex;
int a[1000000],t = -1,success[1000000];

int bns(int);
int dfs(Node);
int cmp(const void* a, const void* b)
{  return ( *(int*)a - *(int*)b );  }

int main()
{
  scanf("%d",&n);
  for( int i=1; i<=n; ++i )
    node[i].s = node[i].p = -1;
  for( int i=1; i<=n; ++i )
    {
      scanf("%d%d%d", &node[i].n , &node[i].li , &node[i].ri);
      if( node[i].li != -1 )
	{
	  node[ node[i].li ].p = i;
	  node[ node[i].li ].s = 0;
	}
      if( node[i].ri != -1 )
	{
	  node[ node[i].ri ].p = i;
	  node[ node[i].ri ].s = 1;
	}
      a[ ++t ] = node[i].n;
    }
  qsort( a, t+1, sizeof(int), cmp );
  int p = 0,temp = a[0];
  ndex = -1;
  while( p < t )
    {

      a[ ++ndex ] = a[p];
      temp = a[p];
       while( p < t && a[++p] == temp );
      //  cout<<"u"<<a[ndex];
    }
  if( a[ndex] != a[t] )
    a[++ndex] = a[t];
  for( int i=0; i<=ndex; ++i )
    success[i] = -1;
  for( int i=1; i<=n; ++i )
    if( node[i].p == -1 )
      {
	root = i;
	break;
      }
  node[ root ].ll = INT_MIN;
  node[ root ].rl = INT_MAX;
  dfs(node[ root ]);
  //   cout<<"i"<<ndex;
  for( int i=0; i<=ndex; ++i)
    if( success[i] == -1 )
      {
  	++ount;
	//		cout<<a[i]<<" "<<success[i]<<"\n";
      }
  printf("%d",ount);
  return 0;
}

int dfs( Node v )
{
  if( v.li != -1 )
    {
      node[ v.li ].ll = v.ll;
      node[ v.li ].rl = v.n < v.rl? v.n : v.rl;
      dfs( node[ v.li ] );
    }
  if( v.ri != -1 )
    {
      node[ v.ri ].rl = v.rl;
      node[ v.ri ].ll = v.n > v.ll? v.n : v.ll;
      dfs( node[ v.ri ] );
    }
  if( !( v.n <= v.ll || v.n > v.rl ) )
    success[ bns( v.n ) ] = 1;
  return 0;
}

int bns( int n )
{
  int beg = 0, end = ndex+1,mid;
  while( beg <= end )
    {
      mid = (beg+end)/2;
      if( a[mid] == n )
	return mid;
      else if( a[mid] > n )
	end = mid-1;
      else
	beg = mid + 1;
    }
  //  printf("dsfafsadf\n");
  return -1;
}


#include<iostream>
#include<cstdio>
#include<climits>
#include<cstdlib>
using namespace std;
struct Node{
  int n,p,li,ri,s,ll,rl;
};

Node node[1000001];
int n,root,ount = 0,ndex;
int a[1000000],t = -1,success[1000000];

int bns(int);
int dfs(Node);
int cmp(const void* a, const void* b)
{  return ( *(int*)a - *(int*)b );  }

int main()
{
  scanf("%d",&n);
  for( int i=1; i<=n; ++i )
    node[i].s = node[i].p = -1;
  for( int i=1; i<=n; ++i )
    {
      scanf("%d%d%d", &node[i].n , &node[i].li , &node[i].ri);
      if( node[i].li != -1 )
	{
	  node[ node[i].li ].p = i;
	  node[ node[i].li ].s = 0;
	}
      if( node[i].ri != -1 )
	{
	  node[ node[i].ri ].p = i;
	  node[ node[i].ri ].s = 1;
	}
      a[ ++t ] = node[i].n;
    }
  qsort( a, t+1, sizeof(int), cmp );
  int p = 0,temp = a[0];
  ndex = -1;
  while( p < t )
    {

      a[ ++ndex ] = a[p];
      temp = a[p];
       while( p < t && a[++p] == temp );
      //  cout<<"u"<<a[ndex];
    }
  if( a[ndex] != a[t] )
    a[++ndex] = a[t];
  for( int i=0; i<=ndex; ++i )
    success[i] = -1;
  for( int i=1; i<=n; ++i )
    if( node[i].p == -1 )
      {
	root = i;
	break;
      }
  node[ root ].ll = INT_MIN;
  node[ root ].rl = INT_MAX;
  dfs(node[ root ]);
  // for( int i=0; i<=ndex; ++i)
  //   if( success[i] == -1 )
  //     {
  // 	++ount;
  // 	//		cout<<a[i]<<" "<<success[i]<<"\n";
  //     }
  printf("%d",ount);
  return 0;
}

int dfs( Node v )
{
  if( v.li != -1 )
    {
      node[ v.li ].ll = v.ll;
      node[ v.li ].rl = v.n < v.rl? v.n : v.rl;
      dfs( node[ v.li ] );
    }
  if( v.ri != -1 )
    {
      node[ v.ri ].rl = v.rl;
      node[ v.ri ].ll = v.n > v.ll? v.n : v.ll;
      dfs( node[ v.ri ] );
    }
  if( ( v.n < v.ll || v.n >= v.rl ) )
    ++ount;
  return 0;
}

int bns( int n )
{
  int beg = 0, end = ndex,mid;
  while( beg <= end )
    {
      mid = beg+ (end-beg)/2;
      if( a[mid] == n )
	return mid;
      else if( a[mid] > n )
	end = mid-1;
      else
	beg = mid + 1;
    }
  //  printf("dsfafsadf\n");
  return -1;
}


#include<iostream>
#include<cstdio>
#include<climits>
#include<cstdlib>
using namespace std;
struct Node{
  int n,p,li,ri,s,ll,rl;
};

Node node[1000001];
int n,root,ount = 0,ndex;
int a[1000000],t = -1,success[1000000];

int bns(int);
int dfs(Node);
int cmp(const void* a, const void* b)
{  return ( *(int*)a - *(int*)b );  }

int main()
{
  scanf("%d",&n);
  for( int i=1; i<=n; ++i )
    node[i].s = node[i].p = -1;
  for( int i=1; i<=n; ++i )
    {
      scanf("%d%d%d", &node[i].n , &node[i].li , &node[i].ri);
      if( node[i].li != -1 )
	{
	  node[ node[i].li ].p = i;
	  node[ node[i].li ].s = 0;
	}
      if( node[i].ri != -1 )
	{
	  node[ node[i].ri ].p = i;
	  node[ node[i].ri ].s = 1;
	}
      a[ ++t ] = node[i].n;
    }
  qsort( a, t+1, sizeof(int), cmp );
  int p = 0,temp = a[0];
  ndex = -1;
  while( p < t )
    {

      a[ ++ndex ] = a[p];
      temp = a[p];
       while( p < t && a[++p] == temp );
      //  cout<<"u"<<a[ndex];
    }
  if( a[ndex] != a[t] )
    a[++ndex] = a[t];

  for( int i=0; i<=ndex; ++i )
    success[i] = -1;
  for( int i=1; i<=n; ++i )
    if( node[i].p == -1 )
      {
	root = i;
	break;
      }
  node[ root ].ll = INT_MIN;
  node[ root ].rl = INT_MAX;
  dfs(node[ root ]);
  for( int i=0; i<=ndex; ++i)
    if( success[i] == -1 )
      {
  	++ount;
  	//		cout<<a[i]<<" "<<success[i]<<"\n";
      }
  printf("%d",ount);
  return 0;
}

int dfs( Node v )
{
  if( v.li != -1 )
    {
      node[ v.li ].ll = v.ll;
      node[ v.li ].rl = v.n < v.rl? v.n : v.rl;
      dfs( node[ v.li ] );
    }
  if( v.ri != -1 )
    {
      node[ v.ri ].rl = v.rl;
      node[ v.ri ].ll = v.n > v.ll? v.n : v.ll;
      dfs( node[ v.ri ] );
    }
  if( !( v.n < v.ll || v.n > v.rl ) )
    success[ bns( v.n ) ] = 1;
  return 0;
}

int bns( int n )
{
  int beg = 0, end = ndex,mid;
  while( beg <= end )
    {
      mid = beg+ (end-beg)/2;
      if( a[mid] == n )
	return mid;
      else if( a[mid] > n )
	end = mid-1;
      else
	beg = mid + 1;
    }
  //  printf("dsfafsadf\n");
  return -1;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, val[N], l[N], r[N];
bool vis[N];

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    // printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>=biggerThan && val[node]<smallerThan) )
        ans++;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
   }
   for(int i=1;i<=n;i++)
    if(vis[i]==0)
       root=i;
   Check(root, -1, M);
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];
map<int, bool> reachable;

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    //printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>=biggerThan && val[node]<smallerThan) )
        reachable[val[node]]=true;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
     reachable[val[i]]=0;
   }
   for(int i=1;i<=n;i++){
    if(vis[i]==0)
       root=i;
   }
   Check(root, -1, M);
   for(int i=1;i<=n;i++){
     if(reachable[val[i]])
        ans++;
   }
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, val[N], l[N], r[N];
bool vis[N];

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    // printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>biggerThan && val[node]<smallerThan) )
        ans++;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
   }
   for(int i=1;i<=n;i++)
    if(vis[i]==0)
       root=i;
   Check(root, -1, M);
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1 || (smallerThan<biggerThan))
        return;
    // printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>biggerThan && val[node]<smallerThan) )
        ans++;
    reached++;
    Check(l[node], biggerThan, val[node]);
    Check(r[node], val[node], smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
   }
   for(int i=1;i<=n;i++)
    if(vis[i]==0)
       root=i;
   Check(root, -1, M);
   cout<<ans+(n-reached);

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];
map<int, bool> reachable;

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    //printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if(val[node]>=biggerThan && val[node]<smallerThan)
        reachable[val[node]]=true;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
     reachable[val[i]]=0;
   }
   for(int i=1;i<=n;i++){
    if(vis[i]==0)
       root=i;
   }
   Check(root, -1, M);
   for(int i=1;i<=n;i++){
     if(!reachable[val[i]])
        ans++;
   }
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];
map<int, bool> reachable;

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    //printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if(val[node]>biggerThan && val[node]<smallerThan)
        reachable[val[node]]=true;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
     reachable[val[i]]=0;
   }
   for(int i=1;i<=n;i++){
    if(vis[i]==0)
       root=i;
   }
   Check(root, -1, M);
   for(int i=1;i<=n;i++){
     if(!reachable[val[i]])
        ans++;
   }
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];
map<int, bool> reachable;

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1)
        return;
    //printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>biggerThan && val[node]<smallerThan) )
        reachable[val[node]]=true;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
     reachable[val[i]]=0;
   }
   for(int i=1;i<=n;i++){
    if(vis[i]==0)
       root=i;
   }
   Check(root, -1, M);
   for(int i=1;i<=n;i++){
     if(reachable[val[i]])
        ans++;
   }
   cout<<ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=100010, M=1e9+1;
int n, root, ans, reached, val[N], l[N], r[N];
bool vis[N];

void Check(int node, int biggerThan, int smallerThan)
{
    if(node==-1 || (smallerThan<biggerThan))
        return;
    // printf("%d,%d,%d,%d    ",node, biggerThan, smallerThan, val[node]);
    if( !(val[node]>biggerThan && val[node]<smallerThan) )
        ans++;
    reached++;
    Check(l[node], biggerThan, min(val[node], smallerThan));
    Check(r[node], max(biggerThan, val[node]), smallerThan);
}

int main()
{
   //freopen("r.txt","r", stdin);
   scanf("%d", &n);
   for(int i=1;i<=n;i++){
     scanf("%d %d %d", &val[i], &l[i], &r[i]);
     vis[l[i]]=vis[r[i]]=1;
   }
   for(int i=1;i<=n;i++)
    if(vis[i]==0)
       root=i;
   Check(root, -1, M);
   cout<<ans+(n-reached);

    return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define INF 0x3f3f3f3f
#define mt make_tuple
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
const int N = 400010;

struct Node {
	int v, id, sz;
	Node *p, *l, *r;
	Node () {}
	Node (int v, int id) : v(v), id(id) {
		sz = 1;
		l = r = p = NULL;
	}
	void print() {
		printf("Node\n");
		printf("val %d sz %d\n", v, sz);

		printf("pai: ");
		if (!p) printf("vazio\n");
		else printf("%d\n", p->v);

		printf("left: ");
		if (!l) printf("vazio\n");
		else printf("%d\n", l->v);

		printf("right: ");
		if (!r) printf("vazio\n");
		else printf("%d\n", r->v);
	}
};
void dfs (Node *t) {
	if (t == NULL) return ;
	dfs (t->l);
	t->print();
	dfs (t->r);
}

void fix (Node *t) {
	t->sz = 1;
	if (t->l) t->sz += t->l->sz;
	if (t->r) t->sz += t->r->sz;
}
void link_left(Node *t, Node *c) {
	t->l = c;
	if (c) c->p = t;
	fix(t);
}

void link_right(Node *t, Node *c) {
	t->r = c;
	if (c) c->p = t;
	fix(t);
}

void rotateLeft(Node *t) {
	Node *x = t->r, *y = t->p;
	link_right(t, x->l);
	link_left(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

void rotateRight(Node *t) {
	Node *x = t->l, *y = t->p;
	link_left(t, x->r);
	link_right(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

Node* splay(Node *t) {
	if (!t) return t;
	while (t->p) {
		if (t == t->p->l) {
			if (!t->p->p) rotateRight(t->p);
			else if (t->p == t->p->p->l) {
				rotateRight(t->p->p);
				rotateRight(t->p);
			} else {
				rotateRight(t->p);
				rotateLeft (t->p);
			}
		} else {
			if (!t->p->p) rotateLeft(t->p);
			else if (t->p == t->p->p->r) {
				rotateLeft (t->p->p);
				rotateLeft (t->p);
			} else {
				rotateLeft (t->p);
				rotateRight(t->p);
			}
		}
	}
	return t;
}

Node *find (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	Node *ret = nullptr;
	if (val > t->v) ret = find (t->r, val, id);
	else if (val < t->v)  ret = find (t->l, val, id);
	else if (id > t->id) ret = find(t->r, val, id);
	else if (id < t->id) ret = find(t->l, val, id);
	return ret ? ret : splay(t);
}
pair<Node*, Node*> split (Node *t, int val, int id) {
	if (t == NULL) return mp(nullptr, nullptr);
	t = find(t, val, id);
	Node *outra;
	if (t->v < val or (t->v == val and t->id <= id)) {
		outra = t->r;
		link_right(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(t, outra);
	} else {
		outra = t->l;
		link_left(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(outra, t);
	}
}
Node *merge (Node *t1, Node *t2) {
	if (t1 == NULL or t2 == NULL) return t1 ? t1 : t2;
	while (t1->r) t1 = t1->r;
	t1 = splay(t1);
	link_right (t1, t2);
	return t1;
}
Node *insert (Node *t, int val, int id) {
	Node *l, *r;
	tie (l, r)= split (t, val, id);
	Node *novo = new Node (val, id);
	link_left (novo, l);
	link_right(novo, r);
	return novo;
}
Node *erase (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	t = find(t, val, id);
	assert(t->v == val and t->id == id);

	if (t->v != val or (t->v == val and t->id != id)) return t;

	Node *l, *r;
	tie (l, r) = split (t, val, id);
	if (l->l) l->l->p = nullptr;

	return merge(l->l, r);
}
int kTh (Node *t, int k) {
	if ( (t->l ? t->l->sz : 0) + 1 == k) return t->v;
	if (t->l and t->l->sz >= k) return kTh (t->l, k);
	return kTh (t->r, k - (t->l ? t->l->sz : 0) - 1);
}
pair<int, Node* >countMaior (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x+1, -1);
	int qtd = r ? r->sz : 0;
	return mp (qtd, merge (l, r));
}
pair<int, Node* >countMenor (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x, -1);
	int qtd = l ? l->sz : 0;
	pair<int, Node *> lul = mp (qtd, merge (l, r));
	return lul;

}
int l[N], r[N], v[N], ans;
int cnt = 1;
Node *solve (int u) {
	if (u == -1) return nullptr;
	Node *left = solve(l[u]);
	Node *novo = nullptr;
	novo = insert(novo, v[u], cnt++);
	Node *right = solve(r[u]);

	int qtd;
	//quantos maiores que v[u] tem em left
	tie (qtd, left) = countMaior (left, v[u]);
	ans += qtd;
	//quantos menores que v[u] tem em right
	qtd = 0;
	tie (qtd, right) = countMenor (right, v[u]);
	ans += qtd;

	Node *aux;
	//excluindo maiores que v[u] em left
	tie (left, aux) = split(left, v[u]+1, -1);
	//excluindo menores que v[u] em right
	tie (aux, right) = split(right, v[u], -1);

	novo = merge(left, novo);
	novo = merge(novo, right);

	return novo;
}
int main (void) {
	int n; scanf("%d", &n);
	set <int> root;
	for (int i = 1; i <= n; i++) root.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", v+i, l+i, r+i);
		root.erase(l[i]);
		root.erase(r[i]);
	}
	solve (*(root.begin()));
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define INF 0x3f3f3f3f
#define mt make_tuple
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
const int N = 400010;

struct Node {
	int v, id, sz;
	Node *p, *l, *r;
	Node () {}
	Node (int v, int id) : v(v), id(id) {
		sz = 1;
		l = r = p = NULL;
	}
	void print() {
		printf("Node\n");
		printf("val %d sz %d\n", v, sz);

		printf("pai: ");
		if (!p) printf("vazio\n");
		else printf("%d\n", p->v);

		printf("left: ");
		if (!l) printf("vazio\n");
		else printf("%d\n", l->v);

		printf("right: ");
		if (!r) printf("vazio\n");
		else printf("%d\n", r->v);
	}
};
void dfs (Node *t) {
	if (t == NULL) return ;
	dfs (t->l);
	t->print();
	dfs (t->r);
}

void fix (Node *t) {
	t->sz = 1;
	if (t->l) t->sz += t->l->sz;
	if (t->r) t->sz += t->r->sz;
}
void link_left(Node *t, Node *c) {
	t->l = c;
	if (c) c->p = t;
	fix(t);
}

void link_right(Node *t, Node *c) {
	t->r = c;
	if (c) c->p = t;
	fix(t);
}

void rotateLeft(Node *t) {
	Node *x = t->r, *y = t->p;
	link_right(t, x->l);
	link_left(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

void rotateRight(Node *t) {
	Node *x = t->l, *y = t->p;
	link_left(t, x->r);
	link_right(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

Node* splay(Node *t) {
	if (!t) return t;
	while (t->p) {
		if (t == t->p->l) {
			if (!t->p->p) rotateRight(t->p);
			else if (t->p == t->p->p->l) {
				rotateRight(t->p->p);
				rotateRight(t->p);
			} else {
				rotateRight(t->p);
				rotateLeft (t->p);
			}
		} else {
			if (!t->p->p) rotateLeft(t->p);
			else if (t->p == t->p->p->r) {
				rotateLeft (t->p->p);
				rotateLeft (t->p);
			} else {
				rotateLeft (t->p);
				rotateRight(t->p);
			}
		}
	}
	return t;
}

Node *find (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	Node *ret = nullptr;
	if (val > t->v) ret = find (t->r, val, id);
	else if (val < t->v)  ret = find (t->l, val, id);
	else if (id > t->id) ret = find(t->r, val, id);
	else if (id < t->id) ret = find(t->l, val, id);
	return ret ? ret : splay(t);
}
pair<Node*, Node*> split (Node *t, int val, int id) {
	if (t == NULL) return mp(nullptr, nullptr);
	t = find(t, val, id);
	Node *outra;
	if (t->v < val or (t->v == val and t->id <= id)) {
		outra = t->r;
		link_right(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(t, outra);
	} else {
		outra = t->l;
		link_left(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(outra, t);
	}
}
Node *merge (Node *t1, Node *t2) {
	if (t1 == NULL or t2 == NULL) return t1 ? t1 : t2;
	while (t1->r) t1 = t1->r;
	t1 = splay(t1);
	link_right (t1, t2);
	return t1;
}
Node *insert (Node *t, int val, int id) {
	Node *l, *r;
	tie (l, r)= split (t, val, id);
	Node *novo = new Node (val, id);
	link_left (novo, l);
	link_right(novo, r);
	return novo;
}
Node *erase (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	t = find(t, val, id);
	assert(t->v == val and t->id == id);

	if (t->v != val or (t->v == val and t->id != id)) return t;

	Node *l, *r;
	tie (l, r) = split (t, val, id);
	if (l->l) l->l->p = nullptr;

	return merge(l->l, r);
}
int kTh (Node *t, int k) {
	if ( (t->l ? t->l->sz : 0) + 1 == k) return t->v;
	if (t->l and t->l->sz >= k) return kTh (t->l, k);
	return kTh (t->r, k - (t->l ? t->l->sz : 0) - 1);
}
pair<int, Node* >countMaior (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x+1, -1);
	int qtd = r ? r->sz : 0;
	return mp (qtd, merge (l, r));
}
pair<int, Node* >countMenor (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x, -1);
	int qtd = l ? l->sz : 0;
	pair<int, Node *> lul = mp (qtd, merge (l, r));
	return lul;

}
int l[N], r[N], v[N], ans;
int cnt = 1;
Node *solve (int u) {
	if (u == -1) return nullptr;
	Node *left = solve(l[u]);
	Node *right = solve(r[u]);
	Node *novo = nullptr;
	novo = insert(novo, v[u], cnt++);

	int qtd;
	//quantos maiores que v[u] tem em left
	tie (qtd, left) = countMaior (left, v[u]);
	ans += qtd;
	//quantos menores que v[u] tem em right
	qtd = 0;
	tie (qtd, right) = countMenor (right, v[u]);
	ans += qtd;

	Node *aux;
	//excluindo maiores que v[u] em left
	tie (left, aux) = split(left, v[u]+1, -1);
	//excluindo menores que v[u] em right
	tie (aux, right) = split(right, v[u], -1);

	novo = merge(left, novo);
	novo = merge(novo, right);

	return novo;
}
int main (void) {
	int n; scanf("%d", &n);
	set <int> root;
	for (int i = 1; i <= n; i++) root.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", v+i, l+i, r+i);
		root.erase(l[i]);
		root.erase(r[i]);
	}
	solve (*(root.begin()));
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define INF 0x3f3f3f3f
#define mt make_tuple
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
const int N = 400010;

struct Node {
	int v, id, sz;
	Node *p, *l, *r;
	Node () {}
	Node (int v, int id) : v(v), id(id) {
		sz = 1;
		l = r = p = NULL;
	}
	void print() {
		printf("Node\n");
		printf("val %d sz %d\n", v, sz);

		printf("pai: ");
		if (!p) printf("vazio\n");
		else printf("%d\n", p->v);

		printf("left: ");
		if (!l) printf("vazio\n");
		else printf("%d\n", l->v);

		printf("right: ");
		if (!r) printf("vazio\n");
		else printf("%d\n", r->v);
	}
};
int ans;
map <int, int> qtd;
set <int> s;
void dfs (Node *t) {
	if (t == NULL) return ;
	if (!s.count(t->v)) {
		ans += qtd[t->v];
	}
	s.insert(t->v);
	dfs (t->l);
//	t->print();
	dfs (t->r);
}

void fix (Node *t) {
	t->sz = 1;
	if (t->l) t->sz += t->l->sz;
	if (t->r) t->sz += t->r->sz;
}
void link_left(Node *t, Node *c) {
	t->l = c;
	if (c) c->p = t;
	fix(t);
}

void link_right(Node *t, Node *c) {
	t->r = c;
	if (c) c->p = t;
	fix(t);
}

void rotateLeft(Node *t) {
	Node *x = t->r, *y = t->p;
	link_right(t, x->l);
	link_left(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

void rotateRight(Node *t) {
	Node *x = t->l, *y = t->p;
	link_left(t, x->r);
	link_right(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

Node* splay(Node *t) {
	if (!t) return t;
	while (t->p) {
		if (t == t->p->l) {
			if (!t->p->p) rotateRight(t->p);
			else if (t->p == t->p->p->l) {
				rotateRight(t->p->p);
				rotateRight(t->p);
			} else {
				rotateRight(t->p);
				rotateLeft (t->p);
			}
		} else {
			if (!t->p->p) rotateLeft(t->p);
			else if (t->p == t->p->p->r) {
				rotateLeft (t->p->p);
				rotateLeft (t->p);
			} else {
				rotateLeft (t->p);
				rotateRight(t->p);
			}
		}
	}
	return t;
}

Node *find (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	Node *ret = nullptr;
	if (val > t->v) ret = find (t->r, val, id);
	else if (val < t->v)  ret = find (t->l, val, id);
	else if (id > t->id) ret = find(t->r, val, id);
	else if (id < t->id) ret = find(t->l, val, id);
	return ret ? ret : splay(t);
}
pair<Node*, Node*> split (Node *t, int val, int id) {
	if (t == NULL) return mp(nullptr, nullptr);
	t = find(t, val, id);
	Node *outra;
	if (t->v < val or (t->v == val and t->id <= id)) {
		outra = t->r;
		link_right(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(t, outra);
	} else {
		outra = t->l;
		link_left(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(outra, t);
	}
}
Node *merge (Node *t1, Node *t2) {
	if (t1 == NULL or t2 == NULL) return t1 ? t1 : t2;
	while (t1->r) t1 = t1->r;
	t1 = splay(t1);
	link_right (t1, t2);
	return t1;
}
Node *insert (Node *t, int val, int id) {
	Node *l, *r;
	tie (l, r)= split (t, val, id);
	Node *novo = new Node (val, id);
	link_left (novo, l);
	link_right(novo, r);
	return novo;
}
Node *erase (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	t = find(t, val, id);
	assert(t->v == val and t->id == id);

	if (t->v != val or (t->v == val and t->id != id)) return t;

	Node *l, *r;
	tie (l, r) = split (t, val, id);
	if (l->l) l->l->p = nullptr;

	return merge(l->l, r);
}
int kTh (Node *t, int k) {
	if ( (t->l ? t->l->sz : 0) + 1 == k) return t->v;
	if (t->l and t->l->sz >= k) return kTh (t->l, k);
	return kTh (t->r, k - (t->l ? t->l->sz : 0) - 1);
}
pair<int, Node* >countMaior (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x+1, -1);
	int qtd = r ? r->sz : 0;
	return mp (qtd, merge (l, r));
}
pair<int, Node* >countMenor (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x, -1);
	int qtd = l ? l->sz : 0;
	pair<int, Node *> lul = mp (qtd, merge (l, r));
	return lul;

}
int l[N], r[N], v[N];
int cnt = 1;
Node *solve (int u) {
	if (u == -1) return nullptr;
	Node *left = solve(l[u]);
	Node *novo = nullptr;
	novo = insert(novo, v[u], cnt++);
	Node *right = solve(r[u]);

	Node *aux;
	//excluindo maiores que v[u] em left
	tie (left, aux) = split(left, v[u]+1, -1);
	//excluindo menores que v[u] em right
	tie (aux, right) = split(right, v[u], -1);

	novo = merge(left, novo);
	novo = merge(novo, right);

	return novo;
}
int main (void) {
	int n; scanf("%d", &n);
	set <int> root;
	for (int i = 1; i <= n; i++) root.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", v+i, l+i, r+i);
		qtd[v[i]]++;
		root.erase(l[i]);
		root.erase(r[i]);
	}
	Node *tree = solve (*(root.begin()));
	dfs (tree);
	cout << n - ans << endl;
	return 0;
}


#include <bits/stdc++.h>

#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define INF 0x3f3f3f3f
#define mt make_tuple
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
const int N = 400010;

struct Node {
	int v, id, sz;
	Node *p, *l, *r;
	Node () {}
	Node (int v, int id) : v(v), id(id) {
		sz = 1;
		l = r = p = NULL;
	}
	void print() {
		printf("Node\n");
		printf("val %d sz %d\n", v, sz);

		printf("pai: ");
		if (!p) printf("vazio\n");
		else printf("%d\n", p->v);

		printf("left: ");
		if (!l) printf("vazio\n");
		else printf("%d\n", l->v);

		printf("right: ");
		if (!r) printf("vazio\n");
		else printf("%d\n", r->v);
	}
};
void dfs (Node *t) {
	if (t == NULL) return ;
	dfs (t->l);
	t->print();
	dfs (t->r);
}

void fix (Node *t) {
	t->sz = 1;
	if (t->l) t->sz += t->l->sz;
	if (t->r) t->sz += t->r->sz;
}
void link_left(Node *t, Node *c) {
	t->l = c;
	if (c) c->p = t;
	fix(t);
}

void link_right(Node *t, Node *c) {
	t->r = c;
	if (c) c->p = t;
	fix(t);
}

void rotateLeft(Node *t) {
	Node *x = t->r, *y = t->p;
	link_right(t, x->l);
	link_left(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

void rotateRight(Node *t) {
	Node *x = t->l, *y = t->p;
	link_left(t, x->r);
	link_right(x, t);

	if (t == (y ? y->l : nullptr)) link_left(y, x);
	else if (t == (y ? y->r : nullptr)) link_right(y, x);
	else x->p = nullptr;
}

Node* splay(Node *t) {
	if (!t) return t;
	while (t->p) {
		if (t == t->p->l) {
			if (!t->p->p) rotateRight(t->p);
			else if (t->p == t->p->p->l) {
				rotateRight(t->p->p);
				rotateRight(t->p);
			} else {
				rotateRight(t->p);
				rotateLeft (t->p);
			}
		} else {
			if (!t->p->p) rotateLeft(t->p);
			else if (t->p == t->p->p->r) {
				rotateLeft (t->p->p);
				rotateLeft (t->p);
			} else {
				rotateLeft (t->p);
				rotateRight(t->p);
			}
		}
	}
	return t;
}

Node *find (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	Node *ret = nullptr;
	if (val > t->v) ret = find (t->r, val, id);
	else if (val < t->v)  ret = find (t->l, val, id);
	else if (id > t->id) ret = find(t->r, val, id);
	else if (id < t->id) ret = find(t->l, val, id);
	return ret ? ret : splay(t);
}
pair<Node*, Node*> split (Node *t, int val, int id) {
	if (t == NULL) return mp(nullptr, nullptr);
	t = find(t, val, id);
	Node *outra;
	if (t->v < val or (t->v == val and t->id <= id)) {
		outra = t->r;
		link_right(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(t, outra);
	} else {
		outra = t->l;
		link_left(t, nullptr);
		if (outra) outra->p = nullptr;
		return mp(outra, t);
	}
}
Node *merge (Node *t1, Node *t2) {
	if (t1 == NULL or t2 == NULL) return t1 ? t1 : t2;
	while (t1->r) t1 = t1->r;
	t1 = splay(t1);
	link_right (t1, t2);
	return t1;
}
Node *insert (Node *t, int val, int id) {
	Node *l, *r;
	tie (l, r)= split (t, val, id);
	Node *novo = new Node (val, id);
	link_left (novo, l);
	link_right(novo, r);
	return novo;
}
Node *erase (Node *t, int val, int id) {
	if (t == NULL) return nullptr;
	t = find(t, val, id);
	assert(t->v == val and t->id == id);

	if (t->v != val or (t->v == val and t->id != id)) return t;

	Node *l, *r;
	tie (l, r) = split (t, val, id);
	if (l->l) l->l->p = nullptr;

	return merge(l->l, r);
}
int kTh (Node *t, int k) {
	if ( (t->l ? t->l->sz : 0) + 1 == k) return t->v;
	if (t->l and t->l->sz >= k) return kTh (t->l, k);
	return kTh (t->r, k - (t->l ? t->l->sz : 0) - 1);
}
pair<int, Node* >countMaior (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x+1, -1);
	return mp (r ? r->sz : 0, merge (l, r));
}
pair<int, Node* >countMenor (Node *t, int x) {
	Node *l, *r;
	tie (l, r) = split(t, x, -1);
	int qtd = l ? l->sz : 0;
	pair<int, Node *> lul = mp (qtd, merge (l, r));
	return lul;

}
int l[N], r[N], v[N], ans;
Node *solve (int u) {
	if (u == -1) return nullptr;
	Node *left = solve(l[u]);
	Node *right = solve(r[u]);
	Node *novo = nullptr;
	novo = insert(novo, v[u], u);

	int qtd;
	//quantos maiores que v[u] tem em left
	tie (qtd, left) = countMaior (left, v[u]);
	ans += qtd;
	//quantos menores que v[u] tem em right
	qtd = 0;
	tie (qtd, right) = countMenor (right, v[u]);
	ans += qtd;

	Node *aux;
	//excluindo maiores que v[u] em left
	tie (left, aux) = split(left, v[u]+1, -1);
	//excluindo menores que v[u] em right
	tie (aux, right) = split(right, v[u], -1);

	novo = merge(left, novo);
	novo = merge(novo, right);

	return novo;
}
int main (void) {
	int n; scanf("%d", &n);
	set <int> root;
	for (int i = 1; i <= n; i++) root.insert(i);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d", v+i, l+i, r+i);
		root.erase(l[i]);
		root.erase(r[i]);
	}
	solve (*(root.begin()));
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
struct ver{
    int v,l,r;
} vertex[100100];
int sub[100100],check[100100],finalans;
int findsub(int x){
    int ans = 0;
    if(vertex[x].l!=-1) ans += findsub(vertex[x].l);
    if(vertex[x].r!=-1) ans += findsub(vertex[x].r);
    return sub[x] = ans+1;
}
void findans(int x,int lower,int upper){
    if(vertex[x].l!=-1){
        if(vertex[vertex[x].l].v>min(vertex[x].v,upper) || vertex[vertex[x].l].v<lower){
          finalans += sub[vertex[x].l];
        }
        else findans(vertex[x].l,lower,min(vertex[x].v,upper));
    }
    if(vertex[x].r!=-1){
        if(vertex[vertex[x].r].v>upper || vertex[vertex[x].r].v<max(lower,vertex[x].v)) finalans += sub[vertex[x].r];
        else findans(vertex[x].r,max(lower,vertex[x].v),upper);
    }
}
int main(){
    cin >> n;
    int i;
    for(i=1;i<=n;i++){
      cin >> vertex[i].v >> vertex[i].l >> vertex[i].r;
      check[vertex[i].l] = 1;
      check[vertex[i].r] = 1;
    }
    int root = 0;
    for(i=1;i<=n;i++){
        if(!check[i]){
            root = i;
            break;
        }
    }
    findsub(root);
    findans(root,-1,1000000001);
    cout << finalans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
struct ver{
    int v,l,r,num;
} vertex[100100];
bool cmp(const ver & x,const ver &y){
    if(x.v<y.v) return true;
    else return false;
}
bool cmpb(const ver & x,const ver &y){
    if(x.num<y.num) return true;
    else return false;
}
int sub[100100],check[100100],finalans;
bool wh[100100];
int findsub(int x){
    int ans = 0;
    if(vertex[x].l!=-1) ans += findsub(vertex[x].l);
    if(vertex[x].r!=-1) ans += findsub(vertex[x].r);
    return sub[x] = ans+1;
}
void findans(int x,int lower,int upper){
    if(vertex[x].l!=-1){
        if(vertex[vertex[x].l].v>min(vertex[x].v,upper) || vertex[vertex[x].l].v<lower);
        else wh[vertex[x].l] = true;
        findans(vertex[x].l,lower,min(vertex[x].v,upper));

    }
    if(vertex[x].r!=-1){
        if(vertex[vertex[x].r].v>upper || vertex[vertex[x].r].v<max(lower,vertex[x].v));
        else wh[vertex[x].r] = true;
        findans(vertex[x].r,max(lower,vertex[x].v),upper);

    }
}
int main(){
    cin >> n;
    int i;
    for(i=1;i<=n;i++){
      cin >> vertex[i].v >> vertex[i].l >> vertex[i].r;
      check[vertex[i].l] = 1;
      check[vertex[i].r] = 1;
      vertex[i].num = i;
    }
    int root = 0;
    for(i=1;i<=n;i++){
        if(!check[i]){
            root = i;
            break;
        }
    }

    memset(check,false,sizeof(check));
    sort(vertex+1,vertex+n+1,cmp);
    for(i=2;i<=n;i++){
        if(vertex[i].v==vertex[i-1].v) check[i] = 1;
    }
    vertex[1].v = 1;
    for(i=2;i<=n;i++){
        if(check[i]) vertex[i].v = vertex[i-1].v;
        else vertex[i].v = i;
    }
    sort(vertex+1,vertex+n+1,cmpb);
    wh[root] = true;
    findans(root,-1,1000000001);
    memset(check,false,sizeof(check));
    for(i=1;i<=n;i++) if(wh[i]) check[vertex[i].v] = true;
    for(i=1;i<=n;i++){
        if(!check[vertex[i].v]){
            finalans++;
        }
    }
    cout << finalans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
struct ver{
    int v,l,r;
} vertex[100100];
int sub[100100],check[100100],finalans;
bool wh[100100];
int findsub(int x){
    int ans = 0;
    if(vertex[x].l!=-1) ans += findsub(vertex[x].l);
    if(vertex[x].r!=-1) ans += findsub(vertex[x].r);
    return sub[x] = ans+1;
}
void findans(int x,int lower,int upper){
    if(vertex[x].l!=-1){
        if(vertex[vertex[x].l].v>min(vertex[x].v,upper) || vertex[vertex[x].l].v<lower);
        else wh[vertex[x].l] = true;
        findans(vertex[x].l,lower,min(vertex[x].v,upper));

    }
    if(vertex[x].r!=-1){
        if(vertex[vertex[x].r].v>upper || vertex[vertex[x].r].v<max(lower,vertex[x].v));
        else wh[vertex[x].r] = true;
        findans(vertex[x].r,max(lower,vertex[x].v),upper);

    }
}
int main(){
    cin >> n;
    int i;
    for(i=1;i<=n;i++){
      cin >> vertex[i].v >> vertex[i].l >> vertex[i].r;
      check[vertex[i].l] = 1;
      check[vertex[i].r] = 1;
    }
    int root = 0;
    for(i=1;i<=n;i++){
        if(!check[i]){
            root = i;
            break;
        }
    }
    findsub(root);
    wh[root] = true;
    findans(root,-1,1000000001);
    for(i=1;i<=n;i++) if(!wh[i]) finalans++;
    cout << finalans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
struct ver{
    int v,l,r;
} vertex[100100];
int sub[100100],check[100100],finalans;
bool wh[100100];
int findsub(int x){
    int ans = 0;
    if(vertex[x].l!=-1) ans += findsub(vertex[x].l);
    if(vertex[x].r!=-1) ans += findsub(vertex[x].r);
    return sub[x] = ans+1;
}
void findans(int x,int lower,int upper){
    if(vertex[x].l!=-1){
        if(vertex[vertex[x].l].v>min(vertex[x].v,upper) || vertex[vertex[x].l].v<lower);
        else wh[vertex[x].l] = true;
        findans(vertex[x].l,lower,min(vertex[x].v,upper));

    }
    if(vertex[x].r!=-1){
        if(vertex[vertex[x].r].v>upper || vertex[vertex[x].r].v<max(lower,vertex[x].v));
        else wh[vertex[x].r] = true;
        findans(vertex[x].r,max(lower,vertex[x].v),upper);

    }
}
int main(){
    cin >> n;
    int i;
    for(i=1;i<=n;i++){
      cin >> vertex[i].v >> vertex[i].l >> vertex[i].r;
      check[vertex[i].l] = 1;
      check[vertex[i].r] = 1;
    }
    int root = 0;
    for(i=1;i<=n;i++){
        if(!check[i]){
            root = i;
            break;
        }
    }
    memset(check,false,sizeof(check));
    findsub(root);
    wh[root] = true;
    findans(root,-1,1000000001);
    for(i=1;i<=n;i++) if(wh[i]) check[vertex[i].v] = true;
    for(i=1;i<=n;i++){
        if(!check[vertex[i].v]){
            finalans++;
        }
    }
    cout << finalans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n;
struct ver{
    int v,l,r;
} vertex[100100];
int sub[100100],check[100100],finalans;
bool wh[100100];
int findsub(int x){
    int ans = 0;
    if(vertex[x].l!=-1) ans += findsub(vertex[x].l);
    if(vertex[x].r!=-1) ans += findsub(vertex[x].r);
    return sub[x] = ans+1;
}
void findans(int x,int lower,int upper){
    if(vertex[x].l!=-1){
        if(vertex[vertex[x].l].v>=min(vertex[x].v,upper) || vertex[vertex[x].l].v<=lower);
        else wh[vertex[x].l] = true;
                findans(vertex[x].l,lower,min(vertex[x].v,upper));

    }
    if(vertex[x].r!=-1){
        if(vertex[vertex[x].r].v>=upper || vertex[vertex[x].r].v<=max(lower,vertex[x].v));
        else wh[vertex[x].r] = true;
        findans(vertex[x].r,max(lower,vertex[x].v),upper);

    }
}
int main(){
    cin >> n;
    int i;
    for(i=1;i<=n;i++){
      cin >> vertex[i].v >> vertex[i].l >> vertex[i].r;
      check[vertex[i].l] = 1;
      check[vertex[i].r] = 1;
    }
    int root = 0;
    for(i=1;i<=n;i++){
        if(!check[i]){
            root = i;
            break;
        }
    }
    findsub(root);
    wh[root] = true;
    findans(root,-1,1000000001);
    for(i=1;i<=n;i++) if(!wh[i]) finalans++;
    cout << finalans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif

#define N 100010
int ans;
int n, a[N], lc[N], rc[N], mark[N], sz[N], c[N];

void dfs(int u, int l, int r) {
  if (u == -1 || l > r)
    return;
  // printf("%d %d %d\n", u, l, r);
  dfs(lc[u], l, min(r, a[u]-1));
  dfs(rc[u], max(l, a[u]+1), r);
  if (l <= a[u] && a[u] <= r)
    ans -= c[a[u]];
}

int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  FOR (i, n) {
    scanf("%d%d%d", &a[i], &lc[i], &rc[i]);
    c[a[i]]++;
    if (lc[i] != -1)
      mark[lc[i]] = 1;
    if (rc[i] != -1)
      mark[rc[i]] = 1;
  }
  ans = n;
  FOR (i, n)
    if (!mark[i]) {
      dfs(i, -1e9, 1e9);
      printf("%d\n", ans);
      return 0;
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif

#define N 100010
int ans;
int n, a[N], lc[N], rc[N], mark[N], sz[N];
map<int, int> c;

void dfs(int u, int l, int r) {
  if (u == -1 || l > r)
    return;
  // printf("%d %d %d\n", u, l, r);
  dfs(lc[u], l, min(r, a[u]-1));
  dfs(rc[u], max(l, a[u]+1), r);
  if (l <= a[u] && a[u] <= r)
    ans -= c[a[u]];
}

int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  FOR (i, n) {
    scanf("%d%d%d", &a[i], &lc[i], &rc[i]);
    c[a[i]]++;
    if (lc[i] != -1)
      mark[lc[i]] = 1;
    if (rc[i] != -1)
      mark[rc[i]] = 1;
  }
  ans = n;
  FOR (i, n)
    if (!mark[i]) {
      dfs(i, -1e9, 1e9);
      printf("%d\n", ans);
      return 0;
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif

#define N 100010
int ans;
int n, a[N], lc[N], rc[N], mark[N], sz[N];

void dfs(int u, int l, int r) {
  if (u == -1 || l > r)
    return;
  // printf("%d %d %d\n", u, l, r);
  dfs(lc[u], l, min(r, a[u]-1));
  dfs(rc[u], max(l, a[u]+1), r);
  if (l <= a[u] && a[u] <= r)
    ans--;
}

int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  FOR (i, n) {
    scanf("%d%d%d", &a[i], &lc[i], &rc[i]);
    if (lc[i] != -1)
      mark[lc[i]] = 1;
    if (rc[i] != -1)
      mark[rc[i]] = 1;
  }
  ans = n;
  FOR (i, n)
    if (!mark[i]) {
      dfs(i, -1e9, 1e9);
      printf("%d\n", ans);
      return 0;
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif

#define N 100010
int ans;
int n, a[N], lc[N], rc[N], mark[N], sz[N];

void dfs(int u, int l, int r) {
  if (u == -1)
    return;
  // printf("%d %d %d\n", u, l, r);
  dfs(lc[u], l, min(r, a[u]-1));
  dfs(rc[u], max(l, a[u]+1), r);
  if (l <= a[u] && a[u] <= r)
    ans--;
}

int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  FOR (i, n) {
    scanf("%d%d%d", &a[i], &lc[i], &rc[i]);
    if (lc[i] != -1)
      mark[lc[i]] = 1;
    if (rc[i] != -1)
      mark[rc[i]] = 1;
  }
  ans = n;
  FOR (i, n)
    if (!mark[i]) {
      dfs(i, -1e9, 1e9);
      printf("%d\n", ans);
      return 0;
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5, INF=0x3f3f3f3f;
int N, w[MAXN], l[MAXN], r[MAXN], fa[MAXN], ans;
map<int, int> c;
void dfs(int u, int a, int b){
	if(u==-1) return;
	if(a>b) return;
	if(a<=w[u]&&w[u]<=b) ans+=c[w[u]];
	dfs(l[u], a, min(w[u]-1,b));
	dfs(r[u], max(w[u]+1,a), b);
}
int main(){
	scanf("%d", &N);
	for(int i=1; i<=N; ++i){
		scanf("%d%d%d", w+i, l+i, r+i);
		c[w[i]]++;
		fa[l[i]]=fa[r[i]]=i;
	}
	for(int i=1; i<=N; ++i) if(!fa[i]) dfs(i,0,INF);
	printf("%d\n", N-ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 1; i <= n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
#define MP make_pair
#define FI first
#define SE second
#define VI vector<int>
#define CLR(x) memset(x, 0, sizeof(x))
#define SZ(x) (x.size())
#ifdef QWERTIER
#define err(x) cerr<<x<<endl;
#else
#define err(x)
#endif

#define N 100010
int ans;
int n, a[N], mark[N], lc[N], rc[N];
multiset<int> st[N];
multiset<int>& union_set(multiset<int> &l, multiset<int> &r) {
  if (l.size() <= r.size()) {
    for (auto v : l) {
      r.insert(v);
    }
    return r;
  } else {
    for (auto v : r) {
      l.insert(v);
    }
    return l;
  }
}

void print(multiset<int> &st, int u) {
  printf("%d\n", u);
  for (auto v : st)
    printf("%d ", v);
  puts("");
}

multiset<int> &dfs(int u) {
  if (u == -1)
    return st[0];
  //printf("%d %d\n",u , a[u]);
  multiset<int> &l = dfs(lc[u]), &r = dfs(rc[u]);
  if (rc[u] != -1) {
    for (auto it = r.begin(), it2 = r.begin(); it != r.end() && *it < a[u]; it = it2, it2 = it) {
      ++it2;
      r.erase(*it);
      ans++;
    }
  }
  if (lc[u] != -1) {
    for (auto it = l.upper_bound(a[u]), it2 = it; it != l.end(); it = it2, it2 = it ) {
      ++it2;
      l.erase(*it);
      ans++;
    }
  }
  if (lc[u] != -1 && rc[u] != -1) {
    multiset<int> &res = union_set(l, r);
    res.insert(a[u]);
    return res;
  } else if (lc[u] != -1) {
    l.insert(a[u]);
    return l;
  } else if (rc[u] != -1) {
    r.insert(a[u]);
    return r;
  } else {
    st[u].insert(a[u]);
    return st[u];
  }
}

int main() {
#ifdef QWERTIER
  freopen("in.txt", "r", stdin);
#endif
  scanf("%d", &n);
  FOR (i, n) {
    scanf("%d%d%d", &a[i], &lc[i], &rc[i]);
    if (lc[i] != -1)
      mark[lc[i]] = 1;
    if (rc[i] != -1)
      mark[rc[i]] = 1;
  }
  FOR (i, n)
    if (!mark[i]) {
      dfs(i);
      printf("%d\n", ans);
      return 0;
    }
  printf("%d\n", ans);
  return 0;

}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    ok[u]=left<=v[u]&&v[u]<=right;
    if(~l[u])dfs(l[u],left,min(v[u]-1,right));
    if(~r[u])dfs(r[u],max(v[u],left),right);
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n),dfs(root,0,1e9);
    bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)ans+=j-i;
    }
    PUTI(ans);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u)
{
    if(~l[u])
    {
        ok[l[u]]=v[l[u]]<v[u];
        if(ok[l[u]])dfs(l[u]);
    }
    if(~r[u])
    {
        ok[r[u]]=v[r[u]]>=v[u];;
        if(ok[r[u]])dfs(r[u]);
    }
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n);
    ok[root]=true,dfs(root);
    bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=true,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)++ans;
    }
    PUTI(ans);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    ok[u]=left<=v[u]&&v[u]<=right;
    if(~l[u])dfs(l[u],left,min(v[u]-1,right));
    if(~r[u])dfs(r[u],max(v[u],left),right);
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n),dfs(root,0,1e9);
    bool yes;
    int i=0,j,k,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        k=i;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)ans+=j-k;
    }
    PUTI(ans);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    if(~l[u])
    {
        ok[l[u]]=left<=v[l[u]]&&v[l[u]]<=min(v[u]-1,right);
        if(ok[l[u]])dfs(l[u],left,min(v[u]-1,right));
    }
    if(~r[u])
    {
        ok[r[u]]=max(left,v[u])<=v[r[u]]&&v[r[u]]<=right;
        if(ok[r[u]])dfs(r[u],max(left,v[u]),right);
    }
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n);
    ok[root]=true,dfs(root,0,1e9);
    bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)++ans;
    }
    PUTI(ans);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    ok[u]=left<=v[u]&&v[u]<=right;
    if(~l[u])dfs(l[u],left,min(v[u]-1,right));
    if(~r[u])dfs(r[u],max(v[u],left),right);
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root,ans=0;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n),dfs(root,0,1e9);
    REP_1(i,n)ans+=!ok[i];
    PUTI(ans);
    /*bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)++ans;
    }
    PUTI(ans);*/
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    ok[u]=left<=v[u]&&v[u]<=right;
    if(~l[u])dfs(l[u],left,min(v[u]-1,right));
    if(~r[u])dfs(r[u],max(v[u],left),right);
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n),dfs(root,0,1e9);
    bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)++ans;
    }
    PUTI(ans);
    return 0;
}


#include <bits/stdc++.h>
//#include <ext/hash_map>
//using namespace __gnu_cxx;
typedef long long LL;
typedef unsigned long long ULL;
#define RDI(x) scanf("%d",&x)
#define RDI_2(x,y) scanf("%d%d",&x,&y)
#define RDD(x) scanf("%lf",&x)
#define RDD_2(x,y) scanf("%lf%lf",&x,&y)
#define RDL(x) scanf("%I64d",&x)
#define RDL_2(x,y) scanf("%I64d%I64d",&x,&y)
#define RDS(x) scanf("%s",x)
#define RDS_2(x,y) scanf("%s%s",x,y)
#define PUTI(x) printf("%d",x)
#define PUTL(x) printf("%I64d",x)
#define PUTF(x) printf("%f",x)
#define PUTC(x) putchar(x)
#define LINE putchar('\n')
#define SPACE putchar(' ')
#define REP(i,x) for(int i=0;i<int(x);++i)
#define REP_1(i,x) for(int i=1;i<=int(x);++i)
#define FOR_EDGE(i,x) for(int i=head[x];~i;i=edge[i].next)
#define FOR_EDGE2(x,i,y) for(int i=head[x][y];~i;i=edge[i].next)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);++i)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);--i)
#define DWN(i,x) for(int i=int(x-1);i>=0;--i)
#define DWN_1(i,x) for(int i=int(x);i>0;--i)
#define FIL(x,v) memset(x,v,sizeof(x))
#define CLR(x) memset(x,0,sizeof(x))
#define ALL(x) x.begin(),x.end()
#define p_queue priority_queue
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define x first
#define y second
#define mp(x,y) make_pair(x,y)
#define check(x) printf("%s=%d\n",#x,x)
using namespace std;
template<typename T>
T gcd(T a, T b){ return b == 0 ? a : gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){ return a / gcd(a, b)*b; }
template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b==0){x=1,y=0;return a;}
    T d=ext_gcd(b,a%b,y,x);
    y-=x*(a/b);
    return d;
}
template<typename T>
T inverse(T a, T n)
{
    T x,y;
    T t=ext_gcd(a,n,x,y);
    if(t!=1)return -1;
    return (x%n+n)%n;
}
template<typename T>
T Q_mul(T a,T b,T Mod)
{
    T ret;
    for(ret =0;b;b>>=1,a=(a+a)%Mod)if(b&1)ret=(ret+a)%Mod;
    return ret;
}
template<typename T>
T quick_pow_mod(T a, T b,T Mod)
{
    T ret;
    for(ret=1;b;b>>=1,(a*=a)%=Mod)if(b&1)(ret*=a)%=Mod;
    return ret;
}
template<typename T>
T quick_pow(T a, T b)
{
    T ret;
    for(ret=1;b;b>>=1,a*=a)if(b&1)ret*=a;
    return ret;
}
double combination(int n, int r)
{
    if (r<n - r) return combination(n, n - r);
    double s = 1.0;
    REP_1(i, n - r) s *= (r + i), s /= i;
    return s;
}
template<typename T>
inline void read(T& v)
{
    T ret=0,sgnv=1;
    char p;
    while(!isdigit(p=getchar()))if(p=='-')sgnv=-1;
    do ret=(ret<<3)+(ret<<1)+p-'0';while(isdigit(p=getchar()));
    v=sgnv*ret;
}
//const double eps=1e-8;
//inline int sgn(double x){ return (x>-eps)-(x<eps); }
//const LL mod=1000000007;
//const double INF = 1e9;
//const LL INF = numeric_limits<LL>::max();
//const int INF=0x3f3f3f3f;
//const int INFCELL = 0x7f;
//const int NINFCELL = 0x80;
//const int NINF = 0x80808080;
#define MAX 100000+5
int l[MAX],r[MAX],v[MAX],degree[MAX];
bool ok[MAX];
pair<int,int> a[MAX];
void dfs(int u,int left,int right)
{
    ok[u]=left<=v[u]&&v[u]<=right;
    if(~l[u])dfs(l[u],left,min(v[u]-1,right));
    if(~r[u])dfs(r[u],max(v[u],left),right);
}
int main()
{
    //freopen("test.in","r",stdin);
    int n,root,ans=0;
    read(n);
    REP_1(i,n)
    {
        read(v[i]),read(l[i]),read(r[i]),a[i-1].x=v[i],a[i-1].y=i;
        if(~l[i])++degree[l[i]];
        if(~r[i])++degree[r[i]];
    }
    REP_1(i,n)if(!degree[i]){root=i;break;}
    sort(a,a+n),dfs(root,0,1e9);
    bool yes;
    int i=0,j,ans=0;
    while(i<n)
    {
        yes=false,j=i+1;
        while(j<n&&a[j].x==a[i].x)++j;
        while(i<j)yes=yes||ok[a[i].y],++i;
        if(!yes)ans+=j-i;
    }
    PUTI(ans);
    return 0;
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.geom.*;

import static java.lang.Math.*;

 public class Solution implements Runnable {
	 static Vector<Integer>[] tree;
    public void solve() throws Exception {

//    		int t=sc.nextInt();
//    		while(t-->0)
//    		{
//
    	int n=sc.nextInt();
    	int arr[]=new int[n];
    	 int count=0;
    	 long sum=0;
    	 ArrayList<Integer> a=new ArrayList<>();
    	for(int i=0;i<n;i++)
    	{
    		arr[i]=sc.nextInt();
    		if(arr[i]%2==0 && arr[i]>=0)
    		sum+=arr[i];
    		if(arr[i]%2!=0)
    		{
    			if(arr[i]>0)
    			count++;
    			a.add(arr[i]);
    		}
    	}
    	Collections.sort(a);

    	if(count==0 || count==1)
    	{
    		sum+=a.get(a.size()-1);
    		System.out.println(sum);
    		return;
    	}
    	if(count%2==1)
    	{
    		int pos=a.size()-1;
    		while(count!=0)
    		{
    			sum+=a.get(pos);
    			pos--;
    			count--;
    		}

    	}
    	else if(count%2==0)
    	{
    		int pos=a.size()-1;
    		while(count!=1)
    		{
    			sum+=a.get(pos);
    			pos--;
    			count--;
    		}
    		if(pos>=1)
    		{
    			if(arr[pos]+arr[pos-1]>=0)
    			{
    				sum+=arr[pos]+arr[pos-1];
    			}

    		}
    	}
    	System.out.println(sum);

    }

    static Throwable uncaught;

    BufferedReader in;
    FastScanner sc;
    PrintWriter out;

    @Override
    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            sc = new FastScanner(in);
            solve();
        } catch (Throwable uncaught) {
            Solution.uncaught = uncaught;
        } finally {
            out.close();
        }
    }

    public static void main(String[] args) throws Throwable {
        Thread thread = new Thread(null, new Solution(), "", (1 << 26));
        thread.start();
        thread.join();
        if (Solution.uncaught != null) {
            throw Solution.uncaught;
        }
    }

}

class FastScanner {

    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }

}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int * tomb= new int[n];
    for (int i=0;i<n;++i){
        cin>>tomb[i];
        }
    sort(tomb,tomb+n);
    if(n % 2==1){
        cout<<tomb[n/2];}
    if(n % 2==0){
        cout<<tomb[(n/2)-1];}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int * tomb= new int[n];
    for (int i=0;i<n;++i){
        cin>>tomb[i];
        }
    sort(tomb,tomb+n);
    if(n % 2==0){
        cout<<tomb[n/2];}
    if(n % 2==1){
        cout<<tomb[(n/2)+1];}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int * tomb= new int[n];
    for (int i=0;i<n;++i){
        cin>>tomb[i];
        }
    sort(tomb,tomb+n);
    if(n % 2==1){
        cout<<tomb[n/2];}
    if(n % 2==0){
        cout<<tomb[(n/2)+1];}
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int * tomb= new int[n];
    for (int i=0;i<n;++i){
        cin>>tomb[i];
        }
    sort(tomb,tomb+n);
    cout<<tomb[n/2];
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,a;
    cin>>n;
    int * tomb= new int[n];
    for (int i=0;i<n;++i){
        cin>>tomb[i];
        }
    sort(tomb,tomb+n);
    if(n % 2==0){
        cout<<tomb[n/2];}
    if(n % 2==0){
        cout<<tomb[(n/2)+1];}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct MaxHeap {
	vector<int> arr;
	int N;
	int sz;
	MaxHeap(int n) {
		arr = vector<int>(n+1);
		N=n;
		sz = 0;
	}

	MaxHeap(vector<int> v) {
		N = v.size()+1;
		arr.resize(N+1);
		for(int i=1;i<N;i++) {
			arr[i]=v[i-1];
		}
		build_max_heap();
	}

	void max_heapify(int i) {
		int l = 2*i;
		int r = 2*i+1;
		int largest = i;
		if(l<=N && arr[i]<arr[l]) {
			largest = l;
		}
		if(r<=N && arr[largest]<arr[r]) {
			largest = r;
		}
		if(i!=largest) {
			swap(arr[i], arr[largest]);
			max_heapify(largest);
		}
	}

	void build_max_heap() {
		for(int i = N/2; i>=1;i--) {
			max_heapify(i);
		}
	}

	int get_top() {
		return arr[1];
	}

	void delete_top() {
		swap(arr[1], arr[sz]);
		sz--;
		max_heapify(1);
	}

	void insert(int x) {
		sz++;
		arr[sz]=x;
		int i = sz;
		while(i>1 && arr[i/2] < arr[i]) {
			swap(arr[i/2], arr[i]);
			i/=2;
		}
	}
};

int main()  {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}
	int trm = n/2;
	MaxHeap heap = MaxHeap(v);
	while(trm>0) {
		trm--;
		heap.delete_top();
	}
	cout<<heap.get_top();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct MaxHeap {
	vector<int> arr;
	int N;
	int sz;
	MaxHeap(int n) {
		arr = vector<int>(n+1);
		N=n;
		sz = 0;
	}

	MaxHeap(vector<int> v) {
		N = v.size()+1;
		arr.resize(N+1);
		for(int i=1;i<N;i++) {
			arr[i]=v[i-1];
		}
		sz =v.size();
		build_max_heap();
	}

	void max_heapify(int i) {
		int l = 2*i;
		int r = 2*i+1;
		int largest = i;
		if(l<=N && arr[i]<arr[l]) {
			largest = l;
		}
		if(r<=N && arr[largest]<arr[r]) {
			largest = r;
		}
		if(i!=largest) {
			swap(arr[i], arr[largest]);
			max_heapify(largest);
		}
	}

	void build_max_heap() {
		for(int i = N/2; i>=1;i--) {
			max_heapify(i);
		}
	}

	int get_top() {
		return arr[1];
	}

	void delete_top() {
		swap(arr[1], arr[sz]);
		sz--;
		max_heapify(1);
	}

	void insert(int x) {
		sz++;
		arr[sz]=x;
		int i = sz;
		while(i>1 && arr[i/2] < arr[i]) {
			swap(arr[i/2], arr[i]);
			i/=2;
		}
	}
};

int main()  {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}
	int trm = n/2;
	MaxHeap heap = MaxHeap(v);
	while(trm>0) {
		trm--;
		heap.delete_top();
	}
	cout<<heap.get_top();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct MaxHeap {
	vector<int> arr;
	int N;
	int sz;
	MaxHeap(int n) {
		arr = vector<int>(n+1);
		N=n;
		sz = 0;
	}

	MaxHeap(vector<int> v) {
		N = v.size();
		arr.resize(N+1);
		for(int i=1;i<N;i++) {
			arr[i]=v[i-1];
		}
		sz =v.size();
		build_max_heap();
	}

	void max_heapify(int i) {
		int l = 2*i;
		int r = 2*i+1;
		int largest = i;
		if(l<=N && arr[i]<arr[l]) {
			largest = l;
		}
		if(r<=N && arr[largest]<arr[r]) {
			largest = r;
		}
		if(i!=largest) {
			swap(arr[i], arr[largest]);
			max_heapify(largest);
		}
	}

	void build_max_heap() {
		for(int i = N/2; i>=1;i--) {
			max_heapify(i);
		}
	}

	int get_top() {
		return arr[1];
	}

	void delete_top() {
		swap(arr[1], arr[sz]);
		sz--;
		max_heapify(1);
	}

	void insert(int x) {
		sz++;
		arr[sz]=x;
		int i = sz;
		while(i>1 && arr[i/2] < arr[i]) {
			swap(arr[i/2], arr[i]);
			i/=2;
		}
	}
};

int main()  {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}
	int trm = n/2;
	MaxHeap heap = MaxHeap(v);
	while(trm>0) {
		trm--;
		// cout<<heap.get_top()<<"\n";
		heap.delete_top();
	}
	cout<<heap.get_top();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back

#define int int64_t

const int MOD = 1e9+7;

int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    	cin>>arr[i];
    sort(arr,arr+n);
    if(n%2)
        cout<<arr[n/2];
    else
        cout<<arr[n/2-1];

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct MaxHeap {
	vector<int> arr;
	int N;
	int sz;
	MaxHeap(int n) {
		arr = vector<int>(n+1);
		N=n;
		sz = 0;
	}

	MaxHeap(vector<int> v) {
		N = v.size();
		arr.resize(N+1);
		for(int i=1;i<=N;i++) {
			arr[i]=v[i-1];
		}
		sz =v.size();
		build_max_heap();
	}

	void max_heapify(int i) {
		int l = 2*i;
		int r = 2*i+1;
		int largest = i;
		if(l<=sz && arr[i]<arr[l]) {
			largest = l;
		}
		if(r<=sz && arr[largest]<arr[r]) {
			largest = r;
		}
		if(i!=largest) {
			swap(arr[i], arr[largest]);
			max_heapify(largest);
		}
	}

	void build_max_heap() {
		for(int i = sz/2; i>=1;i--) {
			max_heapify(i);
		}
	}

	int get_top() {
		return arr[1];
	}

	void delete_top() {
		swap(arr[1], arr[sz]);
		sz--;
		max_heapify(1);
	}

	void insert(int x) {
		sz++;
		arr[sz]=x;
		int i = sz;
		while(i>1 && arr[i/2] < arr[i]) {
			swap(arr[i/2], arr[i]);
			i/=2;
		}
	}
};

int main()  {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}
	int trm = (n-1)/2;
	MaxHeap heap = MaxHeap(v);
	while(trm>0) {
		trm--;
		// cout<<heap.get_top()<<"\n";
		heap.delete_top();
	}
	cout<<heap.get_top();

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct MaxHeap {
	vector<int> arr;
	int N;
	int sz;
	MaxHeap(int n) {
		arr = vector<int>(n+1);
		N=n;
		sz = 0;
	}

	MaxHeap(vector<int> v) {
		N = v.size();
		arr.resize(N+1);
		for(int i=1;i<=N;i++) {
			arr[i]=v[i-1];
		}
		sz =v.size();
		build_max_heap();
	}

	void max_heapify(int i) {
		int l = 2*i;
		int r = 2*i+1;
		int largest = i;
		if(l<=sz && arr[i]<arr[l]) {
			largest = l;
		}
		if(r<=sz && arr[largest]<arr[r]) {
			largest = r;
		}
		if(i!=largest) {
			swap(arr[i], arr[largest]);
			max_heapify(largest);
		}
	}

	void build_max_heap() {
		for(int i = sz/2; i>=1;i--) {
			max_heapify(i);
		}
	}

	int get_top() {
		return arr[1];
	}

	void delete_top() {
		swap(arr[1], arr[sz]);
		sz--;
		max_heapify(1);
	}

	void insert(int x) {
		sz++;
		arr[sz]=x;
		int i = sz;
		while(i>1 && arr[i/2] < arr[i]) {
			swap(arr[i/2], arr[i]);
			i/=2;
		}
	}
};

int main()  {
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++) {
		cin>>v[i];
	}
	int trm = (n)/2;
	MaxHeap heap = MaxHeap(v);
	while(trm>0) {
		trm--;
		// cout<<heap.get_top()<<"\n";
		heap.delete_top();
	}
	cout<<heap.get_top();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(n%2==0)
        cout<<a[(n+1)/2];
    else
        cout<<a[(n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(n%2==0)
        cout<<a[(n+1)/2];
    else
        cout<<a[n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(n%2==0)
        cout<<a[(n/2)-1];
    else
        cout<<a[n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[(n+1)/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    string a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    char a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<a[n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(n%2==0)
        cout<<a[(n+1)/2];
    else
        cout<<a[n/2];
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,x;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a,a+n+1);
    if(n%2==0)
        cout<<a[(n+1)/2];
    else
        cout<<a[n/2];
}


input()
nums = list(map(int, input().split()))

nums.sort()
n = len(nums)
if n%2==1:
	m = n//2
else:
	m = (n//2)-1

print(nums[m])


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,m,t;
	vector<int> v;
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(), v.end());
	int l = v.size();
	if (l%2==1)
		m = l/2;
	else
		m = (l/2)-1;

	cout << v[m] << endl;

	for (int x: v){
		cout << x << " ";
	}
}


#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,m,t;
	vector<int> v;
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(), v.end());
	int l = v.size();
	if (l%2==1)
		m = l/2;
	else
		m = (l/2)-1;

	cout << v[m] << endl;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n,m,t;
	vector<int> v;
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(), v.end());
	int l = v.size();
	if (l%2==1)
		m = l/2;
	else
		m = (l/2)-1;

	cout << v[m] << endl;

	for (int x: v){
		cout << x << " ";
	}
}


#include <iostream>
#include <vector
#include <algorithm>
using namespace std;

int main()
{
	int n,m,t;
	vector<int> v;
	cin >> n;
	for (int i=0; i<n; i++){
		cin >> t;
		v.push_back(t);
	}
	sort(v.begin(), v.end());
	int l = v.size();
	if (l%2==1)
		m = l/2;
	else
		m = (l/2)-1;

	cout << v[m] << endl;

	for (int x: v){
		cout << x << " ";
	}
}


//Game
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{

  int n,a[100],i,j;

  cin >> n;

  for(int i = 0; i < n; i++)
      cin >> a[i];

  sort(a,a+n);

  for(i = 0,j = n-1;i < n, j > 0;i++,j--)
  {
    if(j == i)
    {
        cout << a[i];
        break;
    }

    else if(j < i)
    {
      cout << a[j];
      break;
    }
  }

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{

  int n,a[100],i,j;

  cin >> n;

  for(int i = 0; i < n; i++)
      cin >> a[i];

  sort(a,a+n);

  for(i = 0,j = n-1; i < n, j >= 0; i++,j--)
  {
    if(j == i)
    {
      cout << a[i];
      break;
    }
  }

}


//Game
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{

  int n,i,j;

  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++)
      cin >> a[i];

  sort(a,a+n);
    if(n%2 == 1)
        cout << a[(n-1)/2];
    else
      cout << a[n/2-1];

}


//Game
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{

  int n,a[100],i,j;

  cin >> n;

  for(int i = 0; i < n; i++)
      cin >> a[i];

  sort(a,a+n);

  int m = floor(n/2)-1;

  if(n%2 == 0)
      cout << a[m];

  else
        cout << floor(a[n/2]);

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{

  int n,a[100],i,j;

  cin >> n;

  for(int i = 0; i < n; i++)
      cin >> a[i];

  sort(a,a+n);

  for(i = 0,j = n-1; i < n, j >= 0; i++,j--)
  {
    if(j == i)
    {
      cout << a[i];
      break;
    }
  }
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n; int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];

    sort(a,a+n);

    cout<<a[(int)ceil(n/2.0)-1];

return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n; int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];

    sort(a,a+n);

    cout<<a[ceil(n/2)];

return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n; int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];

    sort(a,a+n);

    cout<<a[ceil(n/2)];

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n; int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];

    sort(a,a+n);

    cout<<a[(int)ceil(n/2.0)];

return 0;

}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin>>n; int a[n];
    for(int i=0; i<n; i++)
    cin>>a[i];

    sort(a,a+n);

    cout<<a[ceil(n/2.0)];

return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<a[0];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   sort(a,a+n);
   t=n/2;
   cout<<a[t-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   sort(a,a+n);
    t=n/2;
   if(n==1)cout<<a[0];
   else if(n==2)cout<<a[0];
   else if(n==3)cout<<a[1];
   else if(n%2==0) cout<<a[t-1];
   else if(n%2==1)cout<<a[t];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   sort(a,a+n);
    t=n/2;
   if(n==1)cout<<a[0];
   else if(n==2)cout<<a[1];
   else if(n==3)cout<<a[1];
   else if(n%2==0) cout<<a[t-1];
   else if(n%2==1)cout<<a[t];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   sort(a,a+n);

   if(n==1)cout<<a[0];
   else if(n==2)cout<<a[1];
   else if(n==3)cout<<a[1];
   else if(n%2==0) cout<<a[t-1];
   else if(n%2==1)cout<<a[t];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,t;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
   sort(a,a+n);
   t=n/2;
   if(n==1)cout<<a[0];
   else if(n==2)cout<<a[1];
   else if(n==3)cout<<a[1];
   else
   cout<<a[t-1];
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n%2==0)
   {
       cout<<min(a[0],a[1]);
   }
   else
    {
       cout<<max(a[0],a[1]);
   }
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define ll long long
#define int long long

using namespace std;

int32_t main()
{

    int n,s=0;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++) {cin>>a[i];}
    sort(a,a+n);
    if(n%2==0) n=n/2;
    else n=n/2;
    cout<<a[n]<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define mod 998244353
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }
int min(int a, int b) { return (a < b)? a : b ;}

/************************************************************/
int solve()
{
     return 0;
}

signed main()
{
    int t=1,ca=0;
    // cin>>t;
    // ca=t;
    int a,b,d,sum,c;
    d=t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(all(a));
        if(!(n&1))
            n=n-1;
        cout<<a[n/2]<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define ll long long
#define int long long

using namespace std;

int32_t main()
{

    int n,s=0;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++) {cin>>a[i];s+=a[i];}
    s=s/n;
    sort(a,a+n);
    for(int i=0;i<n;i++)
    if(a[i]>=s) {cout<<a[i];break;}
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define ll long long
#define int long long

using namespace std;

int32_t main()
{

    int n,s=0;
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++) {cin>>a[i];}
    sort(a,a+n);
    if(n%2==0) n=n/2-1;
    else n=n/2;
    cout<<a[n]<<endl;
    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define mod 998244353
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }
int min(int a, int b) { return (a < b)? a : b ;}

/************************************************************/
int solve()
{
     return 0;
}

signed main()
{
    int t=1,ca=0;
    // cin>>t;
    // ca=t;
    int a,b,d,sum,c;
    d=t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(all(a));
        cout<<a[n/2]<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define pll pair<long , long>
#define all(a) a.begin(), a.end()
#define int long long
#define ll long long
#define mod 998244353
#define endl "\n"
#define loop(i,a,b) for(int i=a;i<b;i++)
#define bloop(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

int max(int a, int b) { return (a > b)? a : b; }
int min(int a, int b) { return (a < b)? a : b ;}

/************************************************************/
int solve()
{
     return 0;
}

signed main()
{
    int t=1,ca=0;
    // cin>>t;
    // ca=t;
    int a,b,d,sum,c;
    d=t;
    while(t--)
    {
        int n;
        cin>>n;
        vector<int> a(n+1);
        for(int i=1;i<=n;i++)
            cin>>a[i];
        sort(all(a));
        // for(auto x:a)
        //     cout<<x<<" ";
        cout<<a[n/2]<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	for(int i = 0; i < n; i++) {
		cout << x[i] << ' ';
	}
	if (n % 2 == 0) {
		cout <<  x[(n/2)];
	}
	else {
		cout <<  x[(n/2)+1];
	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	cout <<  x[n/2];

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	if(n % 2 == 0) {
		cout << x[(n/2)-1];
	}
	else {
		cout << x[(n/2)];
	}
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	cout <<  x[(n/2)];
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	if (n % 2 == 0) {
		cout <<  x[(n/2)+1];
	}
	else {
		cout <<  x[(n/2)];
	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int x[n];
	for(int i = 0; i < n; i++) {
		cin >> x[i];
	}
	sort(x, x+n);
	if(n % 2 == 0) {
		cout << x[(n/2)];
	}
	else {
		cout << x[(n/2)];
	}
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> v;
int main()
{
    int n;
    int n1;
    cin>>n;
    v.assign(n, 0);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(), v.end());
    if(n%2==0){
        printf("%d\n",v[n/2-1]);
    }
    else{
        printf("%d\n",v[n/2]);
    }

    return 0;
}


#include <iostream>
#include <bits/stdc++.h>
#define LL long long
#define Clear(a,x) memset(a,x,sizeof(a))
using namespace std;
vector<int> V;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, x;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x;
        V.push_back(x);
    }
    int flag = 1;
    while(V.size() > 1){
        int len = V.size() - 1;
        if(flag){
            if(V[len] >= V[len - 1]){
                V.pop_back();
            }
            else{
                int MAX = V.back();
                for(int i = 0; i < len; i++){
                    if(MAX < V[i]){
                        MAX = i;
                    }
                }
                V.erase(V.begin() + MAX);
            }
        }
        else{
            if(V[len] <= V[len - 1]){
                V.pop_back();
            }
            else{
                int MIN = V.back();
                for(int i = 0; i < len; i++){
                    if(MIN < V[i]){
                        MIN = i;
                    }
                }
                V.erase(V.begin() + MIN);
            }
        }
        flag ^= 1;
    }
    cout << V[0] << endl;
    return 0;
}