#include <iostream>
#include <string>
using namespace std;
string s;
const int N=2e5+1;
int tab[N],n,x,k,l;
int main()
{ scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
   scanf("%d",&x);
    tab[x]=i;
  }
  for(int i=0;i<n;i++)
  {
    scanf("%d",&x);
    l=0;
    if(tab[x]>k)l=tab[x]-k,k=tab[x];
    s+=to_string(l)+" ";
  }
cout<<s;
}


#include <iostream>
#include <string>
using namespace std;
string s;
const int N=2e5;
int tab[N],n,x,k,l;
int main()
{ scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
   scanf("%d",&x);
    tab[x]=i;
  }
  for(int i=0;i<n;i++)
  {
    scanf("%d",&x);
    l=0;
    if(tab[x]>k)l=tab[x]-k,k=tab[x];
    s+=to_string(l)+" ";
  }
cout<<s;
}


#include <iostream>
#include<string>
using namespace std;
const int N=2e5;
int tab[N],n,x,k;string s;
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>x;
    tab[x]=i;
  }
  for(int i=0;i<n;i++)
  {
    cin>>x;
    int l=0;
    if(tab[x]>k)l=tab[x]-k,k=tab[x];
    cout<<l<<" ";
  }

}


#include<stdio.h>
using namespace std;
const int N=2e5;
int tab[N],n,x,k,l;
int main()
{ scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
   scanf("%d",&x);
    tab[x]=i;
  }
  for(int i=0;i<n;i++)
  {
    scanf("%d",&x);
    l=0;
    if(tab[x]>k)l=tab[x]-k,k=tab[x];
   printf("%d ",l);
  }

}


#include <iostream>
#include<string>
using namespace std;
const int N=2e5;
int tab[N],n,x,k;string s;
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>x;
    tab[x]=i;
  }
  for(int i=0;i<n;i++)
  {
    cin>>x;
    int l=0;
    if(tab[x]>k)l=tab[x]-k,k=tab[x];
    s+=to_string(l);
  }
 cout<<s;

}


#include <iostream>
#include <unordered_map>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unordered_map<int, int> a;
    int x, n;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> x;
        a[x] = i;
    }
    int k=-1;
    while (n--) {
        cin >> x;
        x = a[x];
        if (x>k) {
            cout << x-k << ' ';
            k = x;
        }
        else cout << 0 << ' ';
    }
    cout<<'\n';
    return 0;
}


#include <stdio.h>
int find(int x, int a[], int n) {
	for (int i=0; i<n; i++) if (x==a[i]) return i;
	return -1;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int j=-1;
	int k;
	for (int i=0; i<n; i++) {
		k=find(b[i], a, n);
		if (k<0) {
			printf("%d ", 0);
			continue;
		}
		printf("%d ", k-j);
		j=k;
	}
	return 0;
}


#include <stdio.h>
int find(int x, int a[], int n) {
	for (int i=0; i<n; i++) if (x==a[i]) return i;
	return -1;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int j=-1;
	int k;
	for (int i=0; i<n; i++) {
		k=find(b[i], a, n);
		if (k<j) {
			printf("%d ", 0);
			continue;
		}
		printf("%d ", k-j);
		j=k;
	}
	return 0;
}


#include <stdio.h>
int find(int x, int a[], int n, int o) {
	for (int i=o+1; i<n; i++) {
		if (x==a[i]) {
			return i;
			break;
		}
	}
	return -1;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int j=-1;
	int k;
	for (int i=0; i<n; i++) {
		k=find(b[i], a, n, j);
		if (k<0) {
			printf("%d ", 0);
			continue;
		}
		printf("%d ", k-j);
		j=k;
	}
	return 0;
}


#include <stdio.h>
int find(int x, int a[], int n, int o) {
	int nn=o+(n-o+1)/2;
	int j=n-1;
	for (int i=o+1; i<nn+1; i++, j--) {
		if (x==a[i]) return i;
		else if (x==a[j]) return j;
	}
	return -1;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int j=-1;
	int k;
	for (int i=0; i<n; i++) {
		k=find(b[i], a, n, j);
		if (k<0) {
			printf("%d ", 0);
			continue;
		}
		printf("%d ", k-j);
		j=k;
	}
	return 0;
}


#include <stdio.h>
int find(int x, int a[], int n , int o) {
	for (int i=o+1; i<n; i++) if (x==a[i]) return i;
	return -1;
}
int main() {
	int n;
	scanf("%d", &n);
	int a[n], b[n];
	for (int i=0; i<n; i++) scanf("%d", &a[i]);
	for (int i=0; i<n; i++) scanf("%d", &b[i]);
	int j=-1;
	int k;
	for (int i=0; i<n; i++) {
		k=find(b[i], a, n, j);
		if (k<0) {
			printf("%d ", 0);
			continue;
		}
		printf("%d ", k-j);
		j=k;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    std::ios::sync_with_stdio(false);
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
        cout<<"0 ";
       else
       {
           int c=1;
           while(d1.front()!=x)
           {
               int z=d1.front();
               ++c;
               cnt[z]=0;
               d1.pop_front();
           }
            d1.pop_front();
           cout<<c<<" ";
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
        cout<<"0 ";
       else
       {
           int c=0;
           int f=1;

           while(f)
           {
               ++c;
               int z=d1.front();
               cnt[z]=0;
               d1.pop_front();
               if(z == x)
               {
                   cout<<c<<" ";f=0;
               }
           }
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n;
   cin>>n;
   ll cnt[n+1];
   for(int i=0; i<n; i++)
   {
       ll x;
       cin>>x;
       cnt[x]=i+1;
   }
   ll p;
   cin>>p;
   ll r;
   ll z=cnt[p];
   cout<<z<<" ";
   for(int i=1; i<n; i++)
   {
       ll x;
       cin>>x;
       r=cnt[x];
       if(r <= z)
       {
           cout<<"0 ";
       }
       else
       {
          ll k=r-z;
          cout<<k<<" ";
          z=r;
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=1; i<=3; i++)
    cout<<cnt[i]<< " ";
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
         cout<<"0"<<" ";
       else
       {
           int c=0;
           int f=1;

           while(f)
           {
               ++c;
               int z=d1.front();
               cnt[z]=0;
               d1.pop_front();
               if(z == x)
               {
                   cout<<c<<" ";f=0;
               }
           }
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
        cout<<"0 ";
       else
       {
           int c=0;
           int f=1;

           while(f)
           {
               ++c;
               int z=d1.front();
               cnt[z]=0;
               d1.pop_front();
               if(z == x)
               {
                   cout<<c<<" ";f=0;
               }
               if(d1.empty() == 1)
               {
                   for(int j=i; j<n-1; j++)
                    cout<<"0 ";
                   return 0;
               }
           }
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     std::ios::sync_with_stdio(false);
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
        cout<<"0 ";
       else
       {
           int c=0;
           int f=1;

           while(f)
           {
               ++c;
               int z=d1.front();
               cnt[z]=0;
               d1.pop_front();
               if(z == x)
               {
                   cout<<c<<" ";f=0;
               }
           }
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       cnt[x]=i+1;
   }
   int p;
   cin>>p;
   int r;
   int z=cnt[p];
   cout<<z<<" ";
   for(int i=1; i<n; i++)
   {
       int x;
       cin>>x;
       r=cnt[x];
       if(r <= z)
       {
           cout<<"0 ";
       }
       else
       {
          int k=r-z;
          cout<<k<<" ";
          z=r;
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   ll n;
   std::ios::sync_with_stdio(false);
   cin>>n;
   ll cnt[n+1];
   for(int i=0; i<n; i++)
   {
       ll x;
       cin>>x;
       cnt[x]=i+1;
   }
   ll p;
   cin>>p;
   ll r;
   ll z=cnt[p];
   cout<<z<<" ";
   for(int i=1; i<n; i++)
   {
       ll x;
       cin>>x;
       r=cnt[x];
       if(r < z)
       {
           cout<<"0 ";
       }
       else
       {
          ll k=r-z;
          cout<<k<<" ";
          z=r;
       }
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   deque<int> d1;
   int cnt[n+1];
   for(int i=1; i<=n; i++)
    cnt[i]=1;
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       d1.push_back(x);
   }
   for(int i=0; i<n; i++)
   {
       int x;
       cin>>x;
       if(cnt[x] == 0)
        cout<<"0 ";
       else
       {
           int c=1;
           while(d1.front()!=x)
           {
               int z=d1.front();
               ++c;
               cnt[z]=0;
               d1.pop_front();
           }
            d1.pop_front();
           cout<<c<<" ";
       }
   }
   return 0;
}


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

#define lli long long int
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define mod 1000000007
#define inf 1e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define bakchodi                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

//prime sieve
vector<bool> primes(100006, false);
void sieve()
{
    for (ll i = 3; i <= 100006; i += 2)
    {
        primes[i] = 1;
    }
    //Sieve
    for (ll i = 3; i <= 100006; i+=2)
    {
        if (primes[i] == 1)
        {
            for (ll j = i * i; j <= 100006; j += i)
            {
                primes[j] = 0;
            }
        }
    }
    primes[2] = 1;
    primes[0] = primes[1] = 0;

}

int recpow(int x, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x), n / 2);
    else //n is odd
        return (x * recpow((x * x), (n - 1) / 2));
}

int main()
{
    bakchodi;
    int n;
    cin>>n;
    unordered_map <int,int> arr;
    int brr[n];

    for(int i=0;i<n;i++)
     {
         int temp;
         cin>>temp;
         arr.insert(make_pair(temp,i));
     }

  int  prev=0,curr=0;

     for(int i=0;i<n;i++)
     {
            int elem;
            cin>>elem;

            int pos=arr[elem];

        if (pos>=prev)
        {
            curr=pos;
            cout<<curr-prev+1<<" ";
            prev=curr+1;
        }
        else
        cout<<0<<" ";

     }

}


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

#define lli long long int
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define mod 1000000007
#define inf 1e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define bakchodi                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

//prime sieve
vector<bool> primes(100006, false);
void sieve()
{
    for (ll i = 3; i <= 100006; i += 2)
    {
        primes[i] = 1;
    }
    //Sieve
    for (ll i = 3; i <= 100006; i+=2)
    {
        if (primes[i] == 1)
        {
            for (ll j = i * i; j <= 100006; j += i)
            {
                primes[j] = 0;
            }
        }
    }
    primes[2] = 1;
    primes[0] = primes[1] = 0;

}

int recpow(int x, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x), n / 2);
    else //n is odd
        return (x * recpow((x * x), (n - 1) / 2));
}

int main()
{
    bakchodi;
    int n;
    cin>>n;
    unordered_map <int,int> arr;

    for(int i=0;i<n;i++)
     {
         int temp;
         cin>>temp;
         arr.insert(make_pair(temp,i));
     }

  int  prev=0,curr=0;

     for(int i=0;i<n;i++)
     {
            int elem;
            cin>>elem;

            int pos=arr[elem];

        if (pos>=prev)
        {
            curr=pos;
            cout<<curr-prev+1<<" ";
            prev=curr+1;
        }
        else
        cout<<0<<" ";

     }

}


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

#define lli long long int
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define mod 1000000007
#define inf 1e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define bakchodi                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

//prime sieve
vector<bool> primes(100006, false);
void sieve()
{
    for (ll i = 3; i <= 100006; i += 2)
    {
        primes[i] = 1;
    }
    //Sieve
    for (ll i = 3; i <= 100006; i+=2)
    {
        if (primes[i] == 1)
        {
            for (ll j = i * i; j <= 100006; j += i)
            {
                primes[j] = 0;
            }
        }
    }
    primes[2] = 1;
    primes[0] = primes[1] = 0;

}

int recpow(int x, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x), n / 2);
    else //n is odd
        return (x * recpow((x * x), (n - 1) / 2));
}

int main()
{
    bakchodi;
    int n;
    cin>>n;
    vector <int> arr;
    int brr[n];

    for(int i=0;i<n;i++)
     {
         int temp;
         cin>>temp;
         arr.push_back(temp);
     }

    for(int i=0;i<n;i++)
     cin>>brr[i];
  lli prev=0,curr=0;
     for(int i=0;i<n;i++)
     {
            int elem=brr[i];
         auto it = find(arr.begin()+prev-1, arr.end(), elem);
        // cout<<it-arr.begin()<<endl;
        if (it!= arr.end() and it-arr.begin()>=prev)
        {
            curr=it-arr.begin();
            cout<<curr-prev+1<<" ";
            prev=curr+1;
        }
        else
        cout<<0<<" ";

     }

}


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

#define lli long long int
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define mod 1000000007
#define inf 1e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define bakchodi                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

//prime sieve
vector<bool> primes(100006, false);
void sieve()
{
    for (ll i = 3; i <= 100006; i += 2)
    {
        primes[i] = 1;
    }
    //Sieve
    for (ll i = 3; i <= 100006; i+=2)
    {
        if (primes[i] == 1)
        {
            for (ll j = i * i; j <= 100006; j += i)
            {
                primes[j] = 0;
            }
        }
    }
    primes[2] = 1;
    primes[0] = primes[1] = 0;

}

int recpow(int x, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x), n / 2);
    else //n is odd
        return (x * recpow((x * x), (n - 1) / 2));
}

int main()
{
    bakchodi;
    int n;
    cin>>n;
    vector <int> arr;
    int brr[n];

    for(int i=0;i<n;i++)
     {
         int temp;
         cin>>temp;
         arr.push_back(temp);
     }

    for(int i=0;i<n;i++)
     cin>>brr[i];
  lli prev=0,curr=0;
     for(int i=0;i<n;i++)
     {
            int elem=brr[i];
         auto it = find(arr.begin(), arr.end(), elem);
        // cout<<it-arr.begin()<<endl;
        if (it!= arr.end() and it-arr.begin()>=prev)
        {
            curr=it-arr.begin();
            cout<<curr-prev+1<<" ";
            prev=curr+1;
        }
        else
        cout<<0<<" ";

     }

}


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

#define lli long long int
#define ll long long
#define rep(i, a, b) for (int i = a; i < b; i++)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define mod 1000000007
#define inf 1e18
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
#define bakchodi                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

//prime sieve
vector<bool> primes(100006, false);
void sieve()
{
    for (ll i = 3; i <= 100006; i += 2)
    {
        primes[i] = 1;
    }
    //Sieve
    for (ll i = 3; i <= 100006; i+=2)
    {
        if (primes[i] == 1)
        {
            for (ll j = i * i; j <= 100006; j += i)
            {
                primes[j] = 0;
            }
        }
    }
    primes[2] = 1;
    primes[0] = primes[1] = 0;

}

int recpow(int x, int n)
{
    if (n == 0)
        return 1;
    else if (n % 2 == 0) //n is even
        return recpow((x * x), n / 2);
    else //n is odd
        return (x * recpow((x * x), (n - 1) / 2));
}

int main()
{
    bakchodi;
    int n;
    cin>>n;
    unordered_map <int,int> arr;
    int brr[n];

    for(int i=0;i<n;i++)
     {
         int temp;
         cin>>temp;
         arr.insert(make_pair(temp,i));
     }

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

  int  prev=0,curr=0;

     for(int i=0;i<n;i++)
     {
            int elem=brr[i];

            int pos=arr[brr[i]];

        if (pos>=prev)
        {
            curr=pos;
            cout<<curr-prev+1<<" ";
            prev=curr+1;
        }
        else
        cout<<0<<" ";

     }

}


#include<bits/stdc++.h>
using namespace std;
int a[200010],x,n, p=0,j;
int main()
{

    scanf("%d",&n);

    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        a[x]=i;
    }

    while(n--)
    {
        scanf("%d",&x);
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        printf("%d ",j);

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[200001],b[n],x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    int p=0,j;
    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


#include<bits/stdc++.h>
using namespace std;
int a[200001],b[n],x,n;
int main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    int p=0,j;
    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


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

    }
    vector<int>v;
    for(int i=1;i<=n;i++)
    {
        int p=0;
        int cnt=0;
        for(int j=1;j<=n;j++)
        {

            if(b[i]==a[j])
            {
             p=j;
             break;

            }

        }
      //  cout<<"p: "<<p<<'\n';
        for(int i=1;i<=p;i++)
        {
            if(a[i]!=0)
            {
                a[i]=0;
                cnt++;
            }
        }
        cout<<cnt<<" ";

       // v.push_back(cnt);
    }

}


#include<bits/stdc++.h>
using namespace std;
int a[200010],x,n, p=0,j;
int main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }

    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


#include<bits/stdc++.h>
using namespace std;
int a[200010],x,n, p=0,j;
int main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }

    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        printf("%d ",j);

    }

}


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

    }
    vector<int>v;
    for(int i=1;i<=n;i++)
    {
        int p=0;
        int cnt=0;
        for(int j=1;j<=n;j++)
        {

            if(b[i]==a[j])
            {
             p=j;
             break;

            }

        }
      //  cout<<"p: "<<p<<'\n';
        for(int i=1;i<=p;i++)
        {
            if(a[i]!=0)
            {
                a[i]=0;
                cnt++;
            }
        }
      //  cout<<"cnt: "<<cnt<<'\n';

        v.push_back(cnt);
    }
    for(int i=0;i<v.size();i++)
    {
        cout<<v[i]<<" ";
    }
}


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

        cin>>b[i];
    }
    for(int i=0;i<t;i++)
    {
        int cnt=0;

        for(int j=0;j<v.size();j++)
        {
            //cout<<"v[j]: "<<v[j]<<" b[i]:"<<b[i]<<'\n';
            if(v[j]==b[i])
            {
                cnt++;
                c.push_back(j+1);
                v.erase(v.begin(),v.begin()+j+1);
            }

        }
        if(cnt==0)
        {
            c.push_back(0);
        }

    }
     for(int i=0;i<c.size();i++)
        {
            if(i==c.size()-1)
            {
                cout<<c[i]<<'\n';
            }
            else
            cout<<c[i]<<' ';
        }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n],x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    int p=0,j;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n],x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    int p=0,j;
    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


#include<bits/stdc++.h>
using namespace std;
int a[200001],x,n;
int main()
{

    cin>>n;

    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    int p=0,j;
    while(n--)
    {
        cin>>x;
        j=0;
        if(a[x]>p)j=a[x]-p,p=a[x];
        cout<<j<<" ";

    }

}


#include <bits/stdc++.h>
//PROBLEM :https://codeforces.com/contest/1073/problem/B

//Fixed TLE. Had to look at the code.

//Also, replacing the below C++ functions for I/O with C equivalents caused the solution to execute 5 times faster.
//Migrating over to C.

//

//Removing const will make the 8th test case fail. I need to figure out why.
const int N = int(2e5) + 1;
int main() {
    int n;
    std::cin>>n;
    int stack[N];
    int vasya[N];
    bool status[N];

    for(int i = 0 ; i < n  ; i++)
        status[i] = false;

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i];

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        if(status[vasya[i]]){
            std::cout<<0<<" ";
            continue;
        }

        int m = 0;
        while(true){
            m++;
            status[stack[top_of_stack]] = true;
            if(vasya[i] == stack[top_of_stack])
                break;
            top_of_stack++;
        }
        top_of_stack++;

        std::cout<<m<<" ";
    }
    return 0;
}


#include <bits/stdc++.h>

struct stat_val{
    bool processsed = false;
    int val;
};
bool num_present(stat_val* stv, int num, int size, int from_index){
    for(int i = from_index ; i < size; i++)
        if(stv[i].val == num)
            return true;
    return false;
}
int main() {
    int n;
    std::cin>>n;
    stat_val* stack  =  new stat_val[n];
    stat_val* vasya  =  new stat_val[n];
    int* result =  new int[n];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i].val;

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i].val;

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        int m = 0;
        if(num_present(stack, vasya[i].val, n, top_of_stack)) {
            for (int j = top_of_stack; j < n; j++) {
                if (stack[j].processsed)
                    continue;
                m++;
                stack[j].processsed = true;
                vasya[i].processsed = true;
                if (stack[j].val == vasya[i].val)
                    break;
            }
        }
        top_of_stack+=m;
        result[i] = m;
    }

    for(int i = 0 ; i < n  ; i++)
        std::cout<<result[i]<<" ";

    delete [] stack;
    delete [] vasya;
    delete [] result;
    return 0;
}


#include <bits/stdc++.h>

int main() {
    int n;
    std::cin>>n;
    int* stack  =  new int[n];
    int* vasya  =  new int[n];
    bool* status = new bool[n+1];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i];

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        if(status[vasya[i]]){
            std::cout<<0<<" ";
            continue;
        }

        int m = 0;
        while(true){
            m++;
            status[stack[top_of_stack]] = true;
            if(vasya[i] == stack[top_of_stack])
                break;
            top_of_stack++;
        }
        top_of_stack++;

        std::cout<<m<<" ";
    }

    delete [] stack;
    delete [] vasya;
    return 0;
}


#include <bits/stdc++.h>

int main() {
    int n;
    std::cin>>n;
    int* stack  =  new int[n];
    int* vasya  =  new int[n];
    bool* status = new bool[n];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i];

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        if(status[vasya[i]]){
            std::cout<<0<<" ";
            continue;
        }

        int m = 0;
        while(true){
            m++;
            status[stack[top_of_stack]] = true;
            if(vasya[i] == stack[top_of_stack])
                break;
            top_of_stack++;
        }
        top_of_stack++;

        std::cout<<m<<" ";
    }

    delete [] stack;
    delete [] vasya;
    delete [] status;
    return 0;
}


//#include <bits/stdc++.h>
//int N = int(2e5) + 9;
//int main() {
//    int n;
//    std::cin>>n;
//    int stack[N];
//    int vasya[N];
//    bool status[N];
//
//    for(int i = 0 ; i < n  ; i++)
//        status[i] = false;
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>stack[i];
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>vasya[i];
//
//    int top_of_stack = 0;
//
//    for(int i = 0 ; i < n  ; i++){
//        if(status[vasya[i]]){
//            std::cout<<0<<" ";
//            continue;
//        }
//
//        int m = 0;
//        while(true){
//            m++;
//            status[stack[top_of_stack]] = true;
//            if(vasya[i] == stack[top_of_stack])
//                break;
//            top_of_stack++;
//        }
//        top_of_stack++;
//
//        std::cout<<m<<" ";
//    }
//    return 0;
//}
#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 9;

int n;
int a[N];
int b[N];
bool u[N];

int main() {
//	freopen("input.txt", "r", stdin);
    scanf("%d", &n);
    for(int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    for(int i = 0; i < n; ++i){
        scanf("%d", b + i);
    }

    int pos = 0;
    for(int i = 0; i < n; ++i){
        int x = b[i];
        if(u[x]){
            printf("0 ");
            continue;
        }

        int cnt = 0;
        while(true){
            ++cnt;
            u[a[pos]] = true;
            if(a[pos] == x) break;
            ++pos;
        }

        ++pos;
        printf("%d ", cnt);
    }

    puts("");
    return 0;
}


//#include <bits/stdc++.h>
//int N = int(2e5) + 9;
//int main() {
//    int n;
//    std::cin>>n;
//    int stack[N];
//    int vasya[N];
//    bool status[N];
//
//    for(int i = 0 ; i < n  ; i++)
//        status[i] = false;
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>stack[i];
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>vasya[i];
//
//    int top_of_stack = 0;
//
//    for(int i = 0 ; i < n  ; i++){
//        if(status[vasya[i]]){
//            std::cout<<0<<" ";
//            continue;
//        }
//
//        int m = 0;
//        while(true){
//            m++;
//            status[stack[top_of_stack]] = true;
//            if(vasya[i] == stack[top_of_stack])
//                break;
//            top_of_stack++;
//        }
//        top_of_stack++;
//
//        std::cout<<m<<" ";
//    }
//    return 0;
//}
#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 9;

int n;
int a[N];
int b[N];
bool u[N];

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

    for(int i = 0 ; i < n  ; i++)
        std::cin>>b[i];

    int pos = 0;
    for(int i = 0; i < n; ++i){
        if(u[b[i]]){
            printf("0 ");
            continue;
        }

        int cnt = 0;
        while(true){
            ++cnt;
            u[a[pos]] = true;
            if(a[pos] == b[i]) break;
            ++pos;
        }

        ++pos;
        printf("%d ", cnt);
    }

    puts("");
    return 0;
}


#include <bits/stdc++.h>
//PROBLEM :https://codeforces.com/contest/1073/problem/B

//Fixed TLE. Had to look at the code. I had a solution, just wan't fast enough.
//Also, replacing the below C++ functions for I/O with C equivalents caused the solution to execute 5 times faster. Do that.
//Migrating over to C(scanf, printf, puts, gets, getline etc.).

//Removing const will make the 8th test case fail. I need to figure out why(maybe because array on stack takes
//literal or const value as the size).
//Removing the extra 1 will do the same. I think it is because we are removing books from 1 to N and not 0 to N-1. The first index
//goes useless I think.
const int N = int(2e5) + 1;

int main() {
    int n;
    std::cin>>n;

    int* stack = new int[n];
    int* vasya = new int[n];
    bool* status = new bool[n];

    for(int i = 0 ; i < n  ; i++)
        status[i] = false;

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i];

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        if(status[vasya[i]]){
            std::cout<<0<<" ";
            continue;
        }

        int m = 0;
        while(true){
            m++;
            status[stack[top_of_stack]] = true;
            if(vasya[i] == stack[top_of_stack])
                break;
            top_of_stack++;
        }
        top_of_stack++;

        std::cout<<m<<" ";
    }
    delete [] stack;
    delete [] status;
    delete [] vasya;
    return 0;
}


#include <bits/stdc++.h>
int N = (2e5) + 9;
int main() {
    int n;
    std::cin>>n;
    int stack[N];
    int vasya[N];
    bool status[N];

    for(int i = 0 ; i < n  ; i++)
        status[i] = false;

    for(int i = 0 ; i < n  ; i++)
        std::cin>>stack[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>vasya[i];

    int top_of_stack = 0;

    for(int i = 0 ; i < n  ; i++){
        if(status[vasya[i]]){
            std::cout<<0<<" ";
            continue;
        }

        int m = 0;
        while(true){
            m++;
            status[stack[top_of_stack]] = true;
            if(vasya[i] == stack[top_of_stack])
                break;
            top_of_stack++;
        }
        top_of_stack++;

        std::cout<<m<<" ";
    }
    return 0;
}


//#include <bits/stdc++.h>
//int N = int(2e5) + 9;
//int main() {
//    int n;
//    std::cin>>n;
//    int stack[N];
//    int vasya[N];
//    bool status[N];
//
//    for(int i = 0 ; i < n  ; i++)
//        status[i] = false;
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>stack[i];
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>vasya[i];
//
//    int top_of_stack = 0;
//
//    for(int i = 0 ; i < n  ; i++){
//        if(status[vasya[i]]){
//            std::cout<<0<<" ";
//            continue;
//        }
//
//        int m = 0;
//        while(true){
//            m++;
//            status[stack[top_of_stack]] = true;
//            if(vasya[i] == stack[top_of_stack])
//                break;
//            top_of_stack++;
//        }
//        top_of_stack++;
//
//        std::cout<<m<<" ";
//    }
//    return 0;
//}
#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 9;

int main() {
    int n;
    int a[N];
    int b[N];
    bool u[N];
    std::cin>>n;
    for(int i = 0 ; i < n  ; i++)
        std::cin>>a[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>b[i];

    int pos = 0;
    for(int i = 0; i < n; ++i){
        if(u[b[i]]){
            printf("0 ");
            continue;
        }

        int cnt = 0;
        while(true){
            ++cnt;
            u[a[pos]] = true;
            if(a[pos] == b[i]) break;
            ++pos;
        }

        ++pos;
        printf("%d ", cnt);
    }

    puts("");
    return 0;
}


//#include <bits/stdc++.h>
//int N = int(2e5) + 9;
//int main() {
//    int n;
//    std::cin>>n;
//    int stack[N];
//    int vasya[N];
//    bool status[N];
//
//    for(int i = 0 ; i < n  ; i++)
//        status[i] = false;
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>stack[i];
//
//    for(int i = 0 ; i < n  ; i++)
//        std::cin>>vasya[i];
//
//    int top_of_stack = 0;
//
//    for(int i = 0 ; i < n  ; i++){
//        if(status[vasya[i]]){
//            std::cout<<0<<" ";
//            continue;
//        }
//
//        int m = 0;
//        while(true){
//            m++;
//            status[stack[top_of_stack]] = true;
//            if(vasya[i] == stack[top_of_stack])
//                break;
//            top_of_stack++;
//        }
//        top_of_stack++;
//
//        std::cout<<m<<" ";
//    }
//    return 0;
//}
#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 9;

int n;
int a[N];
int b[N];
bool u[N];

int main() {
//	freopen("input.txt", "r", stdin);
    scanf("%d", &n);
//    for(int i = 0; i < n; ++i) {
//        scanf("%d", a + i);
//    }
//    for(int i = 0; i < n; ++i){
//        scanf("%d", b + i);
//    }
    for(int i = 0 ; i < n  ; i++)
        std::cin>>a[i];

    for(int i = 0 ; i < n  ; i++)
        std::cin>>b[i];

    int pos = 0;
    for(int i = 0; i < n; ++i){
        if(u[b[i]]){
            printf("0 ");
            continue;
        }

        int cnt = 0;
        while(true){
            ++cnt;
            u[a[pos]] = true;
            if(a[pos] == b[i]) break;
            ++pos;
        }

        ++pos;
        printf("%d ", cnt);
    }

    puts("");
    return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
	if(v[i - 1].second > v[i].second and v[i].second < v[i].first){
		swap(v[i].first, v[i].second);
	}

  }
  cout<<"YES";

  return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
  	if(v[i - 1].second < v[i].second){
  		swap(v[i].first, v[i].second);
  	}
	if(v[i - 1].second > v[i].second and v[i].second < v[i].first){
		swap(v[i].first, v[i].second);
	}

  }
  for(int i = 0; i < t; i++){

  	cout<<v[i].first<<" "<<v[i].second<<"\n";

  }
  cout<<"YES";

  return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
  	if(v[i - 1].second < v[i].second){
  		swap(v[i].first, v[i].second);
  	}
  	if(v[i - 1].second >= v[i].first and v[i].first >= v[i].second){
  		swap(v[i].first, v[i].second);
  	}

  }
  if(v[v.size() - 2].second < v[v.size() - 1].first and v[v.size() - 2].second < v[v.size() - 1].second){
  		cout<<"NO";
  		return 0;
  }
  cout<<"YES";

  return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
  	if(v[i - 1].second < v[i].second){
  		swap(v[i].first, v[i].second);
  	}
	if(v[i - 1].second > v[i].second and v[i].second < v[i].first){
		swap(v[i].first, v[i].second);
	}

  }
  if(v[v.size() - 2].second < v[v.size() - 1].first and v[v.size() - 2].second < v[v.size() - 1].second){
  		cout<<"NO";
  		return 0;
  }
  cout<<"YES";

  return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
	if(v[i - 1].second > v[i].second and v[i].second < v[i].first){
		swap(v[i].first, v[i].second);
	}

  }
  cout<<"YES";

  system("PAUSE");
  return 0;
}


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

#define printV(x, y) for(ll i = 0; i < y; i++) cout<<x[i]<<" "
#define all(x) (x).begin(), (x).end()
#define ll long long

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int t;
  cin>>t;
  vector <pair <ll,ll> > v(t);
  cin>>v[0].first>>v[0].second; v[0].second = max(v[0].first, v[0].second);
  for(int i = 1; i < t; i++){

	cin>>v[i].first>>v[i].second;
  	if(v[i - 1].second < v[i].first and v[i - 1].second < v[i].second){
  		cout<<"NO";
  		return 0;
  	}
  	if(v[i - 1].second < v[i].second){
  		swap(v[i].first, v[i].second);
  	}
  	if(v[i - 1].second >= v[i].first and v[i].first >= v[i].second){
  		swap(v[i].first, v[i].second;
  	}

  }
  if(v[v.size() - 2].second < v[v.size() - 1].first and v[v.size() - 2].second < v[v.size() - 1].second){
  		cout<<"NO";
  		return 0;
  }
  cout<<"YES";

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
int main()
{
      int tt=5;
      while(tt--){
            int a,b,c;
            cin>>a;
            vector<PII>v;
            for(int i=0;i<a;i++){
                  cin>>b>>c;
                  v.push_back(PII(b,c));
            }
            for(int i=0; i<a-1; i++){
                  if(v[i].first>=v[i+1].first || v[i].second>=v[i+1].first) continue;
                  if(v[i].first>=v[i+1].second || v[i].second>=v[i+1].second) continue;
                  cout<<"NO"<<endl;
                  return 0;
            }

          printf("YES\n\n");
      }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define pf          push_front
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define mp          make_pair
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

ll gcd(ll a, ll b)
{
      if(!b) return a;
      return gcd(b,a%b);
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      int n;
      cin>>n;
      int arr[n][2];
      for(int i=0; i<n; i++){cin>>arr[i][0]>>arr[i][1];}
      bool flag=true;
      for(int i=1; i<n; i++){
            if(arr[i-1][0]>=arr[i][0] || arr[i-1][0]>=arr[i][1]){continue;}
            else if(arr[i-1][1]>=arr[i][0] || arr[i-1][1]>=arr[i][1]){continue;}
            else {flag=false;break;}
      }
      if(flag==true){yes;}
      else no;

      bye;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
int main()
{

      int a,b,c;
      cin>>a;
      vector<PII>v;
      for(int i=0;i<a;i++){
            cin>>b>>c;
            v.push_back(PII(b,c));
      }
      for(int i=0; i<a-1; i++){
            if(v[i].first>=v[i+1].first || v[i].second>=v[i+1].first) continue;
            if(v[i].first>=v[i+1].second || v[i].second>=v[i+1].second) continue;
            cout<<"NO"<<endl;
            return 0;
      }

    printf("YES");
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define pf          push_front
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define mp          make_pair
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

ll gcd(ll a, ll b)
{
      if(!b) return a;
      return gcd(b,a%b);
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      int n;
      cin>>n;
      int arr[n][2];
      for(int i=0; i<n; i++){cin>>arr[i][0]>>arr[i][1];}

      bool flag=true;
      int mx=max(arr[0][0],arr[0][1]);
      int tempMn,tempMx;
      for(int i=1; i<n; i++){
            tempMn=min(arr[i][0],arr[i][1]);
            tempMx=max(arr[i][0],arr[i][1]);
            if(mx>=tempMx){mx=tempMx;}
            else if(mx>=tempMn){mx=tempMn;}
            else{flag=false;break;}
      }
      if(flag==true){yes;}
      else no;

      bye;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>

using namespace std;
#define ll          long long
#define endl        "\n"
#define inf         10000000002
#define pb          push_back
#define pf          push_front
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(a)      a.begin(),a.end()
#define mp          make_pair
#define MAX         100
#define yes         cout<<"YES"<<endl
#define no          cout<<"NO"<<endl
#define bye         return 0

ll gcd(ll a, ll b)
{
      if(!b) return a;
      return gcd(b,a%b);
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      cout.tie(NULL);
      //freopen("inputNew.txt", "r", stdin);

      ll n;
      cin>>n;
      ll arr[n][2];
      for(ll i=0; i<n; i++){cin>>arr[i][0]>>arr[i][1];}

      bool flag=true;
      ll mx=max(arr[0][0],arr[0][1]);
      ll tempMn,tempMx;
      for(ll i=1; i<n; i++){
            tempMn=min(arr[i][0],arr[i][1]);
            tempMx=max(arr[i][0],arr[i][1]);
            if(mx>=tempMx){mx=tempMx;}
            else if(mx>=tempMn){mx=tempMn;}
            else{flag=false;break;}
      }
      if(flag==true){yes;}
      else no;

      bye;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
int main()
{
      int a,b,c;
      cin>>a;
      vector<PII>v;
      for(int i=0;i<a;i++){
            cin>>b>>c;
            v.push_back(PII(b,c));
      }
      for(int i=0;i<a-1;i++){
            if(v[i].first<v[i+1].first){
                  swap(v[i+1].first,v[i+1].second);
                  if(v[i].first<v[i+1].first){
                        swap(v[i+1].first,v[i+1].second);
                        swap(v[i].first,v[i+1].second);
                        if(v[i].first<v[i+1].first){
                              printf("NO");
                              return 0;
                        }
                  }
            }
      }

    printf("YES");
}


#include <bits/stdc++.h>

using namespace std;

long long n , p = 1e10;
int x , y;

int main(){
	cin >> n;

	for (int i = 0 ; i < n ; i++){
		cin >> x >> y;

		if (max(x , y) <= p)
		    p = max(x , y);

		else if (min(x , y) <= p)
		    p = min(x , y);

		else
		    return cout << "NO", 0;
	}
	cout << "YES";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n , p = pow 1e10;
int x , y;

int main(){
	cin >> n;

	for (int i = 0 ; i < n ; i++){
		cin >> x >> y;

		if (max(x , y) <= p)
		    p = max(x , y);

		else if (min(x , y) <= p)
		    p = min(x , y);

		else
		    return cout << "NO", 0;
	}
	cout << "YES";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long n , p = pow (10, 9) + 20;
int x , y;

int main(){
	cin >> n;

	for (int i = 0 ; i < n ; i++){
		cin >> x >> y;

		if (max(x , y) <= p)
		    p = max(x , y);

		else if (min(x , y) <= p)
		    p = min(x , y);

		else
		    return cout << "NO", 0;
	}
	cout << "YES";
	return 0;
}


#include <iostream>

using namespace std;

int main(){
        long long n , w , h , p;
        cin >> n;
        cin >> w >> h;

        p = max(w , h);

        for (long long i = 1 ; i < n ; i++){
                cin >> w >> h;
                if (w < h)
                        swap(w , h);
                if (w <= p)
                        p = w;
                else{
                        cout << "NO";
                        return 0;
                }
        }
        cout << "YES";
        return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
	long long n , w , h , p;
	cin >> n;
	cin >> w >> h;
	p = max(w , h);

	for (long long i = 1 ; i < n ; i++){
		cin >> w >> h;
		if (w < h)
			swap(w , h);
		if (w <= p)
			p = w;
		else{
			cout << "NO";
			return 0;
		}
	}
	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include <set>

using namespace std;
bool is_right(char x  )
{
    if (x== 'a' ||x== 'o'||x== 'u'||x== 'e'||x== 'i' ) return true ;
    else return 0 ;

}

//}
int main() {
  int n;
  cin >> n;
     pair <int, int> arr [n]   ;
     cin >>arr[0].first >>arr[0].second;

for (int   i = 1 ; i < n;   i++)
{

    cin >> arr[i].first >>arr[i].second ;
 }

    for (int   i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {

 if (arr[i].first < arr[i].second ) swap(arr[i].first,arr[i].second) ;

 if ( arr[i].second > arr[i-1].second   )  {

 if (arr[i].second >arr[i-1].first) {cout <<"no" ; return 0 ;}

 else swap(arr[i-1].first , arr[i-1].second) ;

 }

    }

}
for (int   i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {cout <<"2no" ; return 0 ;}

 }
    cout<<"yes" ; return 0 ; }


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >>n;
 pair <long long , long long >   arr[n] ;
    for (int i =  0 ; i <n; i ++) cin >>arr[i].first >>arr[i].second ;

    for (int i =  n-1 ; i >0; i --) {
bool s =false  ;

        if (arr[i].second >arr[i-1].second )

        {
            if (arr[i].first   < arr[i].second ) { swap(arr[i].first , arr[i].second); s = 1 ;  }
             if (arr[i-1].first   >  arr[i-1].second ) { swap(arr[i-1].first , arr[i-1].second);}
                if (arr[i].second  > arr[i-1].second){ cout << "no" ;  return 0 ; }
            }

if (s==1) i++;

     }

    cout <<"yes" ;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c[100005],d[100005];
    int flag=0;
    for(int i=0; i<n; i++)
    {
        cin>>c[i]>>d[i];
    }

    for(int i=1; i<n; i++)
    {
        if(d[i]>d[i-1])swap(c[i],d[i]);
        if(d[i]>d[i-1]){flag=1;break;}
    }
    if(flag)
        cout<<"NO";
    else
        cout<<"YES";return 0 ;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c[100005],d[100005];
    int flag=0;
    for(int i=0; i<n; i++)
    {
        cin>>c[i]>>d[i];
    }

    for(int i=1; i<n; i++)
    {
        if(d[i]>d[i-1])swap(c[i],d[i]);
        if(d[i]>d[i-1]){flag=1;break;}
    }
    if(flag)
        cout<<"NO";
    else
        cout<<"YES";
}
return 0 ; }


#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c[100005],d[100005];
    int flag=0;
    for(int i=0; i<n; i++)
    {
        cin>>c[i]>>d[i];
    }

    for(int i=1; i<n; i++)
    {
        if(d[i]>d[i-1])swap(c[i],d[i]);
        if(d[i]>d[i-1]){flag=1;break;}
    }
    if(flag)
        cout<<"NO";
    else
        cout<<"YES";
}
————————————————
版权声明：本文为CSDN博主「swqeaaa」的原创文章，遵循 CC 4.0 BY-SA 版权协议，转载请附上原文出处链接及本声明。
原文链接：https://blog.csdn.net/qq_32259423/article/details/81269444


#include <iostream>
#include<bits/stdc++.h>
#include <set>

using namespace std;
bool is_right(char x  )
{
    if (x== 'a' ||x== 'o'||x== 'u'||x== 'e'||x== 'i' ) return true ;
    else return 0 ;

}

//}
int main() {

  long long  n;
  cin >> n;
     pair <long long , long long > arr [n]   ;
     cin >>arr[0].first >>arr[0].second;

for (long long    i = 1 ; i < n;   i++)
{

    cin >> arr[i].first >>arr[i].second ;
 }

    for (long long    i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {

 if (arr[i].first < arr[i].second ) swap(arr[i].first,arr[i].second) ;

 if ( arr[i].second > arr[i-1].second   )  {

 if (arr[i].second >arr[i-1].first) {cout <<"no" ; return 0 ;}

 else swap(arr[i-1].first , arr[i-1].second) ;

 }

    }

}
for (long long    i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {cout <<"no" ; return 0 ;}

 }
    cout<<"yes" ; return 0 ; }


#include <iostream>
#include<bits/stdc++.h>
#include <set>

using namespace std;
bool is_right(char x  )
{
    if (x== 'a' ||x== 'o'||x== 'u'||x== 'e'||x== 'i' ) return true ;
    else return 0 ;

}

//}
int main() {

  long long  n;
  cin >> n;
     pair <long long , long long > arr [n]   ;
     cin >>arr[0].first >>arr[0].second;

for (long long    i = 1 ; i < n;   i++)
{

    cin >> arr[i].first >>arr[i].second ;
 }

    for (long long    i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {

 if (arr[i].first < arr[i].second ) swap(arr[i].first,arr[i].second) ;

 if ( arr[i].second > arr[i-1].second   )  {

 if (arr[i].second >arr[i-1].first) {cout <<"no" ; return 0 ;}

 else swap(arr[i-1].first , arr[i-1].second) ;

 }

    }

}
for (long long    i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {cout <<"2no" ; return 0 ;}

 }
    cout<<"yes" ; return 0 ; }


#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int c[100005],d[100005];
    int flag=0;
    for(int i=0; i<n; i++)
    {
        cin>>c[i]>>d[i];
    }
    for(int i=0; i<n; i++)
    {
        if(c[i]>d[i])
            swap(c[i],d[i]);
    }
    for(int i=1; i<n; i++)
    {
        if(d[i]>d[i-1])swap(c[i],d[i]);
        if(d[i]>d[i-1]){flag=1;break;}
    }
    if(flag)
        cout<<"NO";
    else
        cout<<"YES";
return 0;
}


#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int n=0;
  cin>>n;
  int a,b;
  cin>>a>>b;
  int curr=max(a,b);
  for(int i=1;i<n;i++)
  {
    cin>>a>>b;
        if (curr>=max(a,b)) curr=max(a,b);
        else if (curr>=min(a,b)) curr=min(a,b);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
  }
  cout<<"YES"<<endl;
  return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#include <set>

using namespace std;
bool is_right(char x  )
{
    if (x== 'a' ||x== 'o'||x== 'u'||x== 'e'||x== 'i' ) return true ;
    else return 0 ;

}

//}
int main() {
  int n;
  cin >> n;
     pair <int, int> arr [n]   ;
     cin >>arr[0].first >>arr[0].second  ;
for (int   i = 1 ; i < n;   i++)
{

    cin >>arr[i].first >>arr[i].second  ;
    if (arr[i].second>arr[i-1].second) {

        if (arr[i].first >arr[i-1].second)  {cout <<"no" ; return 0 ;}
        else swap(arr[i].first , arr[i].second) ;
    }

}
cout<<"yes" ;
    }


#include <iostream>
#include<bits/stdc++.h>
#include <set>

using namespace std;
bool is_right(char x  )
{
    if (x== 'a' ||x== 'o'||x== 'u'||x== 'e'||x== 'i' ) return true ;
    else return 0 ;

}

//}
int main() {
  int n;
  cin >> n;
     pair <int, int> arr [n]   ;
     cin >>arr[0].first >>arr[0].second;
      if (arr[0].first < arr[0].second )
for (int   i = 1 ; i < n;   i++)
{

    cin >> arr[i].first >>arr[i].second ;
 }
    for (int   i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {

 if (arr[i].first < arr[i].second ) swap(arr[i].first,arr[i].second) ;

 if ( arr[i].second > arr[i-1].second   )  {

 if (arr[i].second >arr[i-1].first) {cout <<"no" ; return 0 ;}

 else swap(arr[i-1].first , arr[i-1].second) ;

 }

    }

}
for (int   i = 1 ; i < n;   i++)
{
    if (arr[i].second>arr[i-1].second) {cout <<"no" ; return 0 ;}

 }
    cout<<"yes" ; return 0 ; }


#include <iostream>

using namespace std;

int main()
{
    long long n;
    cin >>n;
 pair <long long , long long >   arr[n] ;
    for (int i =  0 ; i <n; i ++) cin >>arr[i].first >>arr[i].second ;

    for (int i =  n-1 ; i >0; i --) {
bool s =false  ;

        if (arr[i].second >arr[i-1].second )

        {
            if (arr[i].first   < arr[i].second ) { swap(arr[i].first , arr[i].second); s = 1 ;  }
             if (arr[i-1].first   >  arr[i-1].second ) { swap(arr[i-1].first , arr[i-1].second);}
                if (arr[i].second  > arr[i-1].second){ cout << "no" ;  return 0 ; }
            }

if (s==1) i--;

     }

    cout <<"yes" ;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
           if(mx1>mn2 && mx1<mx2  && i==0)
           {
               a[i+1].first=mn2;
           }
         else if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>=mx2 )
           {  int j=i-1;
               if(a[j].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
           //cout<<"***"<<endl;
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 int j=i-1;
                 cout<<"***"<<endl;
               if(a[j].first<mx1 && i>=1)
               {
                   p=1;
                   break;
               }
               else{
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
               }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
           if(a[i].second >a[i].first)
             swap(a[i].first,a[i].second);
       }
       for(i=0;i<n-1;i++)
       {
           if(a[i+1].first > a[i].first && a[i+1].second > a[i].first)
           {
               p+=1;
               break;
           }
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
          if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>=mx2 )
           {  int j=i-1;
               if(a[j].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
           //cout<<"***"<<endl;
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 int j=i-1;
               if(a[j].first<mx1 && i>=1)
               {
                   p=1;
                   break;
               }
               else{
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
               }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}

            if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }
             else if(mn1<mx2 && mx1>mx2)
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);

                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }
               }
               else
               a[i].first=mx1;
           }
           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
           if(mx1>mn2 && mx1<mx2  && i==0)
           {
               a[i+1].first=mn2;
           }
         else if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>=mx2 )
           {  int j=i-1;
               if(a[j].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
           //cout<<"***"<<endl;
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 int j=i-1;
                 //cout<<"***"<<endl;
               if(a[j].first<mx1 && i>=1)
               {
                   p=1;
                   break;
               }
               else{
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
               }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}

            if(mn1<mx2 && mx1>mx2)
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
                   if(mn2=mx2 && mx1<mn2)
           {
               p=1;
               break;
           }
           else
           {
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }
                   else
               {a[i].first=mx1;}
               }

               }
           }

            else if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    for(i=0;i<n-1;i++)
    {
        if(a[i].first>=a[i+1].first)
           {p+=1; }
        else if(a[i].second >= a[i+1].first)
           { p+=1;  }

    }
    p++;
    if(p==n)
        cout<<"YES";
    else
        cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx,mn;
       for(i=0;i<n-1;i++)
       {
           mx=max(a[i].first,a[i].second);
           mn=min(a[i+1].first,a[i+1].second);
           if(mx<mn)
           {
               p+=1;
               break;
           }
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
           if(mx1>mn2 && mx1<mx2  && i==0)
           {
               a[i].first=mx1;
               a[i+1].first=mn2;
           }
          if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>=mx2 && i>=1)
           {  int j=i-1;
               if(a[j].first<mx1 )
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
           //cout<<"***"<<endl;
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 int j=i-1;
                 //cout<<"***"<<endl;
               if(a[j].first<mx1 && i>=1)
               {
                   p=1;
                   break;
               }
               else{
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
               }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
          if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>=mx2 )
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
           //cout<<"***"<<endl;
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}

            if(mn1<mx2 && mx1>mx2)
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            if(mn2==mx2 && mx1<mn2)
           {
               p=1;
               break;
           }
           else
           {
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }
                   else
               {a[i].first=mx1;}
               }

               }
           }

            else if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    for(i=0;i<n-1;i++)
    {
        if((a[i].first<a[i+1].first && a[i].second<a[i+1].first)&&(a[i].first<a[i+1].second && a[i].second<a[i+1].second))
            break;
        if(a[i].first>=a[i+1].first)
           {p+=1; }
        else if(a[i].second >= a[i+1].first)
           { p+=1;  }
        else if(a[i+1].second <= a[i].first || a[i+1].second<= a[i].second)
            p+=1;

    }
    p++;
    if(p==n)
        cout<<"YES";
    else
        cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    for(i=0;i<n-1;i++)
    {
        if(a[i].first>=a[i+1].first)
           {p+=1; }
        else if(a[i].second >= a[i+1].first)
           { p+=1;  }
        else if(a[i+1].second <= a[i].first || a[i+1].second<= a[i].second)
            p+=1;

    }
    p++;
    if(p==n)
        cout<<"YES";
    else
        cout<<"NO";

}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}
          if(mx1<mn2)
          {
              p=1;
              break;
          }

        else if(mn1<mx2 && mx1>mx2 )
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);
            //if(mn2==mx2 )
           //{
               //p=1;
               //break;
           //}
           //else
           //{
                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }

        }
            else
               {a[i].first=mx1;}

               }
           //}

           else  if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           if(a[i].first>a[i+1].first)
           {
               continue;
           }
           else if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }
             else if(mn1<mx2 && mx1>mx2)
           {
               a[i].first=mx1;
           }
           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}

           if(mn1<mx2 && mx1>mx2)
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);

                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }
               }
               else
               {a[i].first=mx1;
           }

            else if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


#include<bits/stdc++.h>
using namespace std;
int mex(int a,int b)
{
    return max(a,b);
}
int main()
{
    long long int n,i,p=0;
    cin>>n;
    pair<int,int>a[n];
    for(i=0;i<n;i++)
       {
           cin>>a[i].first>>a[i].second;
          // if(a[i].second >a[i].first)
             //swap(a[i].first,a[i].second);
       }
       int mx1,mn1,st,mx2,mn2,s1,s2;
       for(i=0;i<n-1;i++)
       {
           mx1=max(a[i].first,a[i].second);
           mn1=min(a[i].first,a[i].second);
           mx2=max(a[i+1].first,a[i+1].second);
           mn2=min(a[i+1].first,a[i+1].second);
           s1=a[i].first;
           s2=a[i].second;
           //if(a[i].first>a[i+1].first)
           //{
               //continue;
           //}

           if(mn1<mx2 && mx1>mx2)
           {
               if(a[i-1].first<mx1 && i>=1)
               {
                   //a[i-1].first=mex(a[i-1].first,a[i-1].second);

                   a[i+1].first=mn2;
                   if(a[i].first<a[i+1].first)
                   {
                       p=1;
                       break;
                   }
               }
               else
               {a[i].first=mx1;}
           }

            else if(mn1<mn2)
             {
                 a[i].first=mx1;
                 if(mx1<mn2)
                 {
                     p+=1;
                     break;
                 }
             }

           //if(mx<mn)
           //{

           //}
       }
       if(p)
        cout<<"NO";
       else
        cout<<"Yes";
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie();
    ll n,mx,mn;
    cin>>n;
    pair<ll,ll> a[n];
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second;
    }
    bool valid=1;
    ll x=max(a[0].first,a[0].second);
    for(int i=1;i<n;i++){
        mx=max(a[i].first,a[i].second);
        mn=min(a[i].first,a[i].second);
        if(mx>x && mn>x){
            valid=0;
            break;
        }
        else if(mx>x && mn<=x){
            x=mn;
        }
        else{
            x=mx;
        }
    }
    if(valid) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y){return (x<y) ? x : y;}
int max(int x, int y){return (x>y) ? x : y;}
struct NODE{int x,y;} a[100861];
int main()
{
    int n;
    cin>>n;
    int count = max(a[0].x,a[0].y);;
    for(int i=0; i<n-1; i++)
    {
        if (count >= max(a[i+1].x,a[i+1].y))
            count = max(a[i+1].x,a[i+1].y);
        else if((count >= min(a[i+1].x,a[i+1].y)))
            count = min(a[i+1].x,a[i+1].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y){return (x<y) ? x : y;}
int max(int x, int y){return (x>y) ? x : y;}
struct NODE{
    int x,y;
}a[10086];

int main()
{
   int n;
   cin>>n;
   for(int i=0; i<n; i++)
    cin>>a[i].x>>a[i].y;
    for(int i=0; i<n-1; i++)
    {
            if(min(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else if(max(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }
    }
    cout<<"YES"<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y)
{
    return (x<y) ? x : y;
}
int max(int x, int y)
{
    return (x>y) ? x : y;
}
struct NODE
{
    int x,y;
} a[100861];

int main()
{
    int n;
    cin>>n;
    int count;
    for(int i=0; i<n; i++)
        cin>>a[i].x>>a[i].y;
    if(min(a[0].x,a[0].y)>=min(a[1].x,a[1].y))
        count=min(a[0].x,a[0].y);
    else if(max(a[0].x,a[0].y)>=min(a[1].x,a[1].y))
        count=max(a[0].x,a[0].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    for(int i=0;i<n-1;i++)
    {
      if (count >= min(a[i+1].x,a[i+1].y))
            count = min(a[i+1].x,a[i+1].y);
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }

    }
    cout<<"YES"<<endl;

        return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y)
{
    return (x<y) ? x : y;
}
int max(int x, int y)
{
    return (x>y) ? x : y;
}
struct NODE
{
    int x,y;
} a[100861];

int main()
{
    int n;
    cin>>n;
    int count;
    for(int i=0; i<n; i++)
        cin>>a[i].x>>a[i].y;
    if(max(a[0].x,a[0].y)>=max(a[1].x,a[1].y))
        count=max(a[0].x,a[0].y);
    else if(max(a[0].x,a[0].y)>=min(a[1].x,a[1].y))
        count=max(a[0].x,a[0].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    for(int i=0;i<n-1;i++)
    {
      if (count >= max(a[i+1].x,a[i+1].y))
            count = max(a[i+1].x,a[i+1].y);
            else if((count >= min(a[i+1].x,a[i+1].y)))
                count = min(a[i+1].x,a[i+1].y);
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }

    }
    cout<<"YES"<<endl;

        return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y){return (x<y) ? x : y;}
int max(int x, int y){return (x>y) ? x : y;}
struct NODE{int x,y;} a[100861];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i].x>>a[i].y;
    int count = max(a[0].x,a[0].y);;
    for(int i=0; i<n-1; i++)
    {
        if (count >= max(a[i+1].x,a[i+1].y))
            count = max(a[i+1].x,a[i+1].y);
        else if((count >= min(a[i+1].x,a[i+1].y)))
            count = min(a[i+1].x,a[i+1].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }

    }
    cout<<"YES"<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y){return (x<y) ? x : y;}
int max(int x, int y){return (x>y) ? x : y;}
struct NODE{
    int x,y;
}a[100861];

int main()
{
   int n;
   cin>>n;
   for(int i=0; i<n; i++)
    cin>>a[i].x>>a[i].y;
    for(int i=0; i<n-1; i++)
    {
            if(min(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else if(max(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }
    }
    cout<<"YES"<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y){return (x<y) ? x : y;}
int max(int x, int y){return (x>y) ? x : y;}
struct NODE{
    int x,y;
}a[100861];

int main()
{
   int n;
   cin>>n;
   for(int i=0; i<n; i++)
    cin>>a[i].x>>a[i].y;
    for(int i=0; i<n; i++)
    {
            if(min(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else if(max(a[i].x,a[i].y)>=min(a[i+1].x,a[i+1].y))
               ;
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }
    }
    cout<<"YES"<<endl;

    return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y)
{
    return (x<y) ? x : y;
}
int max(int x, int y)
{
    return (x>y) ? x : y;
}
struct NODE
{
    int x,y;
} a[100861];

int main()
{
    int n;
    cin>>n;
    int count;
    for(int i=0; i<n; i++)
        cin>>a[i].x>>a[i].y;
    if(min(a[0].x,a[0].y)>=max(a[1].x,a[1].y))
        count=min(a[0].x,a[0].y);
    else if(max(a[0].x,a[0].y)>=max(a[1].x,a[1].y))
        count=max(a[0].x,a[0].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
        cout<<count<<endl;
    for(int i=0;i<n-1;i++)
    {
      if (count >= max(a[i+1].x,a[i+1].y))
            count = max(a[i+1].x,a[i+1].y);
            else if((count >= min(a[i+1].x,a[i+1].y)))
                count = min(a[i+1].x,a[i+1].y);
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }

    }
    cout<<"YES"<<endl;

        return 0;
}


#include <iostream>
#include <cstring>
using namespace std;
int min(int x, int y)
{
    return (x<y) ? x : y;
}
int max(int x, int y)
{
    return (x>y) ? x : y;
}
struct NODE
{
    int x,y;
} a[100861];

int main()
{
    int n;
    cin>>n;
    int count;
    for(int i=0; i<n; i++)
        cin>>a[i].x>>a[i].y;
    if(min(a[0].x,a[0].y)>=min(a[1].x,a[1].y))
        count=min(a[0].x,a[0].y);
    else if(max(a[0].x,a[0].y)>=min(a[1].x,a[1].y))
        count=max(a[0].x,a[0].y);
        else
        {
            cout<<"NO"<<endl;
            return 0;
        }
    for(int i=1;i<n-1;i++)
    {
      if (count >= min(a[i+1].x,a[i+1].y))
            count = min(a[i+1].x,a[i+1].y);
            else
            {
                cout<<"NO"<<endl;
                return 0;
            }

    }
    cout<<"YES"<<endl;

        return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=1000000001, flag1=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0)
            continue;

        if(max(a,b)<=asc)
        {
            asc=max(a,b);
            cout << asc << endl;
        }
        else if(min(a,b) <= asc)
        {
            asc=min(a,b);
            cout << asc << endl;
        }
        else
            flag1=0;

    }

    if(flag1==0)
        cout << "NO\n" ;
    else
        cout << "YES\n" ;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=1000000001, flag1=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0)
            continue;

        if(max(a,b)<=asc)
        {
            asc=max(a,b);
        }
        else if(min(a,b) <= asc)
        {
            asc=min(a,b);
        }
        else
            flag1=0;

    }

    if(flag1==0)
        cout << "NO\n" ;
    else
        cout << "YES\n" ;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=0, des=1000000001, flag1=1, flag2=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0 && flag2==0)
            continue;

        if(min(a,b)>=asc)
        {
            asc=min(a,b);
        }
        else
            flag1=0;
        if(max(a,b)<=des)
        {
            des=max(a,b);
        }
        else
            flag2=0;
    }

    if(flag1==0 && flag2==0)
        cout << "YES\n" ;
    else
        cout << "NO\n" ;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=100000000, flag1=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0)
            continue;

        if(max(a,b)<=asc)
        {
            asc=max(a,b);
        }
        else if(min(a,b) <= asc)
        {
            asc=min(a,b);
        }
        else
            flag1=0;

    }

    if(flag1==0 || (n==1 && flag1==1))
        cout << "NO\n" ;
    else
        cout << "YES\n" ;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=100000000, flag1=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0)
            continue;

        if(max(a,b)<=asc)
        {
            asc=max(a,b);
        }
        else if(min(a,b) <= asc)
        {
            asc=min(a,b);
        }
        else
            flag1=0;

    }

    if(flag1==0)
        cout << "NO\n" ;
    else
        cout << "YES\n" ;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    int i, j, n, a,b, asc=100000000, flag1=1;

    cin >> n;

    while(n--)
    {
        cin >> a >> b;

        if(flag1==0)
            continue;

        if(max(a,b)<=asc)
        {
            asc=max(a,b);
        }
        else if(min(a,b) <= asc)
        {
            asc=min(a,b);
        }
        else
            flag1=0;

    }

    if(flag1==0 || n!=1)
        cout << "NO\n" ;
    else
        cout << "YES\n" ;

    return 0;
}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n)   for(int i=0;i<(int)(n);i++)
#define GCC_go ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define stop system("pause");
#define F first
#define S second
#define fx fixed
#define setp(n) setprecision(n)
#define OO 1e4
typedef  long long ll;
template <class T>inline void arin(T* st, T* nd){while(st<nd)cin>>*st++;}

const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,-1,1,-1};

class MATH{

                                       	public : MATH(){}
          int count=0;

// ------------------------------------
ll GCD(ll a, ll b) {
	return b == 0 ? a : GCD(b, a % b);
}
//-------------------------------------
ll LCM(ll i, ll j)
{
	return (i*j) / GCD(i, j);
}
//----------------------------------------
ll pows(ll n){return (1<<n);}
//-----------------------------------------
bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}
};

vector<pair<ll,ll> >inp;
int n;

        /*
  bool solve(){
               if(i==n)
return true;

if(inp[i].second>=inp[i+1].second)
  solve(i+1);
else{
swap(inp[i].second,inp[])
}

}

              */

int main()
{          ll a,b;
 cin>>n;
loop(i,n){
cin>>a>>b;
inp.push_back({a,b});
}

loop(i,n-1){
               bool on=false;
if(!(inp[i].second>=inp[i+1].second)){
  swap(inp[i].first,inp[i].second);

}
if(!(inp[i].second>=inp[i+1].second)){
  swap(inp[i+1].first,inp[i+1].second);

}
if(!(inp[i].second>=inp[i+1].second)){
  swap(inp[i].first,inp[i].second);

}
if(!(inp[i].second>=inp[i+1].second)){
  cout<<"NO";return 0;

}      }

cout<<"YES";

}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n)   for(int i=0;i<(int)(n);i++)
#define GCC_go ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define stop system("pause");
#define F first
#define S second
#define fx fixed
#define setp(n) setprecision(n)
#define OO 1e4
typedef  long long ll;
template <class T>inline void arin(T* st, T* nd){while(st<nd)cin>>*st++;}

const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,-1,1,-1};

class MATH{

                                       	public : MATH(){}
          int count=0;

// ------------------------------------
ll GCD(ll a, ll b) {
	return b == 0 ? a : GCD(b, a % b);
}
//-------------------------------------
ll LCM(ll i, ll j)
{
	return (i*j) / GCD(i, j);
}
//----------------------------------------
ll pows(ll n){return (1<<n);}
//-----------------------------------------
bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}
};

vector<pair<ll,ll> >inp;

int n,q;

  void solve(int i,ll x,ll y,bool w){
                           // cout<<x<<" "<<y<<endl;
             if(x<y)
                return ;

 if(i==q-1) {
           cout<<"YES";
             exit(0);}
        if(w)
solve(i+1,inp[i].second,inp[i+1].second,1);
if(w)
solve(i+1,inp[i].second,inp[i+1].first,0);
if(!w)
solve(i+1,inp[i].first,inp[i+1].second,1);
if(!w)
solve(i+1,inp[i].first,inp[i+1].first,0);

                          return ;

                                    }

int main()
{          ll a,b;
 cin>>n;
loop(i,n){
scanf("%I64d%I64d",&a,&b)  ;
if(!(i&&a==inp[i].first&&inp[i].second==b)){

inp.push_back({a,b});            }
}
         q=inp.size();
  if(inp[0].second>inp[0].first)
solve(0,2,2,1);
else
solve(0,2,2,0);

       cout<<"NO";

}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n)   for(int i=0;i<(int)(n);i++)
#define GCC_go ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define stop system("pause");
#define F first
#define S second
#define fx fixed
#define setp(n) setprecision(n)
#define OO 1e4
typedef  long long ll;
template <class T>inline void arin(T* st, T* nd){while(st<nd)cin>>*st++;}

const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,-1,1,-1};

class MATH{

                                       	public : MATH(){}
          int count=0;

// ------------------------------------
ll GCD(ll a, ll b) {
	return b == 0 ? a : GCD(b, a % b);
}
//-------------------------------------
ll LCM(ll i, ll j)
{
	return (i*j) / GCD(i, j);
}
//----------------------------------------
ll pows(ll n){return (1<<n);}
//-----------------------------------------
bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}
};

vector<pair<ll,ll> >inp;

int n;

  void solve(int i,ll x,ll y){

             if(x<y)
                return ;

 if(i==n-1) {
           cout<<"YES";
             exit(0);}

solve(i+1,inp[i].second,inp[i+1].second);
solve(i+1,inp[i].second,inp[i+1].first);
solve(i+1,inp[i].first,inp[i+1].second);
solve(i+1,inp[i].first,inp[i+1].first);

}

int main()
{          ll a,b;
 cin>>n;
loop(i,n){
cin>>a>>b;
inp.push_back({a,b});
}
                inp.push_back({0,0});

solve(0,2,2);

       cout<<"NO";

}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n)   for(int i=0;i<(int)(n);i++)
#define GCC_go ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define stop system("pause");
#define F first
#define S second
#define fx fixed
#define setp(n) setprecision(n)
#define OO 1e4
typedef  long long ll;
template <class T>inline void arin(T* st, T* nd){while(st<nd)cin>>*st++;}

const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,-1,1,-1};

ll n,u,sorc,a,b;
vector<ll>dsu;
class MATH{

                                       	public : MATH(){}
          int count=0;

// ------------------------------------
ll GCD(ll a, ll b) {
	return b == 0 ? a : GCD(b, a % b);
}
//-------------------------------------
ll LCM(ll i, ll j)
{
	return (i*j) / GCD(i, j);
}
//----------------------------------------
ll pows(ll n){return (1<<n);}
//-----------------------------------------
bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}
                          //
void finddsu(int Node,int depth){
	if(!depth)return ;
//	//cout<<Node<<"  #"<<endl;
	if(dsu[Node]== -1){
		count++;
		dsu[Node]=sorc;
  	return ;
	}
		if(dsu[Node]==sorc)
		return ;
		return finddsu(dsu[Node],depth-1);

}

};

bool cmd(pair<ll,ll>a,pair<ll,ll>b){return (a.F<b.S);}

int main(){

	                                      MATH math;

int n;
ll mx=1e10,a,b;
 ll aft1=0,aft2=0;
cin>>n;
loop(i,n){
          cin>>a>>b;

if(!i){
mx=max(a,b);}
else{
       aft1=max(a,b);
       aft2=min(a,b);
        if(mx>=aft1){
            mx=aft1;}
           else if(mx>=aft2){
           mx=aft2;}
       else{
cout<<"No";return 0;}

}

}
cout<<"YES";

}


#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
using namespace std;
#define loop(i,n)   for(int i=0;i<(int)(n);i++)
#define GCC_go ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define stop system("pause");
#define F first
#define S second
#define fx fixed
#define setp(n) setprecision(n)
#define OO 1e4
typedef  long long ll;
template <class T>inline void arin(T* st, T* nd){while(st<nd)cin>>*st++;}

const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,-1,1,-1};

class MATH{

                                       	public : MATH(){}
          int count=0;

// ------------------------------------
ll GCD(ll a, ll b) {
	return b == 0 ? a : GCD(b, a % b);
}
//-------------------------------------
ll LCM(ll i, ll j)
{
	return (i*j) / GCD(i, j);
}
//----------------------------------------
ll pows(ll n){return (1<<n);}
//-----------------------------------------
bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}
};

vector<pair<ll,ll> >inp;

int n;

  void solve(int i,ll x,ll y,bool w){
                           // cout<<x<<" "<<y<<endl;
             if(x<y)
                return ;

 if(i==n-1) {
           cout<<"YES";
             exit(0);}
        if(w)
solve(i+1,inp[i].second,inp[i+1].second,1);
if(w)
solve(i+1,inp[i].second,inp[i+1].first,0);
if(!w)
solve(i+1,inp[i].first,inp[i+1].second,1);
if(!w)
solve(i+1,inp[i].first,inp[i+1].first,0);

                          return ;

}

        /*

          5
         5   5
         6    4
           5 5
         3   3
         2    2

*/

int main()
{          ll a,b;
 cin>>n;
loop(i,n){
cin>>a>>b;
inp.push_back({a,b});
}
                inp.push_back({0,0});

solve(0,2,2,1);
solve(0,2,2,0);

       cout<<"NO";

}