#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <math.h>
#include <queue>
#include <bitset>
#include <cmath>
#include <complex>
#include <iomanip>
#include <valarray>
#include <stack>
#include <cstring>

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef vector<ull> vull;
typedef set<string> ss;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef pair<int, ii> iii;
typedef vector<iii> viii;
typedef vector<viii> vviii;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef map<string, int> msi;
typedef multiset<int> mlsi;
typedef set<ii> sii;
typedef map<int, ii> mii;
typedef pair<string, int> psi;
typedef queue<int> qi;
typedef pair<int, vi> pivi;
typedef vector<pivi> vpivi;
typedef pair<int, ii> iii;
typedef vector<iii> viii;
typedef pair<int, bool> ib;
typedef vector<ib> vib;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<vib> vvib;
typedef set<int> si;
typedef pair<bool, bool> bb;
typedef long long ll;
typedef pair<ll, ll>pll;
typedef vector<ll>vll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vll> vvll;

#define PI 3.14159265

/* ii;
class SegTree {
public:
   vii A;
   vi st;
   int n;

   int left(int i) {
       return (i << 1);
   }

   int right(int i) {
       return (i << 1) + 1;
   }

   void build(int p, int L, int R) {
       if (L == R)
           st[p] = L;
       else {
           build(left(p), L, (L + R) / 2);
           build(right(p), (L + R) / 2 + 1, R);
           int p1 = st[left(p)];
           int p2 = st[right(p)];
           st[p] = A[p1].second <= A[p2].second ? p1 : p2;
       }
   }

   SegTree(const vii &_A) {
       A = _A;
       n = _A.size();
       st.assign(4 * n, -1);
       build(1, 0, n - 1);
   }

   int rmq(int p, int L, int R, int i, int j) {
       if (i > R || j < L) return -1;
       if (L >= i && R <= j) return st[p];
       int p1 = rmq(left(p), L, (L + R) / 2, i, j);
       int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
       if (p1 == -1) return p2;
       if (p2 == -1) return p1;

       return (A[p1].second <= A[p2].second ? p1 : p2);
   }

   int rmq(int i, int j) {
       return rmq(1, 0, n - 1, i, j);
   }

   int getIndex(int p, int L, int R, int pos) {
       if (L == R) return p;
       if (pos <= (L + R) / 2) return getIndex(left(p), L, (L + R) / 2, pos);
       return getIndex(right(p), (L + R) / 2 + 1, R, pos);
   }

   void update(int pos, int value) {
       A[pos].second = value;
       pos = getIndex(1, 0, n - 1, pos);
       pos /= 2;

       while (pos != 0) {
           int p1 = st[left(pos)];
           int p2 = st[right(pos)];

           if (p1 >= 0 && p2 >= 0)
               st[pos] = A[p1].second <= A[p2].second ? p1 : p2;
           pos /= 2;
       }
   }
};
 */

class SegTree {
public:
    vll A;
    vll st;
    int n;

    int left(int i) {
        return (i << 1);
    }

    int right(int i) {
        return (i << 1) + 1;
    }

    void build(int p, int L, int R) {
        if (L == R)
            st[p] = L;
        else {
            build(left(p), L, (L + R) / 2);
            build(right(p), (L + R) / 2 + 1, R);
            int p1 = st[left(p)];
            int p2 = st[right(p)];
            st[p] = A[p1] >= A[p2] ? p1 : p2;
        }
    }

    SegTree(const vll &_A) {
        A = _A;
        n = _A.size();
        st.assign(4 * n, -1);
        build(1, 0, n - 1);
    }

    int rmq(int p, int L, int R, int i, int j) {
        if (i > R || j < L) return -1;
        if (L >= i && R <= j) return st[p];
        int p1 = rmq(left(p), L, (L + R) / 2, i, j);
        int p2 = rmq(right(p), (L + R) / 2 + 1, R, i, j);
        if (p1 == -1) return p2;
        if (p2 == -1) return p1;

        return (A[p1] >= A[p2] ? p1 : p2);
    }

    int rmq(int i, int j) {
        if (i < 0)
            i = 0;

        return rmq(1, 0, n - 1, i, j);
    }

    int getIndex(int p, int L, int R, int pos) {
        if (L == R) return p;
        if (pos <= (L + R) / 2) return getIndex(left(p), L, (L + R) / 2, pos);
        return getIndex(right(p), (L + R) / 2 + 1, R, pos);
    }

    void update(int pos, int value) {
        A[pos] = value;
        pos = getIndex(1, 0, n - 1, pos);
        pos /= 2;

        while (pos != 0) {
            int p1 = st[left(pos)];
            int p2 = st[right(pos)];

            if (p1 >= 0 && p2 >= 0)
                st[pos] = A[p1] >= A[p2] ? p1 : p2;
            pos /= 2;
        }
    }
};

class UnionFind {
public:
    vi rank;
    vii p;

    UnionFind(int N) {
        rank.assign(N, 0);
        p.assign(N, ii(0, 1));
        for (int i = 0; i < N; i++) p[i].first = i;
    }

    int findSet(int i) {
        return (p[i].first == i) ? i : (p[i].first = findSet(p[i].first));
    }

    bool isSameSet(int i, int j) {
        return findSet(i) == findSet(j);
    }

    void unionSet(int i, int j) {
        if (!isSameSet(i, j)) {
            int x = findSet(i), y = findSet(j);
            if (rank[x] > rank[y]) {
                p[y].first = x;
                p[x].second += p[y].second;
            } else {
                p[x].first = y;
                p[y].second += p[x].second;
                if (rank[x] == rank[y]) rank[y]++;
            }
        }
    }

    int getMaxId() {
        int maxIn = 0;
        for (int i = 0; i < p.size(); i++)
            if (p[i].second > p[maxIn].second)
                maxIn = i;

        return maxIn;
    }

    int getNum() {
        si par;

        for (int i = 0; i < p.size(); i++)
            par.insert(p[i].first);
        return par.size();
    }

};

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int tc;
    cin >> tc;
    while (tc--) {
        int n;
        cin >> n;
        vull a, b;

        a.assign(n, 0);
        b.assign(n, 0);

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

        if (n == 1) {
            cout << "0\n";
            continue;
        }

        pair<ull, ull > h, hl, hr;
        h.first = a[0];
        h.second = 0;

        hl.first = a[0];
        hl.second = (1ull << 60);

        hr.first = max(a[1] + 1, a[0]);
        hr.second = (max(0ull, a[1] - a[0] + 1)) * b[0];

        for (int i = 1; i < n; i++) {
            pair<ull, ull> th, thl, thr;

            th.first = a[i];
            thl.first = max(a[i], a[i - 1] + 1);
            thr.first = max(a[i], a[i + 1] + 1);

            th.second = thl.second = thr.second = (1ull << 60);

            if (th.first != h.first) th.second = min(th.second, h.second);
            if (th.first != hl.first) th.second = min(th.second, hl.second);
            if (th.first != hr.first) th.second = min(th.second, hr.second);

            if (thl.first != h.first) thl.second = min(thl.second, h.second);
            if (thl.first != hl.first) thl.second = min(thl.second, hl.second);
            if (thl.first != hr.first) thl.second = min(thl.second, hr.second);

            thl.second += (thl.first - a[i]) * b[i];

            if (thr.first != h.first) thr.second = min(thr.second, h.second);
            if (thr.first != hl.first) thr.second = min(thr.second, hl.second);
            if (thr.first != hr.first) thr.second = min(thr.second, hr.second);

            thr.second += (thr.first - a[i]) * b[i];

            h = th;
            hl = thl;
            hr = thr;
        }

        ull res = min(h.second , hl.second);
        res = min(res , hr.second);
        cout << res << endl;

    }

}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jakestrj
 */

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define mem (arr, a) memset(arr, a, sizeof(arr))
#define sz(x) ((int)(x).size())
#define len(x) (int)(sizeof(x)/sizeof(x[0]))
#define endl "\n"
#define INF 0x20202020
#define EPS 1e-9
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> si;

class B {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		int n,x,y; cin >> n >> x >> y;
		int prev =max(x,y);
		rep(i, 0, n){
			cin >> x >> y;
			if(x>prev && y>prev) {cout << "NO" << endl; return; }
			prev = (x>=y && x<=prev) ? x : y;
		}
		cout << "YES" << endl;
	}
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jakestrj
 */

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define rep(i, j, k) for(int i=(j);i<(k);++i)
#define repi(i, j, k) for(int i=(j);i<=(k);++i)
#define per(i, j, k) for(int i=(j);i>(k);--i)
#define peri(i, j, k) for(int i=(j);i>=(k);--i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).begin(),(x).end(), greater<int>()
#define mem (arr, a) memset(arr, a, sizeof(arr))
#define sz(x) ((int)(x).size())
#define len(x) (int)(sizeof(x)/sizeof(x[0]))
#define endl "\n"
#define INF 0x20202020
#define EPS 1e-9
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> si;

class B {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		int n,x,y; cin >> n >> x >> y;
		int prev =max(x,y);
		rep(i, 0, n){
			cin >> x >> y;
			if(x>prev && y>prev) {cout << "NO" << endl; return; }
		}
		cout << "YES" << endl;
	}
};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	B solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include<iostream>
using namespace std;

int rect[100000][2];
int main()
{
	int n;
	cin>>n;
	if(n==1)cout<<"NO"<<endl;
	else
	{
	for(int i=0;i<n;i++)
	{
		cin>>rect[i][0];
		cin>>rect[i][1];
	}
int mx1,mx2;
if(rect[0][0]>=rect[0][1])mx1=rect[0][0];
else mx1=rect[0][1];
for(int i=1;i<n;i++)
	{
		if(rect[i][0]<=mx1 || rect[i][1]<=mx1)
		{
			if(rect[i][0]<=mx1 && rect[i][1]<=mx1)
			{
				if(rect[i][0]>=rect[i][1])mx1=rect[i][0];
				else mx1=rect[i][1];
				}
			else if(rect[i][0]<=mx1)mx1=rect[i][0];
			else if(rect[i][1]<=mx1)mx1=rect[i][1];
		}
		else
		{
		 cout<<"NO"<<endl;
		 break;
		}
		if(i==n-1)cout<<"YES"<<endl;
	}
	}
}
/*
3
1 8
2 5
9 3
*/


#include<iostream>
using namespace std;

int rect[1000][2];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>rect[i][0];
		cin>>rect[i][1];
	}
int mx1,mx2;
if(rect[0][0]>=rect[0][1])mx1=rect[0][0];
else mx1=rect[0][1];
for(int i=1;i<n;i++)
	{
		if(rect[i][0]<=mx1 || rect[i][1]<=mx1)
		{
			if(rect[i][0]<=mx1 && rect[i][1]<=mx1)
			{
				if(rect[i][0]>=rect[i][1])mx1=rect[i][0];
				else mx1=rect[i][1];
				}
			else if(rect[i][0]<=mx1)mx1=rect[i][0];
			else if(rect[i][1]<=mx1)mx1=rect[i][1];
		}
		else
		{
		 cout<<"NO"<<endl;
		 break;
		}
		if(i==n-1)cout<<"YES"<<endl;
	}
}
/*
3
1 8
2 5
9 3
*/


#include<iostream>
using namespace std;

int rect[100000][2];
int main()
{
	int n;
	cin>>n;
	if(n==1)cout<<"YES"<<endl;
	else
	{
	for(int i=0;i<n;i++)
	{
		cin>>rect[i][0];
		cin>>rect[i][1];
	}
int mx1,mx2;
if(rect[0][0]>=rect[0][1])mx1=rect[0][0];
else mx1=rect[0][1];
for(int i=1;i<n;i++)
	{
		if(rect[i][0]<=mx1 || rect[i][1]<=mx1)
		{
			if(rect[i][0]<=mx1 && rect[i][1]<=mx1)
			{
				if(rect[i][0]>=rect[i][1])mx1=rect[i][0];
				else mx1=rect[i][1];
				}
			else if(rect[i][0]<=mx1)mx1=rect[i][0];
			else if(rect[i][1]<=mx1)mx1=rect[i][1];
		}
		else
		{
		 cout<<"NO"<<endl;
		 break;
		}
		if(i==n-1)cout<<"YES"<<endl;
	}
	}
}
/*
3
1 8
2 5
9 3
*/


#include<iostream>
using namespace std;

int rect[100000][2];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>rect[i][0];
		cin>>rect[i][1];
	}
int mx1,mx2;
if(rect[0][0]>=rect[0][1])mx1=rect[0][0];
else mx1=rect[0][1];
for(int i=1;i<n;i++)
	{
		if(rect[i][0]<=mx1 || rect[i][1]<=mx1)
		{
			if(rect[i][0]<=mx1 && rect[i][1]<=mx1)
			{
				if(rect[i][0]>=rect[i][1])mx1=rect[i][0];
				else mx1=rect[i][1];
				}
			else if(rect[i][0]<=mx1)mx1=rect[i][0];
			else if(rect[i][1]<=mx1)mx1=rect[i][1];
		}
		else
		{
		 cout<<"NO"<<endl;
		 break;
		}
		if(i==n-1)cout<<"YES"<<endl;
	}
}
/*
3
1 8
2 5
9 3
*/


#include<iostream>
#define Max(A,B) (A)>(B)?(A):(B)
using namespace std;
int main(){
	int x,y;
	int n;
	cin>>n;
	int t=1;
	int z=1000000009;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		int g=Max(x,y);
		if(g<=z)
		z=g;
		else if(x<=z)
		z=x;
		else if(y<=z)
		z=y;
		else t=0;

	}
	if(t==1)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#define Max(A,B) (A)>(B)?(A):(B)
using namespace std;
int main(){
	int x,y;
	int n;
	cin>>n;
	int t=1;
	int z=1000000009;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		if(Max(x,y)<=z)
		z=Max(x,y);
		else if(x<=z)
		z=x;
		else if(y<=z)
		z=y;
		else t=0;

	}
	if(t==1)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
struct point{
	int w,h;
};
int main(){
#ifdef LOCAL
	freopen("Text.txt","r",stdin);
#endif
	point a[100001];
	int n;
	cin>>n;
	int t=1;
	a[0].h=a[0].w=9999999999;
	for(int i=1;i<=n;i++){
		cin>>a[i].w>>a[i].h;
		if(max(a[i].h,a[i].w)<=a[i-1].h)
			a[i].h=max(a[i].h,a[i].w);
		else if(a[i].h<=a[i-1].h)
		   continue;
		else if(a[i].w<=a[i-1].h){
		    swap(a[i].w,a[i].h);
			continue;
		}
		else t=0;

	}
	if(t==1)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
using namespace std;
struct point{
	int w,h;
};
int main(){
	point a[100001];
	int n;
	cin>>n;
	int t=1;
	a[0].h=a[0].w=1000000009;
	for(int i=1;i<=n;i++){
		cin>>a[i].w>>a[i].h;
		if(a[i].w<=a[i-1].w||a[i].h<=a[i-1].h||a[i].h<=a[i-1].w||a[i].w<=a[i-1].h)
		continue;
		else t=0;
	}
	if(t==1)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include<iostream>
using namespace std;
struct point{
	int w,h;
};
int main(){
	point a[100001];
	int n;
	cin>>n;
	int t=1;
	a[0].h=a[0].w=1000000009;
	for(int i=1;i<=n;i++){
		cin>>a[i].w>>a[i].h;
		if(a[i].h<=a[i-1].h||a[i].w<=a[i-1].h)
		continue;
		else t=0;
	}
	if(t==1)
	cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <iostream>

int main() {
	int n;	// 1≤n≤10^5
	std::cin >> n;

	int w, h, pre = 1e9;	// 1≤w,h≤10^9
	while (n--) {
		std::cin >> w >> h;
		if (w > h)
			std::swap(w, h);

		if (h <= pre)
			pre = h;
		else if (w <= pre)
			pre = w;
		else {
			std::cout << "NO";
			return 0;
		}
	}

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


#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);

    int n;	// 1≤n≤10^5
	std::cin >> n;

	int w, h, pre = 1e9;	// 1≤w,h≤10^9
	while (n--) {
		std::cin >> w >> h;
		if (w > h)
			std::swap(w, h);
		if (w > pre) {
			std::cout << "NO";
			return 0;
		}

		if (h <= pre)
			pre = h;
		else
			pre = w;
	}

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


#include <iostream>

int main() {
	int n;	// 1≤n≤10^5
	std::cin >> n;

	std::pair<int, int> P[n];
	for (int i = 0, w, h; i < n; ++i) {	// 1≤w,h≤10^9
		std::cin >> w >> h;
		P[i] = std::make_pair(w, h);
	}

	if (P[0].first > P[0].second)
		std::swap(P[0].first, P[0].second);

	for (int i = 1; i < n; ++i)
		if (P[i].second > P[i - 1].second) {
			if (P[i].first > P[i - 1].second) {
				std::cout << "NO";
				return 0;
			} else
				std::swap(P[i].first, P[i].second);
		}

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


#include <iostream>

int main() {
	int n;	// 1≤n≤10^5
	std::cin >> n;

	int w, h, pre = 1e9;	// 1≤w,h≤10^9
	while (n--) {
		std::cin >> w >> h;
		if (h > pre) {
			if (w > pre) {
				std::cout << "NO";
				return 0;
			}
		} else if (h > w || w > pre) {
			pre = h;
			continue;
		}
		pre = w;
	}

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


#include <iostream>

int main() {
	int n;	// 1≤n≤10^5
	std::cin >> n;

	std::pair<int, int> P[n];
	for (int i = 0, w, h; i < n; ++i) {	// 1≤w,h≤10^9
		std::cin >> w >> h;
		if (w > h)
			P[i] = std::make_pair(h, w);
		else
			P[i] = std::make_pair(w, h);
	}

	for (int i = 1; i < n; ++i)
		if (P[i].second > P[i - 1].second) {
			if (P[i].first > P[i - 1].second) {
				std::cout << "NO";
				return 0;
			} else
				std::swap(P[i].first, P[i].second);
		}

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


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a[100010],b[100010],last;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if (b[i]<a[i]) swap(a[i],b[i]);
	}
	last=b[0];
	for (int i=1;i<n;i++){
		if (last<a[i]){
			cout<<"NO";
			return 0;
		}
		else if (last>=b[i])
			last=b[i];
		else if (last>=a[i])
			last=a[i];
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a[100010],b[100010],last;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if (b[i]<a[i]) swap(a[i],b[i]);
	}
	last=b[0];
	for (int i=1;i<n;i++){
		if (last<a[i]){
			cout<<"NO";
			return 0;
		}
		else if (last>b[i])
			last=b[i];
		else if (last>a[i])
			last=a[i];
	}
	cout<<"YES"<<endl;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a[100010],b[100010],f=1,ans=0;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if (b[i]<a[i]) swap(a[i],b[i]);
	}
	for (int i=1;i<n;i++){
		if (f==0){
			if (a[i]>a[i-1]) ans=-1;
			if (b[i]<=a[i-1]) f=1;
		}
		else{
			if (a[i]>b[i-1]) ans=-1;
			if (a[i]<=b[i-1]) f=0;
		}
	}
	if (ans!=-1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int n,a[100010],b[100010],f=1,ans=0;
int main(){
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if (b[i]<a[i]) swap(a[i],b[i]);
	}
	for (int i=1;i<n;i++){
		if (f==0){
			if (a[i]>a[i-1]) ans=-1;
			if (b[i]<=a[i-1]) f=1;
		}
		else{
			if (a[i]>b[i-1]) ans=-1;
			if (a[i]<=b[i-1]&&b[i]>b[i-1]) f=0;
		}
	}
	if (ans!=-1)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	return 0;
}


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

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define fin freopen("in.txt","r",stdin)

typedef long long ll;
const int maxn = 1e5+5;

struct node
{
	int x,y;
}a[maxn];
int main()
{
	IO;
	//fin;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int cnt = 0;
	for(int i=0;i<n-1;i++){
		if(a[i].x>=a[i+1].x || a[i].x>=a[i+1].y || a[i].y>=a[i+1].x || a[i].y>=a[i+1].y) cnt++;
	}
	if(cnt == n) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


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

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define fin freopen("in.txt","r",stdin)

typedef long long ll;
const int maxn = 1e5+5;

struct node
{
	int x,y;
}a[maxn];
int main()
{
	IO;
	//fin;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int cnt = 0;
	for(int i=0;i<n;i++){
		if(a[i].x>=a[i+1].x || a[i].x>=a[i+1].y || a[i].y>=a[i+1].x || a[i].y>=a[i+1].y) cnt++;
	}
	if(cnt == n) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


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

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define fin freopen("in.txt","r",stdin)

typedef long long ll;
const int maxn = 1e5+5;

struct node
{
	int x,y;
}a[maxn];
int main()
{
	IO;
	//fin;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int cnt = 0;
	for(int i=0;i<n-1;i++){
		if(a[i].x>=a[i+1].x || a[i].x>=a[i+1].y || a[i].y>=a[i+1].x || a[i].y>=a[i+1].y) cnt++;
	}
	if(cnt == n-1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


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

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define fin freopen("in.txt","r",stdin)

typedef long long ll;
const int maxn = 1e5+5;

struct node
{
	int x,y;
}a[maxn];
int main()
{
	IO;
	//fin;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int flag = 0;
	int tmp = max(a[0].x,a[0].y);
	for(int i=1;i<n;i++){
		 if(tmp>=max(a[i].x,a[i].y)) tmp = max(a[i].x,a[i].y);
		 else if(tmp>=min(a[i].x,a[i].y)) tmp = min(a[i].x,a[i].y);
		 else flag = 1;
	}
	if(!flag) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


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

#define IO ios_base::sync_with_stdio(0),cin.tie(0)
#define fin freopen("in.txt","r",stdin)

typedef long long ll;
const int maxn = 1e5+5;

struct node
{
	int x,y;
}a[maxn];
int main()
{
	IO;
	fin;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].x>>a[i].y;
	}
	int cnt = 0;
	for(int i=0;i<n-1;i++){
		if(a[i].x>=a[i+1].x || a[i].x>=a[i+1].y || a[i].y>=a[i+1].x || a[i].y>=a[i+1].y) cnt++;
	}
	if(cnt == n-1) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
long long w[60000],h[60000];
using namespace std;
int main()
{
	long long n,temp=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>h[i];
	}
	for(int i=0;i<n;i++)
	{
		if(w[i]>=w[i+1]||w[i]>=h[i+1]||h[i]>=w[i+1]||h[i]>=h[i+1])
			continue;
		else
		{
			cout<<"NO"<<endl;
			temp=1;
			break;
		}
	}
	if(temp!=1)
	cout<<"YES"<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
long long w[60000],h[60000];
using namespace std;
int main()
{
	long long n,temp=0,a,b,i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>h[i];
		if(temp==0)
		{
			a=max(w[i],h[i]);
			temp=1;
			continue;
		}
		if(temp==1)
		{
			b=min(w[i],h[i]);
			temp=0;
			if(a<b)
			{
				cout<<"NO";
				break;
			}
		}
	}
	if(i==n)
	cout<<"YES"<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
long long w[60000],h[60000];
using namespace std;
int main()
{
	long long n,temp=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		scanf("%lld,%lld",&w[i],&h[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(w[i]>=w[i+1]||w[i]>=h[i+1]||h[i]>=w[i+1]||h[i]>=h[i+1])
			continue;
		else
		{
			cout<<"NO"<<endl;
			temp=1;
			break;
		}
	}
	if(temp!=1)
	cout<<"YES"<<endl;
}


#include <iostream>
#include <string>
#include <algorithm>
long long w[60000],h[60000];
using namespace std;
int main()
{
	long long n,temp=0,a,b;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>w[i]>>h[i];
	}
	for(int i=0;i<n;i++)
	{
		a=max(w[i],h[i]);
		b=min(w[i+1],h[i+1]);
		if(a>=b)
			continue;
		else
		{
			cout<<"NO"<<endl;
			temp=1;
			break;
		}
	}
	if(temp!=1)
	cout<<"YES"<<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long n,temp=100000001,a,b,i,temp1=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(temp1==0)
		{
			temp=max(a,b);
			temp1=1;
			continue;
		}
		if(temp1==1)
		{
			if(temp<min(a,b))
			{
				printf("NO\n");
				break;
			}
			if(max(a,b)<=temp)
				temp=max(a,b);
			else if(min(a,b)<=temp)
				temp=min(a,b);
		}
	}
	if(i==n)
		printf("YES\n");
}


#include <iostream>
#include <string>
#include <algorithm>
long long w[60000],h[60000];
using namespace std;
int main()
{
	long long n,temp=0,a,b,i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>w[i]>>h[i];
		if(temp==0)
		{
			a=max(w[i],h[i]);
			temp=1;
			continue;
		}
		if(temp==1)
		{
			b=min(w[i],h[i]);
			if(a<b)
			{
				cout<<"NO";
				break;
			}
			temp=0;
		}
	}
	if(i==n)
	cout<<"YES"<<endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long n,temp=100000001,a,b,i,temp1=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(temp1==0)
		{
			temp=max(a,b);
			temp1=1;
			continue;
		}
		if(temp1==1)
		{
			if(temp<min(a,b))
			{
				printf("NO\n");
				break;
			}
			temp=max(a,b);
		}
	}
	if(i==n)
		printf("YES\n");
}


#include<bits/stdc++.h>
using namespace std;
int main(){
      long long c=0,i=0,j=0,n=0,ka=0,kb=0;
      cin>>n;
      int a[n],b[n];
      for(i=0;i<n;i++){
          cin>>a[i]>>b[i];
      }
      for(i=1;i<n;i++){
          ka=0;
          kb=0;
          if(a[i]<=a[i-1] || a[i]<=b[i-1]){
              ka=1;
          }
          if(b[i]<=a[i-1] || b[i]<=b[i-1]){
              kb=1;
          }
          if(ka==1 && kb==1){
              if(a[i]>b[i]){
                  b[i]=a[i];
                  continue;
              }else{
                  a[i]=b[i];
                  continue;
              }
          }
          if(ka==1){
              b[i]=a[i];
              continue;
          }
          if(kb==1){
          a[i]=b[i];
          continue;
          }
          cout<<"NO";
          return 0;
      }
    cout<<"YES";
}


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


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


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


#include <algorithm>
#include <stack>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
using namespace std;
typedef long long ll;
struct point
{
    ll x, y;
}a[100005];
int main()
{
    int n;
    ll k;
    scanf("%d", &n);
    for(int i = 1; i <= n ; i++)
    {
        scanf("%I64d %I64d", &a[i].x, &a[i].y);
    }
    k = 1000000000000;
    int flag = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i].x <= a[i].y && a[i].y <= k)
        {
            k = a[i].y;
        }
        else if(a[i].x <= a[i].y && a[i].x <= k)
        {
            k = a[i].x;
        }
        else
        {
            flag = 1;
        }
    }
    if(flag)
        puts("NO");
    else
        puts("YES");

}


#include <algorithm>
#include <stack>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
using namespace std;
typedef long long ll;
struct point
{
    ll x, y;
}a[100005];
int main()
{
    int n;
    ll k;
    scanf("%d", &n);
    for(int i = 1; i <= n ; i++)
    {
        scanf("%I64d %I64d", &a[i].x, &a[i].y);
    }
    k = 1000000000000;
    int flag = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i].x < a[i].y && a[i].y <= k)
        {
            k = a[i].y;
        }
        else if(a[i].x < a[i].y && a[i].x <= k)
        {
            k = a[i].x;
        }
        else
        {
            flag = 1;
        }
    }
    if(flag)
        puts("NO");
    else
        puts("YES");

}


#include <algorithm>
#include <stack>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
using namespace std;
typedef long long ll;
struct point
{
    ll x, y;
}a[100005];
int main()
{
    int n;
    ll k;
    scanf("%d", &n);
    for(int i = 1; i <= n ; i++)
    {
        scanf("%I64d %I64d", &a[i].x, &a[i].y);
    }
    k = 1000000000000;
    int flag = 0;
    for(int i = 1; i <= n; i++)
    {
        if(a[i].x <= a[i].y && a[i].y <= k)
        {
            k = a[i].y;
        }
        else if(a[i].x <= a[i].y && a[i].x <= k)
        {
            k = a[i].x;
        }
        else
        {
            flag = 1;
            break;
        }
    }
    if(flag)
        puts("NO");
    else
        puts("YES");

}


#include <algorithm>
#include <stack>
#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
using namespace std;
typedef long long ll;
struct point
{
    ll x, y;
} a[100005];
int main()
{
    int n;
    ll k;
    scanf("%d", &n);
    for(int i = 0; i < n ; i++)
    {
        scanf("%I64d %I64d", &a[i].x, &a[i].y);
    }
    int temp = max(a[0].x, a[0].y);
    for(int i = 1; i < n; i++)
    {
        if(temp >= max(a[i].x, a[i].y))
        {
            temp = max(a[i].x, a[i].y);
        }
        else if (temp >= min(a[i].x, a[i].y))
        {
            temp=min(a[i].x, a[i].y);
        }

        else
        {
            printf("NO");
            return 0;

        }
    }
    puts("YES");
}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n;
float w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(n-1)==true)
        cout<<"YES";

    if (Generate(n-1)==false)
        cout<<"NO";
}


#include<iostream>
#include<stdio.h>
using namespace std;
int n;
long long int w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[k-1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
    {
       cout<<"YES";
        return 0;
    }

    if (Generate(2)==false)
    {
       cout<<"NO";
        return 0;
    }
}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n;
float w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

for (int i=1;i<=n;i++)
    if (Generate(n-1)==true)
        cout<<"YES";

    if (Generate(n-1)==false)
        cout<<"NO";
}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n,w[10000],h[10000],value[10000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(n-1)==true)
        cout<<"YES";

    if (Generate(n-1)==false)
        cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int w[100000],h[100000],value[100000];
int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
   value[0]=10*10*10*10*10*10*10*10*10*2;
  for (int i=1;i<=n;i++)
  {
      cin>>w[i]>>h[i];
      if (min(w[i],h[i])>value[i-1]) { cout<<"NO"; return 0;}
      if (max(w[i],h[i])<=value[i-1]) {value[i]=max(w[i],h[i]);}
      else if (w[i]<=value[i-1])  {value[i]=w[i];}
      else if (h[i]<=value[i-1])  {value[i]=h[i];}
  }
   cout<<"YES"; return 0;

}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n;
float w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
        cout<<"YES";

    if (Generate(2)==false)
        cout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int n;
long long int w[100000],h[100000],value[100000];
int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
   value[0]=10*10*10*10*10*10*10*10*10*2;
  for (int i=1;i<=n;i++)
  {
      cin>>w[i]>>h[i];
      if (min(w[i],h[i])>value[i-1]) { cout<<"NO"; return 0;}
      if (max(w[i],h[i])<=value[i-1]) {value[i]=max(w[i],h[i]);}
      else if (w[i]<=value[i-1])  {value[i]=w[i];}
      else if (h[i]<=value[i-1])  {value[i]=h[i];}
  }
   cout<<"YES";

}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n;
float w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    fin>>n;
    for (int i=1;i<=n;i++)
        fin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);
cout<<h[1];
for (int i=1;i<=n;i++)
    if (Generate(n-1)==true)
        fout<<"YES";

    if (Generate(n-1)==false)
        fout<<"NO";
}


#include<iostream>
using namespace std;
int n,w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[k-1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
  ios::sync_with_stdio(false);
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
        cout<<"YES";

    if (Generate(2)==false)
        cout<<"NO";
}


#include<iostream>
using namespace std;
int n,w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
  ios::sync_with_stdio(false);
    cin>>n;
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
        cout<<"YES";

    if (Generate(2)==false)
        cout<<"NO";
}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n,w[10000],h[10000],value[10000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    fin>>n;
    for (int i=1;i<=n;i++)
        fin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(n-1)==true)
        fout<<"YES";

    if (Generate(n-1)==false)
        fout<<"NO";
}


#include<bits/stdc++.h>
using namespace std;
int n,w[100000],h[100000],value[100000];
int main()
{
  ios::sync_with_stdio(false);
  cin>>n;
   value[0]=10*10*10*10*10*10*10*10*10*2;
  for (int i=1;i<=n;i++)
  {
      cin>>w[i]>>h[i];
      if (min(w[i],h[i])>value[i-1]) { cout<<"NO"; return 0;}
      if (max(w[i],h[i])<=value[i-1]) {value[i]=max(w[i],h[i]);}
      else if (w[i]<=value[i-1])  {value[i]=w[i];}
      else if (h[i]<=value[i-1])  {value[i]=h[i];}
  }
   cout<<"YES";

}


#include<bits/stdc++.h>
using namespace std;
int n,a,b,i,p=2e9;
int main(){
	for(cin>>n;i<n;i++){
		cin>>a>>b;
		if(max(a,b)<=p)p=max(a,b);
		else if(a<=p)p=a;
		else if(b<=p)p=b;
		else return cout<<"NO",0;
	}
	cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
int n,w[100000],h[100000],value[100000];
int main()
{
  ios::sync_with_stdio(false);
  scanf("%u",&n);
  cin>>w[1]>>h[1]; value[1]=max(w[1],h[1]);
  for (int i=2;i<=n;i++)
  {
      cin>>w[i]>>h[i];
      if (min(w[i],h[i])>=value[i-1]) { cout<<"NO"; return 0;}
      if (max(w[i],h[i])<=value[i-1]) {value[i]=max(w[i],h[i]);}
      else if (w[i]<=value[i-1])  {value[i]=w[i];}
      else if (h[i]<=value[i-1])  {value[i]=h[i];}
  }
   cout<<"YES";

}


#include<iostream>
#include<stdio.h>
using namespace std;
int n;
long long int w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[k-1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
  ios::sync_with_stdio(false);
scanf("%d",&n);
    for (int i=1;i<=n;i++)
        cin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
    {
        printf("YES\n");
        return 0;
    }

    if (Generate(2)==false)
    {
        printf("NO\n");
        return 0;
    }
}


#include<iostream>
#include<stdio.h>
#include<conio.h>
using namespace std;
int n;
long long int w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[k-1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
  ios::sync_with_stdio(false);
  scanf("%u",&n);
    for (int i=1;i<=n;i++)
        {
            scanf("%u",&w[i]);
            scanf("%u",&h[i]);
        }

        value[1]=max(w[1],h[1]);

    if (Generate(2)==true)
    {
       cout<<"YES";
        return 0;
    }

    if (Generate(2)==false)
    {
       cout<<"NO";
        return 0;
    }
}


#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
int n,w[100000],h[100000],value[100000];
bool Generate(int k)
{
    if (k==n)
    {
      if (min(w[k],h[k])>value[1])
        return false;

      else
        return true;
    }

   if (min(w[k],h[k])>value[k-1])
     return false;

   else
   {
       if (max(w[k],h[k])<=value[k-1])
       {
           value[k]=max(w[k],h[k]);
           Generate(k+1);
       }
       else
       {
           value[k]=min(w[k],h[k]);
           Generate(k+1);
       }
   }
}

int main()
{
    fin>>n;
    for (int i=1;i<=n;i++)
        fin>>w[i]>>h[i];

        value[1]=max(w[1],h[1]);

    if (Generate(n-1)==true)
        fout<<"YES";

    if (Generate(n-1)==false)
        fout<<"NO";
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  for(int i=1;i<n;i++)
  {
    if(w[i]>h[i]&&w[i]<h[i-1])
    swap(w[i],h[i]);
    else if(h[i]>h[i-1])
    return !~printf("NO");
  }
  printf("YES");
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  //cout<<h[0]<<w[0]<<endl;
  for(int i=1;i<n;i++)
  {

    if(w[i]>h[i]&&w[i]<h[i-1])
   swap(w[i],h[i]);
    //cout<<h[i]<<w[i]<<endl;}
    else if(h[i]>h[i-1]&&w[i]<=h[i-1])
    swap(h[i],w[i]);
    else if(h[i]<=h[i-1])
    continue;
    else
    {return !printf("NO");}
  }
  printf("YES");
}


#include<iostream>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  int flag=1;
  for(int i=0;i<n;i++)
  {cin>>w[i]>>h[i];}
  if(n==1)
  return !printf("YES");
  if(h[0]<h[1]&&h[0]<w[1])
  return !printf("NO");

  for(int i=1;i<n-1;i++)
  {
    if(w[i]>h[i]&&w[i]<h[i-1])
    swap(h[i],w[i]);
    if(h[i]<h[i+1]&&h[i]<w[i+1])
    {
      if(w[i]<h[i+1]&&w[i]<w[i+1])
      return !printf("NO");
      else if(w[i]>h[i-1])
      return !printf("NO");
      else {if(w[i]<h[i+1])swap(w[i+1],h[i+1]); swap(w[i],h[i]);}
    }
    else if(h[i]<h[i+1])
    swap(h[i+1],w[i+1]);

  }
  cout<<"YES";
}


#include<iostream>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  int flag=1;
  for(int i=0;i<n;i++)
  {cin>>w[i]>>h[i];}
  if(n==1)
  return !printf("YES");
  if(h[0]<h[1]&&h[0]<w[1])
  return !printf("NO");

  for(int i=1;i<n-1;i++)
  {
    if(h[i]<h[i+1]&&h[i]<w[i+1])
    {
      if(w[i]<h[i+1]&&w[i]<w[i+1])
      return !printf("NO");
      else if(w[i]>h[i-1])
      return !printf("NO");
      else {if(w[i]<h[i+1])swap(w[i+1],h[i+1]); swap(w[i],h[i]);}
    }
    else if(h[i]<h[i+1])
    swap(h[i+1],w[i+1]);

  }
  cout<<"YES";
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  cout<<h[0]<<w[0]<<endl;
  for(int i=1;i<n;i++)
  {

    if(w[i]>h[i]&&w[i]<h[i-1])
   { swap(w[i],h[i]);
    cout<<h[i]<<w[i]<<endl;}
    else if(h[i]>h[i-1]&&w[i]<=h[i-1])
    swap(h[i],w[i]);
    else if(h[i]<h[i-1])
    continue;
    else
    {return !printf("NO%d",i);}
  }
  printf("YES");
}


#include<iostream>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  int flag=1;
  for(int i=0;i<n;i++)
  {cin>>w[i]>>h[i];}
  if(n==1)
  return !printf("YES");
  if(h[0]<h[1]&&h[0]<w[1])
  return !printf("NO");
  if(h[0]<w[0])
  swap(h[0],w[0]);

  for(int i=1;i<n-1;i++)
  {
    if(w[i]>h[i]&&w[i]<h[i-1])
    swap(h[i],w[i]);
    if(h[i]<h[i+1]&&h[i]<w[i+1])
    {

      return !printf("NO");
    }
    else if(h[i]<h[i+1])
    swap(h[i+1],w[i+1]);

  }
  cout<<"YES";
}


#include<iostream>
using namespace std;

int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  int flag=1;
  for(int i=0;i<n;i++)
  {cin>>w[i]>>h[i];}
  if(n==1)
  return !printf("YES");
  if(h[0]<h[1]&&h[0]<w[1]&&w[0]<h[1]&&w[0]<w[1])
  return !printf("NO");
  if(h[0]<w[0])
  swap(h[0],w[0]);

  for(int i=1;i<n-1;i++)
  {
    if(w[i]>h[i]&&w[i]<h[i-1])
    swap(h[i],w[i]);
    if(h[i]<h[i+1]&&h[i]<w[i+1])
    {
     return !printf("NO");
    }
    else if(h[i]<h[i+1])
    swap(h[i+1],w[i+1]);

  }
  cout<<"YES";
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  //cout<<h[0]<<w[0]<<endl;
  for(int i=1;i<n;i++)
  {

    if(w[i]>h[i]&&w[i]<h[i-1])
   swap(w[i],h[i]);
    //cout<<h[i]<<w[i]<<endl;}
    else if(h[i]>h[i-1]&&w[i]<=h[i-1])
    swap(h[i],w[i]);
    else if(h[i]<h[i-1])
    continue;
    else
    {return !printf("NO%d",i);}
  }
  printf("YES");
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  //cout<<h[0]<<w[0]<<endl;
  for(int i=1;i<n;i++)
  {

    if(w[i]>h[i]&&w[i]<=h[i-1])
   swap(w[i],h[i]);
    //cout<<h[i]<<w[i]<<endl;}
    else if(h[i]>h[i-1]&&w[i]<=h[i-1])
    swap(h[i],w[i]);
    else if(h[i]<=h[i-1])
    continue;
    else
    {return !printf("NO");}
  }
  printf("YES");
}


#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int w[n],h[n];
  for(int i=0;i<n;i++)
  cin>>w[i]>>h[i];
  if(w[0]>h[0])
  swap(w[0],h[0]);
  //cout<<h[0]<<w[0]<<endl;
  for(int i=1;i<n;i++)
  {

    if(w[i]>h[i]&&w[i]<h[i-1])
   swap(w[i],h[i]);
    //cout<<h[i]<<w[i]<<endl;}
    else if(h[i]>h[i-1]&&w[i]<=h[i-1])
    swap(h[i],w[i]);
    else if(h[i]<h[i-1])
    continue;
    else
    {return !printf("NO");}
  }
  printf("YES");
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll m=a[0][0];
    if(a[0][1]>m)
    m=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][0]<=m)
        {
            m=a[i][0];
        }
        else if(a[i][1]<=m)
        m=a[i][1];
        else if(a[i][0]<=m && a[i][1]<=m)
        {
            m=a[i][0];
            if(a[i][1]>m)
            m=a[i][1];
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    for(int i=0;i<n-1;i++)
    {
        if(a[i][0]>=a[i+1][0])
        continue;
        else if(a[i][1]>=a[i+1][0])
        {
            swap(a[i][0],a[i][1]);
        }
        else if(a[i][0]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
        }
        else if(a[i][1]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
            swap(a[i][0],a[i][1]);
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    for(int i=0;i<n-1;i++)
    {
        if(a[i][0]>=a[i+1][1])
        continue;
        else if(a[i][0]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
        }
        else if(a[i][1]>=a[i+1][0])
        {
            swap(a[i][0],a[i][1]);
        }
        else if(a[i][1]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
            swap(a[i][0],a[i][1]);
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll m=a[0][0];
    if(a[0][1]>m)
    m=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][0]<=m && a[i][1]>=m)
        {
            m=a[i][0];
        }
        else if(a[i][0]>=m && a[i][1]<=m)
        m=a[i][1];
        else if(a[i][0]<=m && a[i][1]<=m)
        {
            m=a[i][0];
            if(a[i][1]>m)
            m=a[i][1];
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    for(int i=0;i<n-1;i++)
    {
        if(a[i][0]>=a[i+1][1])
        continue;
        else if(a[i][1]>=a[i+1][0])
        {
            swap(a[i][0],a[i][1]);
        }
        else if(a[i][0]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
        }
        else if(a[i][1]>=a[i+1][1])
        {
            swap(a[i+1][0],a[i+1][1]);
            swap(a[i][0],a[i][1]);
        }
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mod 1000000007
#define length 100001
#define max LONG_MAX
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MS(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(),x.end()
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll a[n][2];
    for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1];
    if(n==1)
    {
        cout<<"YES";
        return 0;
    }
    ll m=a[0][0];
    if(a[0][1]>m)
    m=a[0][1];
    for(int i=1;i<n;i++)
    {
        if(a[i][0]<=m && a[i][1]<=m)
        {
            m=a[i][0];
            if(a[i][1]>m)
            m=a[i][1];
        }
        else if(a[i][0]<=m)
        {
            m=a[i][0];
        }
        else if(a[i][1]<=m)
        m=a[i][1];
        else
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ivect vector<int>
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" "; cout<<endl;
#define f first
#define s second
// v.size(); sort(all(v)); for reverse-v.rbegin()
int main()
{
 	cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],b[n];
   F(i,n)
   cin>>a[i]>>b[i];
   ll flag=0;

   F(i,n-1)
   {
   	if(max(a[i],b[i])>=min(a[i+1],b[i+1]))
   	{
   		flag++;
	   }
   }
   if(flag==n-1)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ivect vector<int>
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" "; cout<<endl;
#define f first
#define s second
// v.size(); sort(all(v)); for reverse-v.rbegin()
int main()
{
 	cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],b[n];
   F(i,n)
   cin>>a[i]>>b[i];
   ll flag=0;
   F(i,n-1)
   {
   	if(max(a[i],b[i])>max(a[i+1],b[i+1]))
   	{
   		flag=1; break;
	   }
   }
   if(flag)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F(i,n) for(int i=0;i<n;i++)
#define F1(x,i,n) for(int i=x;i<n;i++)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define a(n) vector<ll> a(n)
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" "; cout<<endl;
#define f first
#define s second
// v.size(); sort(all(v)); for reverse-v.rbegin()
int main()
{
 	cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n;
     cin>>n;
     ll a[n],b[n],flag=0;
     F(i,n)
     cin>>a[i]>>b[i];
     ll maxx = max(a[0],b[0]);
     F1(1,i,n)
     {
     	if(maxx>=max(a[i],b[i]))
     	maxx=max(a[i],b[i]);
     	else if(maxx>=min(a[i],b[i]))
     	maxx = min(a[i],b[i]);
     	else{
     		flag=1;break;
		 }
	 }
	 if(flag)
	 cout<<"NO";
	 else
	 cout<<"YES";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ivect vector<int>
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" "; cout<<endl;
#define f first
#define s second
// v.size(); sort(all(v)); for reverse-v.rbegin()
int main()
{
 	cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],b[n];
   F(i,n)
   cin>>a[i]>>b[i];
   ll flag=0;
   F(i,n-1)
   {
   	if(max(a[i],b[i])>=min(a[i+1],b[i+1]))
   	{
   		flag=1; break;
	   }
   }
   if(flag)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define F(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define ivect vector<int>
#define mem(x,val) memset(x,val,sizeof(x))
#define mod 1000000007
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" "; cout<<endl;
#define f first
#define s second
// v.size(); sort(all(v)); for reverse-v.rbegin()
int main()
{
 	cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],b[n];
   F(i,n)
   cin>>a[i]>>b[i];
   ll flag=0;
   F(i,n-1)
   {
   	if(max(a[i],b[i])>min(a[i+1],b[i+1]))
   	{
   		flag=1; break;
	   }
   }
   if(flag)
   cout<<"YES"<<endl;
   else
   cout<<"NO"<<endl;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1e9+7;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n)
{
 ll r,p;
	p=1;
	ll m=mod;
	 b=b%m;
	while(n>0)
	{
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m;
		n=n/2;
	}
 return (p%m);
}
ll w[1000002];
ll h[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,v1,v2;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i]>>h[i];
	}
	ll valid1=1;
	ll valid2=1;
	for (int i = 0; i < n-1; ++i)
	{
		v1=0;
		v2=0;
		if (valid1==1)
		{
			if (h[i]>=h[i+1])
			{
				v1=1;
			}
			if (h[i]>=w[i+1])
			{
				v2=1;
			}
		}
		else if (valid2==1)
		{
			if (w[i]>=h[i+1])
			{
				v1=1;
			}
			if (w[i]>=w[i+1])
			{
				v2=1;
			}
		}
		valid1=v1;
		valid2=v2;
		if (valid1==0&&valid2==0)
		{
			cout<<"no"<<"\n";
			return 0;
		}
	}
cout<<"yes"<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1e9+7;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n)
{
 ll r,p;
	p=1;
	ll m=mod;
	 b=b%m;
	while(n>0)
	{
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m;
		n=n/2;
	}
 return (p%m);
}
ll w[1000002];
ll h[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,v1,v2;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i]>>h[i];
	}
	ll valid1=1;
	ll valid2=1;
	for (int i = 0; i < n-1; ++i)
	{
		v1=0;
		v2=0;
		if (valid1==1)
		{
			if (h[i]>=h[i+1])
			{
				v1=1;
			}
			if (h[i]>=w[i+1])
			{
				v2=1;
			}
		}
		if (valid2==1)
		{
			if (w[i]>=h[i+1])
			{
				v1=1;
			}
			if (w[i]>=w[i+1])
			{
				v2=1;
			}
		}
		valid1=v1;
		valid2=v2;
		if (valid1==0&&valid2==0)
		{
			cout<<"no"<<"\n";
			return 0;
		}
	}
cout<<"yes"<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1e9+7;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n)
{
 ll r,p;
	p=1;
	ll m=mod;
	 b=b%m;
	while(n>0)
	{
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m;
		n=n/2;
	}
 return (p%m);
}
ll w[1000002];
ll h[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,v1,v2;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i]>>h[i];
	}
	ll valid1=1;
	ll valid2=1;
	for (int i = 0; i < n-1; ++i)
	{
		v1=0;
		v2=0;
		if (valid1==1)
		{
			if (h[i]>=h[i+1])
			{
				v1=1;
			}
			if (h[i]>=w[i+1])
			{
				v2=1;
			}
		}
		else if (valid2==1)
		{
			if (w[i]>=h[i+1])
			{
				v1=1;
			}
			if (w[i]>=w[i+1])
			{
				v2=1;
			}
		}
		else
		{
			cout<<"no"<<"\n";
			return 0;
		}
		valid1=v1;
		valid2=v2;
	}
cout<<"yes"<<"\n";
	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1e9+7;
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
vector<ll>adj[1000005];
ll expo(ll b,ll n)
{
 ll r,p;
	p=1;
	ll m=mod;
	 b=b%m;
	while(n>0)
	{
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m;
		n=n/2;
	}
 return (p%m);
}
ll w[1000002];
ll h[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n,v1,v2;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>w[i]>>h[i];
	}
	ll valid1=1;
	ll valid2=1;
	for (int i = 0; i < n-1; ++i)
	{
		v1=0;
		v2=0;
		if (valid1==1)
		{
			if (h[i]>=h[i+1])
			{
				v1=1;
			}
			if (h[i]>=w[i+1])
			{
				v2=1;
			}
		}
		else if (valid2==1)
		{
			if (w[i]>=h[i+1])
			{
				v1=1;
			}
			if (w[i]>=w[i+1])
			{
				v2=1;
			}
		}
		else
		{
			cout<<"no"<<"\n";
			return 0;
		}
		valid1=v1;
		valid2=v2;
		if (valid1==0&&valid2==0)
		{
			cout<<"no"<<"\n";
			return 0;
		}
	}
cout<<"yes"<<"\n";
	return 0;
}


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

int main()
{
  int N; cin >> N;
  vector<pair<int,int> > v;
  while (N--) {
    int x, y; cin >> x >> y;
    v.push_back({x, y});
  }
  if (v[0].first < v[0].second) {
    swap(v[0].first, v[0].second);
  }
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].first < v[i].second) {
      swap(v[i].first, v[i].second);
    }
    if (v[i].first > v[i-1].first) {
      swap(v[i].first, v[i].second);
    }
    if (v[i].first > v[i-1].first) {
      cout << "NO\n"; return 0;
    }
  }
  cout << "YES\n";
}


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

int main()
{
  int N; cin >> N;
  vector<pair<int,int> > v;
  while (N--) {
    int x, y; cin >> x >> y;
    v.push_back({x, y});
  }
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].first > v[i-1].first && v[i].first > v[i-1].second) {
      swap(v[i].first, v[i].second);
    }
    if (v[i].first > v[i-1].first && v[i].first > v[i-1].second) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}


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

int main()
{
  int N; cin >> N;
  vector<pair<int,int> > v;
  while (N--) {
    int x, y; cin >> x >> y;
    v.push_back({x, y});
  }
  for (int i = 1; i < v.size(); ++i) {
    if (v[i].first > v[i-1].first && v[i].first > v[i-1].second) {
      swap(v[i-1].first, v[i-1].second);
    }
    if (v[i].first > v[i-1].first && v[i].first > v[i-1].second) {
      swap(v[i].first, v[i].second);
    }
    if (v[i].first > v[i-1].first && v[i].first > v[i-1].second) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}


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

int main()
{
  int N; cin >> N;
  vector<pair<int,int> > v;
  while (N--) {
    int x, y; cin >> x >> y;
    v.push_back({x, y});
  }
  for (int i = 1; i < v.size(); ++i) {
    if (v[i-1].first > v[i-1].second) {
      swap(v[i-1].first, v[i-1].second);
    }
    if (v[i].first > v[i].second) {
      swap(v[i].first, v[i].second);
    }
    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].second);
    }
    if (v[i].first > v[i-1].first) {
      cout << "NO\n"; return 0;
    }
  }
  cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int>mp;
int main()
{
   ll n,cnt=1;
   cin>>n;
   int p,q;
   cin>>p>>q;
   ll mx=max(p,q);
   ll pre,mn=10000005,post=0;
   for(int i=1;i<n;i++)
   {
       ll x,y;
       cin>>x>>y;
       pre=mx;
       mx=max(x,y);
       mn=min(x,y);
       if(mx<=pre)
       {
           cnt++;
           pre=mx;
       }
       else if(mx>pre)
       {
           if(mn<=pre)
           {
               cnt++;
           }
           else
           {
               post=1;
               break;
           }

       }

   }
   if(post==0)
    cout<<"YES"<<endl;
   else if(post==1)
    cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int>mp;
int main()
{
   ll n,cnt=1;
   cin>>n;
   int p,q;
   cin>>p>>q;
   ll mx=max(p,q);
   ll pre,mn=10000005,post=0;
   for(int i=1;i<n;i++)
   {
       ll x,y;
       cin>>x>>y;
       pre=mx;
       mx=max(x,y);
       mn=min(x,y);
       if(mx<=pre)
       {
           cnt++;
           pre=mx;
       }
       else if(mx>pre)
       {
           if(mn<=pre)
           {
               pre=mn;
               cnt++;
           }
           else
           {
               post=1;
               break;
           }

       }

   }
   if(post==0)
    cout<<"YES"<<endl;
   else if(post==1)
    cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int>mp;
int main()
{
   ll n,cnt=1;
   cin>>n;
   int p,q;
   cin>>p>>q;
   ll mx=max(p,q);
   ll pre,mn=10000005,post=0;
   for(int i=1;i<n;i++)
   {
       ll x,y;
       cin>>x>>y;
       pre=mx;
       mx=max(x,y);
       mn=min(x,y);
       if(mx<=pre)
       {
           cnt++;
           pre=mx;
       }
       else if(mx>pre)
       {
           if(mn<=pre)
           {
               pre=mx;
               cnt++;
           }
           else
           {
               post=1;
               break;
           }

       }

   }
   if(post==0)
    cout<<"YES"<<endl;
   else if(post==1)
    cout<<"NO"<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<string,int>mp;
int main()
{
   ll n,cnt=1;
   cin>>n;
   int p,q;
   cin>>p>>q;
   ll mx=max(p,q);
   ll pre,mn=10000005,post=0;
   pre=mx;
   for(int i=1;i<n;i++)
   {
       ll x,y;
       cin>>x>>y;
      // pre=mx;
       mx=max(x,y);
       mn=min(x,y);
       if(mx<=pre)
       {
           cnt++;
           pre=mx;
       }
       else if(mx>pre)
       {
           if(mn<=pre)
           {
               pre=mn;
               cnt++;
           }
           else
           {
               post=1;
               break;
           }

       }

   }
   if(post==0)
    cout<<"YES"<<endl;
   else if(post==1)
    cout<<"NO"<<endl;
}


#include<iostream>
using namespace std;
int main()
{
	int T;
	int chang[10005],kuan[10005];
	int i,flag;
	while(cin>>T)
	{
		flag=0;
		for(i=0;i<T;i++)
		{
		cin>>chang[i]>>kuan[i];
		if(kuan[i]>chang[i])
			flag++;
		}
		if(flag==T)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int T;
  int chang[10005],kuan[10005];
	int i,flag;
	while(cin>>T)
	{
		flag=0;
		for(i=0;i<T;i++)
		{
		cin>>chang[i]>>kuan[i];
		if(kuan[i]!=chang[i])
			flag++;
		}
		if(flag==T)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


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


#include<iostream>
using namespace std;
int main()
{
	int T;
	long long  chang[10005],kuan[10005];
	int i,flag;
	while(cin>>T)
	{
		flag=0;
		for(i=0;i<T;i++)
		{
		cin>>chang[i]>>kuan[i];
		if(kuan[i]>chang[i])
			flag++;
		}
		if(flag==T)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main (){
    int n,i,j;
    cin>>n;
    long long w[n],h[n];
    cin>>w[0]>>h[0];
    for (i=1;i<n;i++){
        cin>>w[i]>>h[i];
        if (w[i]>w[i-1] && w[i]>h[i-1] && h[i]>h[i-1] && h[i]>w[i-1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
}


#include<iostream>
using namespace std;
int main (){
    int n,c=0;
    cin>>n;
    int w[n],h[n];
    cin>>w[1]>>h[1];
    if(w[1]>h[1])
        h[1]=w[1];
    for(int i=2;i<=n;i++){
        cin>>w[i]>>h[i];
        if(w[i]>h[i] && w[i]<=h[i-1])
            h[i]=w[i];
        else if(h[i]>h[i-1] && w[i]<=h[i-1])
            h[i]=w[i];
        else if(h[i]>h[i-1])
            c=1;
    }
    if(c==0)cout<<"YES";
    else cout<<"NO";
    return 0;
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)!=s.charAt(i-1))continue;
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());break;}   }}
}System.out.println(s);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";
char c[]=s.toCharArray();

for(int i=1;i<s.length()-1;i++)
{if(c[i]!=c[i-1])continue;
for(char ch='a';ch<='z';ch++)
{if(c[i+1]!=ch&&c[i-1]!=ch)
{c[i]=ch;break;}   }}
System.out.println(c);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)==s.charAt(i-1)){
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());break;}   }}
}}System.out.println(s.substring(0,s.length()-1));
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i-1)!=s.charAt(i+1))continue;
for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());
break;}   }}
System.out.println(s);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";String t="";
for(char ch='a';ch<='z';ch++)
{if(s.indexOf(ch)!=-1)
    t=t+ch;}
for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)==s.charAt(i-1)){
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());break;}   }}
}}System.out.println(s.substring(0,s.length()-1));
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i-1)!=s.charAt(i))continue;
for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());
break;}   }}
System.out.println(s);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";
char c[]=s.toCharArray();

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)!=s.charAt(i-1))continue;
for(char ch='a';ch<='z';ch++)
{if(c[i+1]!=ch&&c[i-1]!=ch)
{c[i]=ch;break;}   }}
System.out.println(c);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i-1)!=s.charAt(i+1))continue;
for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i+1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());
break;}   }}
System.out.println(s);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)!=s.charAt(i-1))continue;
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());break;}   }}
}System.out.println(s.substring(0,s.length()-1));
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";
char c[]=s.toCharArray();

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)!=s.charAt(i-1))continue;
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{c[i]=ch;break;}   }}
}System.out.println(s);
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";String t="";int c=0;
for(char ch='a';ch<='z';ch++)
{if(s.indexOf(ch)!=-1)
    t=t+ch;}
for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i)==s.charAt(i-1)){c=0;
for(int j=0;j<t.length();j++)
{if(s.charAt(i-1)!=t.charAt(j)&&s.charAt(i+1)!=t.charAt(j))
{s=s.substring(0,i)+t.charAt(j)+s.substring(i+1,s.length());c=1;}}
if(c!=1)
{for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i-1)!=ch)
{s=s.substring(0,i)+ch+s.substring(i+1,s.length());break;}   }}
}}System.out.println(s.substring(0,s.length()-1));
}}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.*;

/**
 *
 * @author PRAVEEN KUMAR SINGH
 */
public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
 public static void main(String args[])
{Scanner br=new Scanner(System.in);
String s=br.next();
s=s+" ";

for(int i=1;i<s.length()-1;i++)
{if(s.charAt(i-1)!=s.charAt(i+1))continue;
for(char ch='a';ch<='z';ch++)
{if(s.charAt(i+1)!=ch&&s.charAt(i+1)!=ch)
{s=s.substring(0,i)+s.substring(i+1,s.length());
break;}   }}
System.out.println(s);
}}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        for (int i = 0; i < s.length() - 2; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                if (s.charAt(i) != 'a' && s.charAt(i + 2) != 'a') {
                    s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                } else if (s.charAt(i) != 'b' && s.charAt(i + 2) != 'b') {
                    s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                } else {
                    s = s.substring(0, i + 1) + "c" + s.substring(i + 2);
                }
                i++;
            }
        }
        System.out.println(s);
    }

}


import java.io.PrintWriter;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String s = sc.nextLine();

        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                if (i + 2 < s.length()) {
                    if (s.charAt(i) == s.charAt(i + 2)) {
                        if (s.charAt(i) == 'a') {
                            s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                        } else {
                            s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                        }
                    }
                    i++;
                } else {
                    if (s.charAt(i) == 'a') {
                        s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                    } else {
                        s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                    }
                }
            }
        }
        out.println(s);
        out.flush();
    }
}


import java.io.PrintWriter;
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String s = sc.nextLine();

        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                if (i + 2 < s.length()) {
                    if (s.charAt(i) != 'a' && s.charAt(i + 2) != 'a') {
//                        s.substring(i+1, i+2) = "a";
                        s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                    } else if (s.charAt(i) != 'b' && s.charAt(i + 2) != 'b') {
                        s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                    } else {
                        s = s.substring(0, i + 1) + "c" + s.substring(i + 2);
                    }
                    i++;
                } else {
                    if (s.charAt(i) == 'a') {
                        s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                    } else {
                        s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                    }
                }
            }
        }
        out.println(s);
        out.flush();
    }
}


import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
         Scanner in = new Scanner(System.in);
         System.out.println(replace(in.nextLine()));
    }

    public static String replace(String input){
        StringBuffer sb = new StringBuffer(input);
        int len = sb.length();
        if (len == 1) {
            return sb.toString();
        }
        if (len == 2) {
            if (sb.charAt(0) == sb.charAt(1)) {
                replace(sb, 1, len, sb.charAt(0));
            }
            return sb.toString();
        }
        for (int i = 1; i < len; i++) {
            if (sb.charAt(i) == sb.charAt(i-1)) {
                replace(sb, i ,len, sb.charAt(i-1));
            }
        }
        return sb.toString();
    }

    static void replace(StringBuffer sb, int index, int len, char leftCh){
        char ch = (index == len-1)? sb.charAt(index-1) : sb.charAt(index + 1);
        char newCh = 'a';
        while(newCh == ch || newCh == leftCh)
            newCh++;
        sb.replace(index, index+1, String.valueOf(newCh));
    }

}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Quan
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();

        for (int i = 0; i < s.length() - 1; i++) {
            if (s.charAt(i) == s.charAt(i + 1)) {
                if (i + 2 < s.length()) {
                    if (s.charAt(i) != 'a' && s.charAt(i + 2) != 'a') {
                        s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                    } else if (s.charAt(i) != 'b' && s.charAt(i + 2) != 'b') {
                        s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                    } else {
                        s = s.substring(0, i + 1) + "c" + s.substring(i + 2);
                    }
                    i++;
                } else {
                    if (s.charAt(i) == 'a') {
                        s = s.substring(0, i + 1) + "b" + s.substring(i + 2);
                    } else {
                        s = s.substring(0, i + 1) + "a" + s.substring(i + 2);
                    }
                }
            }
        }
        System.out.println(s);
    }
}


import java.io.*;
import java.math.*;
import java.util.*;
public class name
{
       public static void main(String[]args)
       {
              Scanner sc=new Scanner(System.in);
              String s;
              char ss[];
              int i,j;
              s=sc.next();
              ss=s.toCharArray();
              l=s.length();
              for(i=1;i<l;i++)
              {
                     if(ss[i]!=ss[i-1])
                     continue;
                     for(j='a',j<='z',j++)
                     {
                            if(j!=ss[i-1]&&j!=ss[i+1])
                            {
                                   ss[i]=(char)j;
                                   break;
                            }
                     }
              }
             for(i=0;i<l;i++)
			System.out.print(ss[i]);
       }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class name
{
	static int l;
	static String ss;
	static char[] s;
	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		ss=sc.next();
		l=ss.length();
		ss=ss+" ";
		s=ss.toCharArray();
		for(int i=1;i<l;i++)
		{
			if(s[i]!=s[i-1])
			continue;
			for(int j='a';j<='z';j++)
				if(j!=s[i-1]&&j!=s[i+1])
				{
				       s[i]=(char)j;
				       break;

				}
		}
		for(int i=0;i<l;i++)
			System.out.print(s[i]);
	}
}


import java.io.*;
import java.math.*;
import java.util.*;
public class name
{
       public static void main(String[]args)
       {
              Scanner sc=new Scanner(System.in);
              String s;
              char ss[];
              int i,j;
              s=sc.next();
              ss=s.toCharArray();
              l=s.length();
              for(i=1;i<l;i++)
              {
                     if(ss[i]!=ss[i-1])
                     continue;
                     for(j='a';j<='z';j++)
                     {
                            if((j!=ss[i-1])&&(j!=ss[i+1]))
                            {
                                   ss[i]=(char)j;
                                   break;
                            }
                     }
              }
             for(i=0;i<l;i++)
			System.out.print(ss[i]);
       }
}


import java.io.*;
import java.math.*;
import java.util.*;
public class name
{
       public static void main(String[]args)
       {
              Scanner sc=new Scanner(System.in);
              String s;
              char ss[];
              int i,j,l=0;
              s=sc.next();
              ss=s.toCharArray();
              l=s.length();
              for(i=1;i<l;i++)
              {
                     if(ss[i]!=ss[i-1])
                     continue;
                     for(j='a';j<='z';j++)
                     {
                            if((j!=ss[i-1])&&(j!=ss[i+1]))
                            {
                                   ss[i]=(char)j;
                                   break;
                            }
                     }
              }
             for(i=0;i<l;i++)
			System.out.print(ss[i]);
       }
}


package problem665;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Max on 11.01.2017.
 *
 * http://codeforces.com/contest/665/problem/C
 *
 */

/**
 *
 */

public class C {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = "";
        try {
            input = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        char[] toChange = "abc".toCharArray();
        char[] inputArr = input.toCharArray();

        if(inputArr.length != 1){
            if (inputArr.length == 2){
                if (inputArr[0] == inputArr[1]){
                    if (inputArr[0] == toChange[0]){
                        inputArr[0] = toChange[1];
                    } else {
                        inputArr[0] = toChange[0];
                    }
                }
            } else {
                for (int i = 1; i<inputArr.length-1; i++){
                    if(inputArr[i] == inputArr[i - 1]){
                        inputArr[i] = changeChar(inputArr[i], inputArr[i + 1], toChange);
                    }
                }
                if (inputArr[inputArr.length - 1] == inputArr[inputArr.length - 2]){
                    inputArr[inputArr.length - 1] = changeChar(inputArr[inputArr.length - 1], 'd', toChange);
                }
            }
        }
        System.out.print(inputArr);
    }

    private static char changeChar(char current, char next, char[] toChange){
        for (char aToChange : toChange) {
            if (current != aToChange && next != aToChange) {
                return aToChange;
            }
        }
        return ' ';
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Link:
 * http://codeforces.com/contest/665/problem/C
 *
 */

/**
 * C. Простые строки
 * zscoder любит простые строки! Строка t называется простой, если любая пара соседних букв различается.
 * Например, строки ab, aba, zscoder — простые, в то время как строки aa, add не являются таковыми.

 * У zscoder есть строка s. Он хочет изменить в ней наименьшее количество букв, чтобы строка s стала простой. Помогите ему с этой задачей!

 * Входные данные
 * В единственной строке находится строка s (1 ≤ |s| ≤ 2·105) — строка, которая есть у zscoder. Строка s состоит только из строчных английских букв.

 * Выходные данные
 * Выведите простую строку s' — строку s после минимального количества изменений. Если существует несколько решений, можете вывести любое из них.

 * Обратите внимание, что строка s' также должна состоять только из строчных английских букв.
 */

public class C {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        char[] toChange = "abc".toCharArray();
        char[] inputArr = input.toCharArray();

        if(inputArr.length != 1){
            if (inputArr.length == 2){
                if (inputArr[0] == inputArr[1]){
                    if (inputArr[0] == toChange[0]){
                        inputArr[0] = toChange[1];
                    } else {
                        inputArr[0] = toChange[0];
                    }
                }
            } else {
                for (int i = 1; i<inputArr.length-1; i++){
                    if(inputArr[i] == inputArr[i - 1]){
                        inputArr[i] = changeChar(inputArr[i], inputArr[i + 1], toChange);
                    }
                }
                if (inputArr[inputArr.length - 1] == inputArr[inputArr.length - 2]){
                    inputArr[inputArr.length - 1] = changeChar(inputArr[inputArr.length - 1], 'd', toChange);
                }
            }
        }
        System.out.print(inputArr);
    }

    private static char changeChar(char current, char next, char[] toChange){
        for (char aToChange : toChange) {
            if (current != aToChange && next != aToChange) {
                return aToChange;
            }
        }
        return ' ';
    }
}


package problem665;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Link:
 * http://codeforces.com/contest/665/problem/C
 *
 */

/**
 * C. Простые строки
 * zscoder любит простые строки! Строка t называется простой, если любая пара соседних букв различается.
 * Например, строки ab, aba, zscoder — простые, в то время как строки aa, add не являются таковыми.

 * У zscoder есть строка s. Он хочет изменить в ней наименьшее количество букв, чтобы строка s стала простой. Помогите ему с этой задачей!

 * Входные данные
 * В единственной строке находится строка s (1 ≤ |s| ≤ 2·105) — строка, которая есть у zscoder. Строка s состоит только из строчных английских букв.

 * Выходные данные
 * Выведите простую строку s' — строку s после минимального количества изменений. Если существует несколько решений, можете вывести любое из них.

 * Обратите внимание, что строка s' также должна состоять только из строчных английских букв.
 */

public class C {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        char[] toChange = "abc".toCharArray();
        char[] inputArr = input.toCharArray();

        if(inputArr.length != 1){
            if (inputArr.length == 2){
                if (inputArr[0] == inputArr[1]){
                    if (inputArr[0] == toChange[0]){
                        inputArr[0] = toChange[1];
                    } else {
                        inputArr[0] = toChange[0];
                    }
                }
            } else {
                for (int i = 1; i<inputArr.length-1; i++){
                    if(inputArr[i] == inputArr[i - 1]){
                        inputArr[i] = changeChar(inputArr[i], inputArr[i + 1], toChange);
                    }
                }
                if (inputArr[inputArr.length - 1] == inputArr[inputArr.length - 2]){
                    inputArr[inputArr.length - 1] = changeChar(inputArr[inputArr.length - 1], 'd', toChange);
                }
            }
        }
        System.out.print(inputArr);
    }

    private static char changeChar(char current, char next, char[] toChange){
        for (char aToChange : toChange) {
            if (current != aToChange && next != aToChange) {
                return aToChange;
            }
        }
        return ' ';
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char[] c = in.readLine().trim().toCharArray();

        for (int i = 1; i < c.length; i++) {
            char left = c[i - 1];
            char cur = c[i];
            char right;
            if (i == c.length - 1) {
                right = cur;
            } else {
                right = c[i + 1];
            }
            if (left == cur) {
                while (cur == left || cur == right) {
                    cur = (char) ('a' + (cur + 1) % 'a');
                }
                c[i] = cur;
            }
        }

        System.out.println(String.valueOf(c));
    }

}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {

    static class Trip {
        int a, b, l;

        public Trip(int a, int b, int l) {
            this.a = a;
            this.b = b;
            this.l = l;
        }
    }

    public static void main(String[] args) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder s = new StringBuilder(in.readLine().trim());

        PriorityQueue<Trip> pq = new PriorityQueue<>(new Comparator<Trip>() {
            @Override
            public int compare(Trip o1, Trip o2) {
                return Integer.compare(o2.l, o1.l);
            }
        });

        char c = s.charAt(0);
        int begin = 0;
        int end = 0;
        for (int i = 1; i < s.length(); i++) {
            if (s.charAt(i) == c) {
                // 3
                if (end - begin == 1) {
                    end = i;
                    pq.add(new Trip(begin, end, (end - begin) / 2 + begin));
                    i++;
                    begin = i;
                    end = i;
                    if (i < s.length())
                        c = s.charAt(i);
                    else
                        c = '\0';
                } else {
                    end = i;
                }
            } else {
                if (end - begin > 0) {
                    pq.add(new Trip(begin, end, (end - begin) / 2 + begin));
                }
                c = s.charAt(i);
                begin = i;
                end = i;
            }
        }
        if (end - begin > 0) {
            pq.add(new Trip(begin, end, (end - begin) / 2 + begin));
        }
//        System.out.println(pq.size());

        while (!pq.isEmpty()) {
            Trip trip = pq.poll();
            int a = trip.a;
            int b = trip.b;
            int l = trip.l;
            char left = s.charAt(Math.max(0, l - 1));
            char right = s.charAt(Math.min(s.length() - 1, l + 1));
            int newC = 'a';
            while (newC == left || newC == right) {
                newC++;
            }
            s.setCharAt(l, (char) newC);
            if (b - a != 1) {
                if (l - 1 - a > 0)
                    pq.add(new Trip(a, l - 1, (l - 1 - a) / 2 + a));
                if (b - l - 1 > 0)
                    pq.add(new Trip(l + 1, b, (b - l - 1) / 2 + l + 1));
            }
        }

        System.out.println(s.toString());
    }

}