#pragma warning(disable:4996)
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#include<string>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
int a[100005];
int main()
{
	int t, i, MAX, MIN, ans, n, k;
	scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (i = 1; i <= n; i++) {
			scanf("%d", &a[i]);
		}
		a[0] = a[n + 1] = -1;
		MAX = -1; MIN = 1e9;
		for (i = 1; i <= n; i++) {
			if (a[i] == -1) {
				if (a[i - 1] != -1) {
					MAX = max(MAX, a[i - 1]);
					MIN = min(MIN, a[i - 1]);
				}
				if (a[i + 1] != -1) {
					MAX = max(MAX, a[i + 1]);
					MIN = min(MIN, a[i + 1]);
				}
			}
		}
		k = (MAX + MIN) >> 1;
		ans = 0;
		for (i = 1; i <= n; i++)
		{
			if (a[i] == -1)a[i] = k;
			if (i != 1)
				ans = max(ans, abs(a[i] - a[i - 1]));
		}
		printf("%d %d\n", ans, k);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		long long int n, MIN = 1000000009,MAX=-1; cin >> n;
		long long int* a = new long long int[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i]!=-1&&a[i] < MIN)
				MIN = a[i];
			if (a[i] != -1 && a[i] > MAX)
				MAX = a[i];
		}
		long long int x=0,t=(MAX + MIN) / 2;
		if (MAX == -1)
			cout << 0 << " " << 5 << endl;
		else
		{
			for (int i = 0; i < n - 1; i++)
			{
				if (a[i] == -1)
					a[i] = t;
				if (a[i + 1] == -1)
					a[i + 1] = t;
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << t << endl;
		}

	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			if (i > 0 && a[i] == -1 && a[i - 1] != -1)
				x.insert(a[i-1]);
			if (a[i] == -1 && a[i + 1] != -1&&i<n-1)
				x.insert(a[i+1]);
		}
		if (x.size() == 0)
			cout << 0 << " " << 0 << endl;
		else
		{
			long long int k = (*x.begin() + *x.rbegin()) / 2, x = 0;
			for (int i = 0; i < n; i++)
				if (a[i] == -1)a[i] = k;
			for (int i = 0; i < n-1; i++)
			{
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << k << endl;
		}
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			if (i > 0 && a[i] == -1 && a[i - 1] != -1)
				x.insert(a[i - 1]);
			if (a[i] == -1 && a[i + 1] != -1 && i < n - 1)
				x.insert(a[i + 1]);
		}
		long long int k=0, z = 0;
		if (x.size() != 0)
			k = (*x.begin() + *x.rbegin()) / 2;
		for (int i = 0; i < n; i++)
			if (a[i] == -1)
				a[i] = k;
		for (int i = 0; i < n - 1; i++)
			if (abs(a[i] - a[i + 1]) > z)
				z = abs(a[i] - a[i + 1]);
			cout << z << " " << k << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		long long int n, MIN = 1000000009,MAX=-1; cin >> n;
		long long int* a = new long long int[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i]!=-1&&a[i] < MIN)
				MIN = a[i];
			if (a[i] != -1 && a[i] > MAX)
				MAX = a[i];
		}
		long long int x=0,t=(MAX + MIN) / 2;
		if (MAX == -1||MAX==MIN)
			cout << 0 << " " << 0 << endl;
		else
		{
			for (int i = 0; i < n - 1; i++)
			{
				if (a[i] == -1)
					a[i] = t;
				if (a[i + 1] == -1)
					a[i + 1] = t;
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << t << endl;
		}

	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		long long int n, MIN = 1000000009,MAX=-1; cin >> n;
		long long int* a = new long long int[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i]!=-1&&a[i] < MIN)
				MIN = a[i];
			if (a[i] != -1 && a[i] > MAX)
				MAX = a[i];
		}
		long long int x=0,t=(MAX + MIN) / 2;
		if (MAX == -1||MAX==MIN)
			cout << 0 << " " << 0 << endl;
		else
		{
			bool f = true;
			while (f)
			{
				bool d = true;
				for(int i=0;i<n;i++)
					if (a[i] == t)
					{
						d = false;
						t++;
						break;
					}
				if (d)
					f = false;
			}
			for (int i = 0; i < n - 1; i++)
			{
				if (a[i] == -1)
					a[i] = t;
				if (a[i + 1] == -1)
					a[i + 1] = t;
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << t << endl;
		}

	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			if (i > 0 && a[i] == -1 && a[i - 1] != -1)
				x.insert(a[i - 1]);
			if (a[i] == -1 && a[i + 1] != -1 && i < n - 1)
				x.insert(a[i + 1]);
		}
		if (x.size() == 0)
			cout << 0 << " " << 0 << endl;
		else
		{
			long long int k = (*x.begin() + *x.rbegin()) / 2, x = 0;
			bool f = false;
			for (int i = 0; i < n; i++)
			{
				if (a[i] == -1){
					a[i] = k;
					f = true;
			}
			}

			for (int i = 0; i < n - 1; i++)
			{
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			if(f)
			cout << x << " " << k << endl;
			else cout << x << " " << 0 << endl;
		}
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		 int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
			for (int i = 0; i < n-1; i++) {
				if (i > 0 && a[i] != -1 && a[i - 1] == -1)
					x.insert(a[i]);
				else if (a[i] != -1 && a[i+1] == -1)
					x.insert(a[i]);
			}
		if (x.size() == 0)
			cout << 0 << " " << 7<<endl;
		else
		{
			long long int k = (*x.begin()+*x.rbegin()) / 2,x=0;
				for (int i = 0; i < n - 1; i++)
				{
					if (a[i] == -1)
						a[i] = k;
					if (a[i + 1] == -1)
						a[i + 1] = k;
					if (abs(a[i] - a[i + 1]) > x)
						x = abs(a[i] - a[i + 1]);
				}
				cout << x << " " << k << endl;
		}
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		long long int n, MIN = 1000000009,MAX=-1; cin >> n;
		long long int* a = new long long int[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i]!=-1&&a[i] < MIN)
				MIN = a[i];
			if (a[i] != -1 && a[i] > MAX)
				MAX = a[i];
		}
		long long int x=0,t=MIN+(MAX - MIN) / 2;
		if (MAX == -1||MAX==MIN)
			cout << 0 << " " << 0 << endl;
		else
		{
			for (int i = 0; i < n - 1; i++)
			{
				if (a[i] == -1)
					a[i] = t;
				if (a[i + 1] == -1)
					a[i + 1] = t;
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << t << endl;
		}

	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			if (i > 0 && a[i] == -1 && a[i - 1] != -1)
				x.insert(a[i - 1]);
			if (a[i] == -1 && a[i + 1] != -1 && i < n - 1)
				x.insert(a[i + 1]);
		}
		long long int k=0, z = 0;
		if (x.size() > 1)
			k = (*x.begin() + *x.rbegin()) / 2;
		else if (x.size() == 1) k = *x.begin();
		for (int i = 0; i < n; i++)
			if (a[i] == -1)
				a[i] = k;
		for (int i = 0; i < n - 1; i++)
			if (abs(a[i] - a[i + 1]) > z)
				z = abs(a[i] - a[i + 1]);
			cout << z << " " << k << endl;
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		for (int i = 0; i < n - 1; i++) {
			if (i > 0 && a[i] == -1 && a[i - 1] != -1)
				x.insert(a[i-1]);
			if (a[i] == -1 && a[i + 1] != -1&&i<n-1)
				x.insert(a[i+1]);
		}
		if (x.size() == 0)
			cout << 0 << " " << 7 << endl;
		else
		{
			long long int k = (*x.begin() + *x.rbegin()) / 2, x = 0;
			for (int i = 0; i < n; i++)
				if (a[i] == -1)a[i] = k;
			for (int i = 0; i < n-1; i++)
			{
				if (abs(a[i] - a[i + 1]) > x)
					x = abs(a[i] - a[i + 1]);
			}
			cout << x << " " << k << endl;
		}
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
int main()
{
	int t; cin >> t;
	while (t--)
	{
		long long int n; cin >> n;
		long long int* a = new long long int[n];
		set<long long int >x;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			if (a[i] != -1)
				x.insert(a[i]);
		}
		if (x.size() == 0)
			cout << 0 << " " << 7<<endl;
		else
		{
			long long int k = (*x.begin()+*x.rbegin()) / 2,x=0;
				for (int i = 0; i < n - 1; i++)
				{
					if (a[i] == -1)
						a[i] = k;
					if (a[i + 1] == -1)
						a[i + 1] = k;
					if (abs(a[i] - a[i + 1]) > x)
						x = abs(a[i] - a[i + 1]);
				}
				cout << x << " " << k << endl;
		}
	}
	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		long long int* a = new long long int[n];
		for (int i = 0; i < n; i++)cin >> a[i];
		long long int  C = 0, mi = 1000000000, ma = -100000000;
		for (int i = 0; i < n; i++) {
			if (a[i] != -1 && (i>0&&a[i - 1] == -1 || a[i + 1] == -1&&i<n-1))
				mi = min(mi, a[i]), ma = max(ma, a[i]);
		}
		long long int  k = mi + (ma - mi) / 2;
		if (a[0] == -1)a[0] = k;
		for (int i = 1; i < n; i++) {
			if (a[i] == -1)a[i] = k;
			C = max(C, abs(a[i] - a[i - 1]));
		}
		cout << C << " " << k << endl;
	}
	return 0;
	/////fuckyourmotheryoumotherfucker
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int t, n, l, x, mx, mna, mxa, k;
	cin >> t;
	bool f, ans, hah;
	for (int i = 0; i < t; ++i) {
		cin >> n;
		cin >> l;
		mx = 0;
		mna = 1e9 + 1;
		mxa = 0;
		ans = false;
		hah = false;
		f = false;
		for (int j = 0; j < n - 1; ++j) {
			cin >> x;
			if (x == -1 && l != -1 && !f) {
				if (mna > l) {
					mna = l;
				}
				if (mxa < l) {
					mxa = l;
				}
				hah = true;
			}
			f = false;
			if (l == -1 && x != -1) {
				if (mxa < x) {
					mxa = x;
				}
				if (mna > x) {
					mna = x;
				}
				f = true;
				hah = true;
			}
			if (mx < abs(x - l) && x != -1 && l != -1) {
				mx = abs(x - l);
				ans = true;
			}
			l = x;
		}
		if (hah) {
			k = mna + (mxa - mna) / 2;
			mx = max(mx, max(k - mna, mxa - k));
			cout << mx << " " << k << endl;
		}
		else {
			cout << 0 << " " << 1 << endl;
		}

	}
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int t, n, l, x, mx, mna, mxa, k;
	cin >> t;
	bool f, ans, hah;
	for (int i = 0; i < t; ++i) {
		cin >> n;
		cin >> l;
		mx = 0;
		mna = 1e9 + 1;
		mxa = 0;
		ans = false;
		hah = false;
		f = false;
		for (int j = 0; j < n - 1; ++j) {
			cin >> x;
			if (x == -1 && l != -1 && !f) {
				if (mna > l) {
					mna = l;
				}
				if (mxa < l) {
					mxa = l;
				}
				hah = true;
			}
			f = false;
			if (l == -1 && x != -1) {
				if (mxa < x) {
					mxa = x;
				}
				if (mna > x) {
					mna = x;
				}
				f = true;
				hah = true;
			}
			if (mx < abs(x - l) && x != -1 && l != -1) {
				mx = abs(x - l);
				ans = true;
			}
			l = x;
		}
		if (hah) {
			k = mna + (mxa - mna) / 2;
			mx = max(mx, max(k - mna, k - mxa));
			cout << mx << " " << k << endl;
		}
		else {
			cout << 0 << " " << 1 << endl;
		}

	}
}


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

int main() {
	//
	//ifstream cin("input.txt");
	//
	int t;
	cin >> t;
	for (int ijk = 0; ijk < t; ijk++) {
		int n;
		cin >> n;
		vector <int> a(n);
		for (int i = 0; i < n; i++) cin >> a[i];
		int min, max;
		min = 1000000002;
		max = -2;
		for (int i = 0; i < n; i++) {
			if (a[i] == -1) {
				if (i != 0) {
					if (a[i - 1] != -1) {
						if (abs(a[i - 1]) < min) min = abs(a[i - 1]);
						if (abs(a[i - 1]) > max) max = abs(a[i - 1]);
					}
				}
				if (i != n - 1) {
					if (a[i + 1] != -1) {
						if (abs(a[i + 1]) < min) min = abs(a[i + 1]);
						if (abs(a[i + 1]) > max) max = abs(a[i + 1]);
					}
				}
			}
		}
		int k = (max + min) / 2;
		int m = -2;
		for (int i = 0; i < n; i++) {
			if (a[i] == -1) {
				a[i] = k;
			}
		}
		for (int i = 1; i < n; i++) {
			if (abs(a[i] - a[i - 1]) > m) m = abs(a[i] - a[i - 1]);
		}
		cout << m << " " << k << endl;
	}
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <functional>

using namespace std;

typedef long long LL;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int N;
		cin >> N;
		vector<LL> v(N);
		LL minn = -1, maxn = -1;
		for (LL& n : v) {
			cin >> n;
		}

		for (int i = 0; i < N; ++i) {
			if (v[i] != -1) {
				continue;
			}

			if (0 <= i - 1 && v[i - 1] != -1) {
				if (minn == -1) {
					minn = v[i - 1];
					maxn = v[i - 1];
				}
				minn = min(minn, v[i - 1]);
				maxn = max(maxn, v[i - 1]);
			}
			if (i + 1 < N && v[i + 1] != -1) {
				if (minn == -1) {
					minn = v[i + 1];
					maxn = v[i + 1];
				}
				minn = min(minn, v[i + 1]);
				maxn = max(maxn, v[i + 1]);
			}
		}

		LL maxd = 0;
		LL mid = (maxn + minn) / 2;
		for (int i = 0; i + 1 < N; ++i) {
			LL l = v[i];
			LL r = v[i + 1];
			if (l == -1) l = mid;
			if (r == -1) r = mid;
			maxd = max(maxd, abs(l - r));
		}

		if (minn == -1) {
			cout << maxd << " " << 0 << endl;
		}
		else {
			cout << maxd << " " << mid << endl;
		}
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t, n;
long long m = 0, k = 0, mx = 0, mn = 0, max_dif=0;
vector <long long> a;

int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n;
		a.clear();
		a.resize(n, -1);
		for (int i = 0;i < n;i++) cin >> a[i];
		mx = 0; mn = 2000000000;
		for (int i = 0;i < n - 1;i++)
		{
			if (a[i] == -1 && a[i + 1] != -1)
			{
				mx = max(mx, a[i + 1]); mn = min(mn, a[i + 1]);
			}
			if (a[i] != -1 && a[i + 1] == -1)
			{
				mx = max(mx, a[i]); mn = min(mn, a[i]);
			}
			if (a[i] != -1 && a[i + 1] != -1) max_dif = max(max_dif, abs(a[i] - a[i + 1]));
		}
		if (mx == 0 && mn == 2000000000) cout << "0 0" << endl;
		else
		{
			k = (mx + mn) / 2;
			m = max(mx - k, max_dif);
			cout << m << " " << k << endl;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int t, n;
long long m = 0, k = 0, mx = 0, mn = 0, max_dif=0;
vector <long long> a;

int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n;
		a.clear();
		a.resize(n, -1);
		for (int i = 0;i < n;i++) cin >> a[i];
		mx = 0; mn = 2000000000;
		max_dif = 0;
		for (int i = 0;i < n - 1;i++)
		{
			if (a[i] == -1 && a[i + 1] != -1)
			{
				mx = max(mx, a[i + 1]); mn = min(mn, a[i + 1]);
			}
			if (a[i] != -1 && a[i + 1] == -1)
			{
				mx = max(mx, a[i]); mn = min(mn, a[i]);
			}
			if (a[i] != -1 && a[i + 1] != -1) max_dif = max(max_dif, abs(a[i] - a[i + 1]));
		}
		if (mx == 0 && mn == 2000000000) cout << "0 0" << endl;
		else
		{
			k = (mx + mn) / 2;
			m = max(mx - k, max_dif);
			cout << m << " " << k << endl;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <utility>
#include <map>
#include <queue>
#include <iterator>
using namespace std;

int a[400000];
int b[400000];
int main() {
	int t; cin >> t;
	while (t--) {
		int n; cin >> n;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			b[i] = a[i];
		}
		long long mini = -1;
		long long maxi = -1;
		int nn = 0;
		bool flaga = false;
		for (int i = 0; i < n; i++) {
			if (a[i] != -1 && (i > 0 && (a[i-1] == -1) || (i < n - 1 && a[i+1] == -1))) {
				if (a[i] > maxi) maxi = a[i];
				if (a[i] < mini || mini == -1) mini = a[i];
				flaga = true;
			}
		}
		int ka = (maxi + mini) / 2 + 1;
		int kb = (maxi + mini) / 2;
		int ansa = -100000000;
		int ansb = -100000000;
		bool flagb = false;
		for (int i = 0; i < n; i++) {
			if (a[i] == -1) {
				a[i] = ka;
				b[i] = kb;
				flagb = true;
			}
		}

		for (int i = 0; i < n-1; i++) {
			ansa = max(ansa, abs(a[i] - a[i + 1]));
			ansb = max(ansb, abs(b[i] - b[i + 1]));
		}
		if (!flaga) {
			cout << "0 42\n";
		}
		else {
			if (ansa < ansb) {
				cout << ansa << " " << ka << '\n';
			}
			else {
				cout << ansb << " " << kb << '\n';
			}
		}
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <algorithm>
#include <sstream>
#include <assert.h>
#include <bitset>
#include <iomanip>
#include <vector>
#include <queue>
#include <random>

#define en "\n"
#define for0(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#pragma warning(disable : 4996)
typedef long long ll;
typedef long double ld;
//АААААААААААААААААААААА ХОЧУУУУУУУУУУУУУУУУУУ СИНЕГООООООООО!!(не ВИКУ)

using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

template<typename T> void output(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void output(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void output(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

vector <ll> del(ll n) {
	vector<ll> ans;
	ll i = 1;
	for (i = 1; i * i < n; i++) {
		if (n % i == 0) {
			ans.pb(i);
			ans.pb(n / i);
		}
	}
	if (n % i == 0)
		ans.pb(i);
	sort(all(ans));
	return ans;
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	int Min = 1e9 + 2, Max = 0;
	for0(i, n) {
		cin >> a[i];
	}

	int delta = 0;
	for0(i, n - 1) {
		if (a[i] != -1 && a[i + 1] != -1) {
			delta = max(abs(a[i] - a[i + 1]), delta);
		}
	}

	for0(i, n) {
		if (a[i] == -1) {
			if (i > 0 && a[i - 1] != -1) {
				Min = min(a[i - 1], Min);
				Max = max(a[i - 1], Max);
			}
			if (i < n - 1 && a[i + 1] != -1) {
				Min = min(a[i +1], Min);
				Max = max(a[i+ 1], Max);
			}
		}
	}
	if (Min != 1e9 + 2) {
		delta = max(delta, (abs(Max - Min) + 1) / 2);
	}

	cout << delta << " " << (Max + Min) / 2 << en;
}

int main() {
	srand(time(0));
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int t;
	cin >> t;
	while(t--)
		solve();
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		vector<long> a(n);
		ll mini = 10e9 + 1;
		ll maxi = -2;
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
			if (a[i] != -1) {
				mini = (mini > a[i]) ? a[i] : mini;
				maxi = (maxi < a[i]) ? a[i] : maxi;
			}
		}
		ll m = -2;
		for (int i = 0; i < n - 1; ++i) {
			if (a[i] != -1 && a[i + 1] != -1) {
				if (m < abs(a[i] - a[i + 1])) {
					m = abs(a[i] - a[i + 1]);
				}
			}
		}
		if (mini == 10e9 + 1 && maxi == -2) {
			mini = 0;
			maxi = 0;
		}
		if (mini == maxi) {
			cout << 0 << " " << mini << endl;
		}
		else if (m == -2) {
			int k = (mini + maxi) / 2;
			m = max(k - mini, maxi - k);
			cout << m << " " << k << endl;
		}
		else {
			cout << m << " " << mini << endl;
		}
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		int mn = 100000001;
		int mx = -2;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		for (int i = 0; i < n; ++i) {
			if (a[i] != -1 && ((i > 0 && a[i - 1] == -1) || (i < n - 1 && a[i + 1] == -1))) {
				mn = min(a[i], mn);
				mx = max(a[i], mx);
			}
		}
		int k = (mx + mn) / 2;
		int m = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] == -1) {
				a[i] = k;
			}
			if (i) {
				m = max(m, abs(a[i] - a[i - 1]));
			}
		}
		cout << m << " " << k << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		int mn = 1000000001;
		int mx = -2;
		vector<int> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		for (int i = 0; i < n; ++i) {
			if (a[i] == -1 && i > 0 && a[i - 1] != -1) {
				mn = min(a[i - 1], mn);
				mx = max(a[i - 1], mx);
			}
			if (a[i] == -1 && i < n - 1 && a[i + 1] != -1) {
				mn = min(a[i + 1], mn);
				mx = max(a[i + 1], mx);
			}
		}
		int k = (mx + mn) / 2;
		int m = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] == -1) {
				a[i] = k;
			}
			if (i) {
				m = max(m, abs(a[i] - a[i - 1]));
			}
		}
		cout << m << " " << k << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
	ios::sync_with_stdio(false);
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int T; cin >> T;
	for (int t = 1; t <= T; ++t) {
		int n; cin >> n;
		ll mn = 10e9;
		ll mx = -2;
		vector<ll> a(n);
		for (int i = 0; i < n; ++i) {
			cin >> a[i];
		}
		for (int i = 0; i < n; ++i) {
			if (a[i] != -1 && ((i > 0 && a[i - 1] == -1) || (i < n - 1 && a[i + 1] == -1))) {
				mn = min(a[i], mn);
				mx = max(a[i], mx);
			}
		}
		ll k = (mx + mn) / 2;
		ll m = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] == -1) {
				a[i] = k;
			}
			if (i) {
				m = max(m, abs(a[i] - a[i - 1]));
			}
		}
		cout << m << " " << k << endl;
	}
	return 0;
}


#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int a[maxn];
bool cmp(int a, int b) {
	return a > b;
}
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int lcm(int a, int b) {
	return (a * b) / gcd(a, b);
}
int MAX(int a, int b) {
	return a > b ? a : b;
}
int MIN(int a, int b) {
	return a < b ? a : b;
}
void solve(int n) {
	int maxx = inf;
	int minn = -inf;
	for (int i = 0; i < n; i++) {
		if (-1 == a[i]) {
			if (i != 0 && a[i - 1] != -1) {
				minn = MAX(minn, a[i - 1]);
				maxx = MIN(maxx, a[i - 1]);

			}
			if (a[i + 1] != -1 && i + 1 != n) {
				minn = MAX(minn, a[i + 1]);
				maxx = MIN(maxx, a[i + 1]);

			}
		}
	}
	if (minn == -inf || maxx == inf) {
		printf("0 0\n");
		return;
	}
	else {
		int ans = -inf;
		int d = (minn + maxx) / 2;
		for (int i = 1; i < n; i++) {
			if (a[i - 1] == -1)
				a[i - 1] = d;
			if (a[i] == -1)
				a[i] = d;
			ans = MAX(ans, abs(a[i] - a[i - 1]));
		}
		printf("%d %d\n", ans, d);
	}
}
int main()
{
	int t; scanf("%d", &t);
	for (int i = 0; i < t; i++) {
		int n; scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", &a[i]);
		solve(n);
	}
	return 0;
}


#include <iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string.h>
#include<math.h>
using namespace std;

int main()
{
	int arr[100000];
	int cases;
	cin >> cases;
	for (int t = 0; t < cases; t++)
	{
		int n;
		cin >> n;
		int Diff = INT_MIN;
		int mn = INT_MAX,mx=INT_MIN;
		for (int i = 0; i < n; i++)
		{
			cin >> arr[i];
			if (i != 0)
			{
				if (arr[i] != -1 && arr[i - 1] != -1)
					Diff = max(Diff, abs(arr[i] - arr[i - 1]));
				else if (arr[i] == -1 && arr[i - 1] != -1)
				{
					mn = min(mn, arr[i - 1]);
					mx = max(mx, arr[i - 1]);
				}
				else if(arr[i]!=-1&&arr[i-1]==-1)
				{
					mn = min(mn, arr[i]);
					mx = max(mx, arr[i]);
				}
			}
		}
		if (Diff == INT_MIN && mn == INT_MAX && mx == INT_MIN)
			cout << "0 0\n";
		else
		{
			Diff = max(Diff, (mx - mn + 1) / 2);
			cout << Diff << ' ' << (mn + mx) / 2 << endl;
		}
	}
}


#include <cstdio>
using namespace std;
inline void in(int &x){
	char c=getchar();
	while (c<'0'||c>'9')  c=getchar();
	for (x=0;c>='0'&&c<='9';c=getchar())  x=x*10+c-'0';
}
int t,n,a[200005],sum,tot;
const int INF=1000000001;
int main(){
	scanf("%d",&t);
	while (t--){int min=INF,max=0;
		scanf("%d",&n);
		for (int i=1;i<=n;i++)
		  scanf("%d",&a[i]);
		if (a[1]==-1&&a[2]!=-1)  max=max>a[2]?max:a[2],min=min<a[2]?min:a[2];
		if (a[n]==-1&&a[n-1]!=-1)  max=max>a[n-1]?max:a[n-1],min=min<a[n-1]?min:a[n-1];
		for (int i=2;i<=n-1;i++){
			if (a[i]==-1){
				if (a[i-1]!=-1)  max=max>a[i-1]?max:a[i-1],min=min<a[i-1]?min:a[i-1];
				if (a[i+1]!=-1)  max=max>a[i+1]?max:a[i+1],min=min<a[i+1]?min:a[i+1];
			}
		}
		if (min==INF)  min=0;
		int ans=(max+min)/2;
		printf("%d %d\n",max-ans>min-ans?max-ans:min-ans,ans);
	}
	return 0;
}


#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 100000;
int arr[MAX];

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

	int t;
	cin >> t;

	for (int test = 0; test < t; test++) {
		int n;
		cin >> n;

		int mi = INT_MAX, ma = -1, ans = -1;

		for (int i = 0; i < n; i++) {
			cin >> arr[i];
		}
		for (int i = 0; i < n; i++) {
			if (arr[i] == -1) continue;
			if (i != 0 && arr[i - 1] != -1) ans = max(ans, (int)fabs(arr[i] - arr[i - 1]));
			if ((i == 0 || arr[i - 1] != -1) && (i == n - 1 || arr[i + 1] != -1)) continue;
			mi = min(mi, arr[i]);
			ma = max(ma, arr[i]);
		}

		if (mi == INT_MAX && ma == -1) cout << max(0, ans) << " 0\n";
		else if (mi == INT_MAX) cout << max(0, ans) << ' ' << ma << '\n';
		else if (ma == -1) cout << max(0, ans) << ' ' << mi << '\n';
		else {
			int mid = (mi + ma) / 2;
			cout << max(ans, ma - mid) << ' ' << mid << '\n';
		}
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e6+500;
ll arr[N];
ll cup[N];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>arr[i];

        bool flag=false;
        for(int i=1;i<=n;i++)
        {
            if(arr[i]!=-1)
            {
                flag=true;
                break;
            }
        }
        if(!flag)
        {
            cout<<"0 0"<<endl;
            continue;
        }
        int cnt=0;
        ll m,k;
        for(int i=1;i<=n;i++)
        {
            if(arr[i]==-1)
            {
                if(i==1)
                {
                    if(arr[i+1]!=-1)
                        cup[++cnt]=arr[i+1];
                }
                else if(i==n)
                {
                    if(arr[i-1]!=-1)
                        cup[++cnt]=arr[i-1];
                }
                else
                {
                    if(arr[i-1]!=-1)
                        cup[++cnt]=arr[i-1];
                    if(arr[i+1]!=-1)
                        cup[++cnt]=arr[i+1];
                }
            }
        }
        //for(int i=1;i<=cnt;i++)
          //  cout<<cup[i]<<endl;
        sort(cup+1,cup+cnt+1);
        k=(cup[1]+cup[cnt])/2;
        m=cup[cnt]-k;
        for(int i=1;i<n;i++)
        {
            if(arr[i]!=-1)
            {
                if(arr[i+1]!=-1)
                    m=max(m,abs(arr[i+1]-arr[i]));
            }
        }
        cout<<m<<" "<<k<<endl;
    }
    return 0;
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
const int maxn=1e5+10;
const int INF = 0x3f3f3f;
int main(){
int n;
int t;
long long a[maxn];
cin>>t;
while(t--)
{cin>>n;
long long maxi=0,mini=INF;
a[0]=-1;a[n+1]=-1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{if(a[i]==-1)
{if(a[i+1]!=-1)
{maxi=max(maxi,a[i+1]);
mini=min(mini,a[i+1]);
}
if(a[i-1]!=-1)
{maxi=max(maxi,a[i-1]);
mini=min(mini,a[i-1]);
}}}
long long d=(maxi+mini)/2;
if(maxi==-INF||mini==INF)
cout<<"0"<<" "<<"0"<<endl;
else
{
long long ans=0;
for(int i=1;i<=n-1;i++)
{if(a[i]==-1)a[i]=d;
if(a[i+1]==-1)a[i+1]=d;
ans=max(ans,abs(a[i]-a[i+1]));
}
cout<<ans<<" "<<d<<endl;}
}
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
const int maxn=1e5+5;
const int INF = 0x3f3f3f3f;
int main(){
int n;
int t;
int a[maxn];
cin>>t;
while(t--)
{cin>>n;
int maxi=-INF,mini=INF;
a[0]=-1;a[n+1]=-1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{if(a[i]==-1)
{if(a[i+1]!=-1)
{maxi=max(maxi,a[i+1]);
mini=min(mini,a[i+1]);
}
if(a[i-1]!=-1)
{maxi=max(maxi,a[i-1]);
mini=min(mini,a[i-1]);
}}}
int d=(maxi+mini)/2;
if(maxi==-INF||mini==INF)
cout<<"0"<<" "<<"0"<<endl;
else
{
int ans=-INF;
for(int i=1;i<=n-1;i++)
{if(a[i]==-1)a[i]=d;
if(a[i+1]==-1)a[i+1]=d;
ans=max(ans,abs(a[i]-a[i+1]));
}
cout<<ans<<" "<<d<<endl;
}}
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
const int maxn=1e5+10;
const int INF = 0x3f3f3f;
int main(){
int n;
int t;
int a[maxn];
cin>>t;
while(t--)
{cin>>n;
int maxi=0,mini=INF;
a[0]=-1;a[n+1]=-1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{if(a[i]==-1)
{if(a[i+1]!=-1)
{maxi=max(maxi,a[i+1]);
mini=min(mini,a[i+1]);
}
if(a[i-1]!=-1)
{maxi=max(maxi,a[i-1]);
mini=min(mini,a[i-1]);
}}}
int d=(maxi+mini)/2;
if(maxi==-INF||mini==INF)
cout<<"0"<<" "<<"0"<<endl;
else
{
int ans=0;
for(int i=1;i<=n-1;i++)
{if(a[i]==-1)a[i]=d;
if(a[i+1]==-1)a[i+1]=d;
ans=max(ans,abs(a[i]-a[i+1]));
}
cout<<ans<<" "<<d<<endl;}
}
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
const int maxn=300010;
const int INF = 0x3f3f3f;
int main(){
int n;
int t;
int a[maxn];
cin>>t;
while(t--)
{cin>>n;
int maxi=-INF,mini=INF;
a[0]=-1;a[n+1]=-1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{if(a[i]==-1)
{if(a[i+1]!=-1)
{maxi=max(maxi,a[i+1]);
mini=min(mini,a[i+1]);
}
if(a[i-1]!=-1)
{maxi=max(maxi,a[i-1]);
mini=min(mini,a[i-1]);
}}}
int d=(maxi+mini)/2;
if(maxi==-INF||mini==INF)
cout<<"0"<<" "<<"0"<<endl;
else
{
int ans=-INF;
for(int i=1;i<=n-1;i++)
{if(a[i]==-1)a[i]=d;
if(a[i+1]==-1)a[i+1]=d;
ans=max(ans,abs(a[i]-a[i+1]));
}
cout<<ans<<" "<<d<<endl;
}}
}


#include<iostream>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<map>
#include<algorithm>

using namespace std;
const int maxn=300010;
const int INF = 0x3f3f3f;
int main(){
int n;
int t;
int a[maxn];
cin>>t;
while(t--)
{cin>>n;
int maxi=-INF,mini=INF;
a[0]=-1;a[n+1]=-1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)
{if(a[i]==-1)
{if(a[i+1]!=-1)
{maxi=max(maxi,a[i+1]);
mini=min(mini,a[i+1]);
}
if(a[i-1]!=-1)
{maxi=max(maxi,a[i-1]);
mini=min(mini,a[i-1]);
}}}
int d=(maxi+mini)/2;
if(maxi==-INF||mini==INF)
cout<<"0"<<" "<<"0"<<endl;
else
{
int ans=0;
for(int i=1;i<=n-1;i++)
{if(a[i]==-1)a[i]=d;
if(a[i+1]==-1)a[i+1]=d;
ans=max(ans,abs(a[i]-a[i+1]));
}
cout<<ans<<" "<<d<<endl;
}}
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define irt insert
#define ll long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
void solve()
{
	int n;
	cin >> n;
	vi inn = {-1};
	si u;
	int ans = 0, k = 0;
	bool st = true;
	for (int i = 0; i < n; ++i)
	{
		int h;
		cin >> h;
		if (h == -1)
			st = false;
		if (inn.back() == -1 && h != -1)
			u.insert(h);
		if (inn.back() != -1 && h != -1)
			ans = max(ans, abs(h - inn.back()));
		if (h == -1 && inn.back() != -1)
			u.insert(inn.back());
		inn.pb(h);
	}
	if (st)
	{
		cout << 0 << " " << ans << "\n";
		return;
	}
	if (u.empty())
	{
		cout << "0 0\n";
		return;
	}
	u.erase(-1);
	auto it = u.end();
	it--;
	k = ((*it - *u.begin())) / 2;
	if ((*it - *u.begin()) % 2 != 0)
		k++;
	ans = max(ans, k);
	k = max(k +*u.begin(), *it - k);
	cout << ans << " " << k << "\n";

}
signed main()
{
	Kirja_ES;
	int t;
	cin >> t;
	while (t--)
		solve();
}


//белый снег
//белый porshe
//белый trash
//в бонге воск
#include <iostream>
#include <locale>
#include <string>
#include <iomanip>
#include <string.h>
#include <unordered_map>
#include <bitset>
#include <vector>
#include <stdlib.h>
#include <clocale>
#include <algorithm>
#include <iterator>
#include <list>
#include <set>
#include <cstddef>
#include <cstdio>
#include <stdio.h>
#include <map>
#include <cmath>
#include <functional>
#include <stack>
#include <type_traits>
#include <queue>
#include <memory>
#include <memory.h>
#include <time.h>
#pragma warning(disable:4996)
using namespace std;
#define Kirja_ES ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define irt insert
#define ll long long
#define ull unsigned long long
#define str string
#define vi vector<int>
#define vll vector<ll>
#define si set<int>
#define sll set<ll>
#define msi multiset<int>
#define msll multiset<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define left false
#define right true
void solve()
{
	int n;
	cin >> n;
	vi inn = {-2};
	si u;
	int ans = 0, k = 0;
	for (int i = 0; i < n; ++i)
	{
		int h;
		cin >> h;
		if (inn.back() == -1 && h != -1)
			u.insert(h);
		if (inn.back() != -1 && h != -1 && inn.back() != -2)
			ans = max(ans, abs(h - inn.back()));
		if (h == -1 && inn.back() != -1 && inn.back() != -2)
			u.insert(inn.back());
		inn.pb(h);
	}
	if (u.empty())
	{
		cout << "0 0\n";
		return;
	}
	u.erase(-1);
	auto it = u.end();
	it--;
	k = ((*it - *u.begin())) / 2;
	if ((*it - *u.begin()) % 2 != 0)
		k++;
	ans = max(ans, k);
	k = max(k +*u.begin(), *it - k);
	cout << ans << " " << k << "\n";

}
signed main()
{
	Kirja_ES;
	int t;
	cin >> t;
	while (t--)
		solve();
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 2000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
duration v[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].start,&v[i].endd);
    }
    sort(v,v+n,cmp);
    int mx=-1,mx1=-1;
    //cout << v[2].start<<endl;
    for(int i=0;i<n;i++)
    {
        //cout <<mn << mn1 << v[i].start << v[i].endd <<endl;
        if(mx<v[i].start)
            mx=v[i].endd;
        else if(mx1<v[i].start)
            mx1 = v[i].endd;
        else
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 1000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
duration v[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].start,&v[i].endd);
    }
    sort(v,v+n,cmp);
    int mn=INT_MAX,mn1=INT_MAX;
    for(int i=1;i<n;i++)
    {
        if(mn<v[i].start)
            mn=v[i].endd;
        else if(mn1<v[i].start)
            mn1 = v[i].endd;
        else
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
pair<int,int> v[200005];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].first,&v[i].second);
    }
    sort(v,v+n);
    for(int i=0;i<n-1;i++)
    {
        if((i<n-2 && v[i].second==v[i+2].first) || v[i].first==v[i+1].first || v[i].second>v[i+1].first)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 1000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
duration v[MAX];

int main()
{
    int n;
    cin >> n;
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].start,&v[i].endd);
    }
    sort(v,v+n,cmp);
    for(int i=1;i<n;i++)
    {
        if(v[i-1].endd>v[i].start)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
struct duration
{
    int start,endd;
    duration()
    {
        start=0;
        endd=0;
    }
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
int main()
{
    int n;
    cin >> n;
    int l,r;
    duration x;
    vector < duration > v;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&l,&r);
        x.start = l;
        x.endd = r;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),cmp);
    for(int i=1;i<n;i++)
    {
        if(v[i-1].endd>v[i].start)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
pair<int,int> v[200005];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].first,&v[i].second);
    }
    sort(v,v+n);
    int mx=-1,mx1=-1;
    for(int i=1;i<n;i++)
    {
        if(v[i-1].second>v[i].first)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 1000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
duration v[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].start,&v[i].endd);
    }
    sort(v,v+n,cmp);
    for(int i=1;i<n;i++)
    {
        if(v[i-1].endd>v[i].start)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
pair<int,int> v[200005];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].first,&v[i].second);
    }
    sort(v,v+n);
    int mx=-1,mx1=-1;
    for(int i=0;i<n;i++)
    {
        if(mx<v[i].first)
            mx=v[i].second;
        else if(mx1<v[i].first)
            mx1 = v[i].second;
        else
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
vector < duration > v;

int main()
{
    int n;
    cin >> n;
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&l,&r);
        x.start = l;
        x.endd = r;
        v.push_back(x);
    }
    sort(v.begin(),v.end(),cmp);
    for(int i=1;i<n;i++)
    {
        if(v[i-1].endd>v[i].start)
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 2000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
pair<int,int> v[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].first,&v[i].second);
    }
    sort(v,v+n);
    int mx=-1,mx1=-1;
    //cout << v[2].start<<endl;
    for(int i=0;i<n;i++)
    {
        //cout <<mn << mn1 << v[i].start << v[i].endd <<endl;
        if(mx<v[i].first)
            mx=v[i].second;
        else if(mx1<v[i].first)
            mx1 = v[i].second;
        else
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
pair<int,int> v[200005];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].first,&v[i].second);
    }
    sort(v,v+n);
    int mx=-1,mx1=-1;
    for(int i=1;i<n;i++)
    {
        if(v[i-1].second>v[i].first || (i<n-1 && v[i-1].second==v[i+1].first))
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


#include<bits/stdc++.h>
using namespace std;
int const MAX = 1000005;
struct duration
{
    int start,endd;
};
bool cmp(duration a,duration b)
{
    if(a.start==b.start)
        return a.endd<b.endd;
    else
        return a.start<b.endd;
}
duration v[MAX];

int main()
{
    int n;
    scanf("%d",&n);
    int l,r;
    duration x;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i].start,&v[i].endd);
    }
    sort(v,v+n,cmp);
    int mn=INT_MAX,mn1=INT_MAX;
    for(int i=1;i<n;i++)
    {
        if(mn<v[i].start)
            mn=v[i].endd;
        else if(mn2<v[i].start)
            mn2 = v[i].endd;
        else
        {
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
struct node{
    int L, R;
    node (){}
    node(int l, int r){
        L = l;
        R = r;
    }
    bool operator < (const node &a)const{
        if(R == a.R){
            return L < a.L;
        }
        return R < a.R;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector<node> v;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(node(l, r));
    }
    int F = -1, S = -1;
    if(n == 1)return 0 * printf("YES\n");
    for(int i = 0; i < n; i ++){
        if(F == -1){
            F = v[i].R;
            continue;
        }
        if(S == -1){
            S = v[i].R;
            continue;
        }
        if(F < v[i].L){
            F = v[i].R;
            continue;
        }
        if(S < v[i].L){
            S = v[i].R;
            continue;
        }
        return 0 * printf("NO\n");
    }
    puts("YES");
    return 0;

}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
struct node{
    int L, R;
    node (){}
    node(int l, int r){
        L = l;
        R = r;
    }
    bool operator < (const node &a)const{
        if(R == a.R){
            return L > a.L;
        }
        return R < a.R;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector<node> v;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(node(l, r));
    }
    int F = -1, S = -1;
    if(n < 3)return 0 * printf("YES\n");
    for(int i = 0; i < n; i ++){
        if(F == -1){
            F = v[i].R;
            continue;
        }
        if(S == -1){
            S = v[i].R;
            continue;
        }
        if(F < v[i].L){
            F = v[i].R;
            continue;
        }
        if(S < v[i].L){
            S = v[i].R;
            continue;
        }
        return 0 * printf("NO\n");
    }
    puts("YES");
    return 0;

}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
vector<pair<int, int > > v;
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(make_pair(r, l));
    }
    sort(v.begin(), v.end());
    int f = -1, s = -1;
    for(int i = 0; i < (int)v.size(); i ++){
        l = v[i].second;
        r = v[i].first;
        if(f < l){
            f = r;
            continue;
        }
        if(s  < l){
            s = r;
            continue;
        }
        return 0 * printf("NO");
    }
    printf("YES");
    return 0;

}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
struct node{
    int L, R;
    node (){}
    node(int l, int r){
        L = l;
        R = r;
    }
    bool operator < (const node &a)const{
        return R < a.R;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector<node> v;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(node(l, r));
    }
    int F = -1, S = -1;
    if(n == 1)return 0 * printf("YES\n");
    for(int i = 0; i < n; i ++){
        if(F == -1){
            F = v[i].R;
            continue;
        }
        if(S == -1){
            S = v[i].R;
            continue;
        }
        if(F < v[i].L){
            F = v[i].R;
            continue;
        }
        if(S < v[i].L){
            S = v[i].R;
            continue;
        }
        return 0 * printf("NO\n");
    }
    puts("YES");
    return 0;

}


#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
struct node{
    int L, R;
    node (){}
    node(int l, int r){
        L = l;
        R = r;
    }
    bool operator < (const node &a)const{
        return R < a.R;
    }
};
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    vector<node> v;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(node(l, r));
    }
    int F, S;
    if(n == 1)return 0 * printf("YES\n");
    F = v[0].R;
    S = v[1].R;
    for(int i = 2; i < n; i += 2){
        if(v[i].L == F && v[i].R == S)return 0 * printf("NO\n");
        F = v[i].R;
        if(i + 1 < n)
        S = v[i + 1].R;
    }
    puts("YES");
    return 0;

}


//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
//#include <stack>
#include <iomanip>
#include <cstdio>
#include <queue>
using namespace std;
typedef long long ll;
int n;
vector<pair<int, int > > v;
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    int l, r;
    for(int i = 0; i < n; i ++){
        cin >> l >> r;
        v.push_back(make_pair(l, r));
    }
    sort(v.begin(), v.end());
    int f = -1, s = -1;
    for(int i = 0; i < (int)v.size(); i ++){
        l = v[i].first;
        r = v[i].second;
        if(f > s){
            swap(f, s);
        }
        if(f < l){
            f = r;
            continue;
        }
        if(s  < l){
            s = r;
            continue;
        }
        return 0 * printf("NO");
    }
    printf("YES");
    return 0;

}


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

struct piyush{
    long long int st;
    long long int end;
};
bool cmp(piyush a,piyush b)
{
    return b.st>a.st;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1,tv2=-1;
    sort(a,a+n,cmp);
    tv1=a[0].end;
    long long int z=1;
    for(i=1;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    int st;
    int end;
};
bool cmp(piyush a,piyush b)
{
    return b.st>a.st;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1,tv2=-1;
    tv1=a[0].end;
    sort(a,a+n,cmp);
    long long int z=1;
    for(i=1;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    long long int st;
    long long int end;
};
bool cmp(piyush a,piyush b)
{
    return b.st>a.st;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1,tv2=-1;
    tv1=a[0].end;
    sort(a,a+n,cmp);
    long long int z=1;
    for(i=1;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    long long int st;
    long long int end;
};
bool cmp(piyush a,piyush b)
{
    if(b.st!=a.st)
    return b.st>a.st;
    else
    return b.end>a.end;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1,tv2=-1;
    tv1=a[0].end;
    sort(a,a+n,cmp);
    long long int z=1;
    for(i=0;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    long long int st;
    long long int end;
};
bool cmp(piyush a,piyush b)
{
    if(b.st!=a.st)
    return b.st>a.st;
    else
    return b.end>a.end;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1=-1,tv2=-1;
    sort(a,a+n,cmp);
    long long int z=1;
    for(i=0;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    int st;
    int end;
};
bool cmp(piyush a,piyush b)
{
    return b.st>a.st;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    sort(a,a+n,cmp);
    long long int z=0;
    for(i=1;i<n;i++)
    {
        if(a[i].st>=a[i-1].end)
        z++;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==n-1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

struct piyush{
    long long int st;
    long long int end;
};
bool cmp(piyush a,piyush b)
{
    if(b.st!=a.st)
    return b.st>a.st;
    else
    return b.end>a.end;
}
int main()
{
    long long int n,i,j,k,t;
    scanf("%lld",&n);
    piyush a[n];
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&j,&k);
        a[i].st=j;
        a[i].end=k;
    }
    long long int tv1,tv2=-1;
    tv1=a[0].end;
    sort(a,a+n,cmp);
    long long int z=1;
    for(i=1;i<n;i++)
    {
        if(a[i].st>tv1)
        {
            tv1=a[i].end;
        }
        else if(a[i].st>tv2)
        {
            tv2=a[i].end;
        }
        else
        z=0;
        //cout<<a[i].st<<" "<<a[i].end<<endl;
    }
    if(z==1)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 6e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[6194304];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 2e6 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 5e6 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 6e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[8194304];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 4e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N << 2];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 6e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N << 2];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 2e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 6e5 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[450000];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 2e6 + 7;

int n, b[MAX_N];

struct Node {
	int l, r;
	bool operator < (const Node & rhs) const {
		return l < rhs.l;
	}
} a[MAX_N];

struct S {
	struct segement_tree{
		int l, r;
		ll sum, add;
	} t[MAX_N << 2];
	#define ls(p) (p << 1)
	#define rs(p) (p << 1 | 1)
	inline void build (int p, int l, int r) {
		t[p].l = l; t[p].r = r;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build (ls(p), l, mid);
		build (rs(p), mid + 1, r);
	}
	inline void push_up(int p){
		if(t[p].add)
		{
			t[ls(p)].add += t[p].add;
			t[rs(p)].add += t[p].add;
			t[ls(p)].sum += (t[ls(p)].r - t[ls(p)].l + 1) * t[p].add;
			t[rs(p)].sum += (t[rs(p)].r - t[rs(p)].l + 1) * t[p].add;
			t[p].add = 0;
		}
	}

	void change(int p, int l, int r, int v){
		if(l <= t[p].l && t[p].r <= r) {
			t[p].sum += 1ll * (t[p].r - t[p].l + 1) * v;
			t[p].add += v;
			return ;
		}
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		if(l <= mid)
			change(ls(p), l, r, v);
		if(r > mid)
			change(rs(p), l, r, v);
		t[p].sum = (t[ls(p)].sum + t[rs(p)].sum);
	}

	ll query(int p, int l, int r){
		if(l <= t[p].l && t[p].r <= r) return t[p].sum;
		push_up(p);
		ll mid = (t[p].l + t[p].r) >> 1;
		ll ans = 0;
		if(l <= mid)
			ans += query(ls(p), l, r);
		if(r > mid)
			ans += query(rs(p), l, r);
		return ans;
	}
} A, B;

int main() {
	n = read ();
	int cnt = 0;
	for (int i = 1; i <= n; i ++ ) {
		a[i].l = read ();
		a[i].r = read ();
		b[++cnt] = a[i].l;
		b[++cnt] = a[i].r;
	}
	sort (b + 1, b + cnt + 1);
	int num = unique (b + 1, b + cnt + 1) - b - 1;
	int N = b[num];
	A.build (1, 1, N); B.build (1, 1, N);
	sort (a + 1, a + n + 1);
	for (int i = 1; i <= n; i ++ ) {
		if (A.query (1, a[i].l, a[i].r) && B.query (1, a[i].l, a[i].r)) {
			puts ("NO");
			return 0;
		}
		else {
			if (A.query (1, a[i].l, a[i].r)) {
				B.change(1, a[i].l, a[i].r, 1);
			} else {
				A.change (1, a[i].l, a[i].r, 1);
			}
		}
	}
	puts ("YES");
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x > y ? y : x;}

typedef long long ll;

const int INF = 2139062143;

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl

inline ll read() {
    ll f = 1, x = 0;char ch;
    do {ch = getchar();if (ch == '-')f = -1;} while (ch > '9' || ch < '0');
    do {x = x * 10 + ch - '0';ch = getchar();} while (ch >= '0' && ch <= '9');
    return f * x;
}

const int MAX_N = 2e5 + 7;

int n;

map < int, int > mp;

int main() {
	n = read ();
	for (int i = 1; i <= n; i ++ ) {
		int l = read (), r = read ();
		mp[l] ++ ;
		mp[r + 1] -- ;
	}
	int now = 0;
	for (map < int , int > :: iterator iter = mp.begin(); iter != mp.end(); iter ++ ) {
		now += (iter -> second);
		if (now > 2) {
			puts ("NO");
			return 0;
		}
	}
	puts ("YES");
	return 0;
}


//in the name of ALlah

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

#define pb push_back
#define pp pop_back
#define ll long long
#define ull unsigned ll
#define ld long double
#define mp make_pair
#define X first
#define Y second

typedef pair <ll,ll> pii;
typedef pair <pii,int> piii;

const  ull  MOD = 1e9+7, INF = 1e6 , MAXN = 1e5+1;

int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<pii> v;
	for(int i=1;i<=n;i++){
		ll a,b;
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	map<ll,int> mpp;
	sort(v.begin(),v.end());
	ll start= (v[0].X);
	ll end = v[v.size()-1].Y;
	ll k=0;
	for (int i=start;i<=end;i++){
		for(int j=k;j<v.size();j++){
			if (v[j].X<=i && i<=v[j].Y){
				mpp[i]++;
				if (mpp[i]>2){
					cout<<"NO";
					return 0;
				}

			}
			else{
				k=(k-1);
				break;
			}
		}
	}
	cout<<"YES";

}


//in the name of god
#include <bits/stdC++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,char> pic;
typedef pair<pic,int> pici;
const int delta=(int)1e9+7;
set<pic>s; map<int,int>p1,p2;
int main(){
	int a,n,m=0; cin>>n; pic b;
	while(n--){
		cin>>a;
		p1[a]++;
		s.insert(pic(a,'a'));
		cin>>a;
		p2[a]++;
		s.insert(pic(a,'b'));
	}
	set<pic>::iterator x=s.begin();
	while(x!=s.end()){
		b=*x;
		if(b.S=='a'){
			m+=p1[b.F];
			if(m>2){
				cout<<"NO";
				return 0;
			}
		}
		else{
			if(m>2){
				cout<<"NO";
				return 0;
			}
			m-=p2[b.F];
		}
		x++;
	}
	cout<<"YES";
	return 0;
}


//in the name of ALlah

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

#define pb push_back
#define pp pop_back
#define ll long long
#define ull unsigned ll
#define ld long double
#define mp make_pair
#define X first
#define Y second

typedef pair <ll,ll> pii;
typedef pair <pii,int> piii;

const  ull  MOD = 1e9+7, INF = 1e6 , MAXN = 1e5+1;

int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<pii> v;
	for(int i=1;i<=n;i++){
		ll a,b;
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	map<ll,int> mpp;
	sort(v.begin(),v.end());
	ll start= (v[0].X);
	ll end = v[v.size()-1].Y;
	ll k=0;
	for (int i=start;i<=end;i++){
		for(int j=k;j<v.size();j++){
			if (v[j].X<=i && i<=v[j].Y){
				mpp[i]++;
				if (mpp[i]>2){
					cout<<"NO";
					return 0;
				}

			}
			else{
				k=(j-1);
				break;
			}
		}
	}
	cout<<"YES";

}


//in the name of ALlah

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

#define pb push_back
#define pp pop_back
#define ll long long
#define ull unsigned ll
#define ld long double
#define mp make_pair
#define X first
#define Y second

typedef pair <ll,ll> pii;
typedef pair <pii,int> piii;

const  ull  MOD = 1e9+7, INF = 1e6 , MAXN = 1e5+1;

int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<pii> v;
	for(int i=1;i<=n;i++){
		ll a,b;
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	map<ll,int> mpp;
	sort(v.begin(),v.end());
	ll start= (v[0].X);
	ll end = v[v.size()-1].Y;
	ll k=0;
	for (int i=start;i<=end;i++){
		for(int j=k;j<v.size();j++){
			if (v[j].X<=i && i<=v[j].Y){
				mpp[i]++;
				if (mpp[i]>2){
					cout<<"NO";
					return 0;
				}

			}
			else{
				k=j;
				break;
			}
		}
	}
	cout<<"YES";

}


//in the name of ALlah

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

#define pb push_back
#define pp pop_back
#define ll long long
#define ull unsigned ll
#define ld long double
#define mp make_pair
#define X first
#define Y second

typedef pair <int,int> pii;
typedef pair <pii,int> piii;

const  ull  MOD = 1e9+7, INF = 1e6 , MAXN = 1e5+1;

int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<pii> v;
	for(int i=1;i<=n;i++){
		int a,b;
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	map<int,int> mpp;
	sort(v.begin(),v.end());
	int start= (v[0].X);
	int end = v[v.size()-1].Y;
	int k=0;
	for (int i=start;i<=end;i++){
		for(int j=k;true;j++){
			if (v[j].X<=i && i<=v[j].Y){
				mpp[i]++;
				if (mpp[i]>2){
					cout<<"NO";
					return 0;
				}

			}
			else{
				k=(j-1);
				break;
			}
		}
	}
	cout<<"YES";

}


//in the name of ALlah

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

#define pb push_back
#define pp pop_back
#define ll long long
#define ull unsigned ll
#define ld long double
#define mp make_pair
#define X first
#define Y second

typedef pair <ll,ll> pii;
typedef pair <pii,int> piii;

const  ull  MOD = 1e9+7, INF = 1e6 , MAXN = 1e5+1;

int main (){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	vector<pii> v;
	for(int i=1;i<=n;i++){
		ll a,b;
		cin >> a >> b;
		v.pb(mp(a,b));
	}
	map<ll,int> mpp;
	sort(v.begin(),v.end());
	ll start= (v[0].X);
	ll end = v[v.size()-1].Y;
	ll k=0;
	for (int i=start;i<=end;i++){
		for(int j=k;j<=v.size();j++){
			if (v[j].X<=i && i<=v[j].Y){
				mpp[i]++;
				if (mpp[i]>2){
					cout<<"NO";
					return 0;
				}

			}
			else{
				k=(j-1);
				break;
			}
		}
	}
	cout<<"YES";

}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define sz(a) a.size()
#define endl '\n'
#define inf int(1e9)
#define mod inf+7
#define fastio std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i,a,b) for( int i=a; i<b; i++)
#define ii pair < ll , ll >
#define F first
#define S second
#define input freopen("C:\\Users\\ASUS\\Desktop\\input.txt","r+",stdin)
#define output freopen("C:\\Users\\ASUS\\Desktop\\output.txt","w+",stdout)
#define debug input; output

using namespace std;

 int main()
   {
     int n;
     cin>> n;
     ii t[200005];
     rep(i,0,n)
     cin>>t[i].F>>t[i].S;
     sort(t,t+n);
     ii a,b;
     a.S=-1;
     b.S=-1;
     for(int  i=0;i<n;i++)
     {
       if (t[i].F>a.S)
         a=t[i];
       else if (t[i].F>b.S)
        b=t[i];
       else
       {
         cout<<"NO"; return 0;
       }
     }

     cout<<"YES";return 0;
   }


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
//fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
sort(t.begin(),t.end());
pair<int,int>a,b;
a.s=0;b.s=0;
por(i,0,n){
    if(a.s<t[i].f) a=t[i];
    else if(b.s<t[i].f) b=t[i];
    else{cout<<"NO";return 0;}

}
cout<<"YES";

return 0;}


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
//fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
//por(i,0,n) cout<<t[i].f<<" "<<t[i].s<<endl;
sort(t.begin(),t.end());
//por(i,0,n) cout<<t[i].f<<" "<<t[i].s<<endl;
//cout<<1<<endl;
por(i,1,n) if(t[i-1].f==t[i].f){cout<<"NO";return 0;}
//cout<<2<<endl;
por(i,1,n) if(t[i].f<t[i-1].s){cout<<"NO";return 0;}
cout<<"YES";

return 0;}


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
sort(t.begin(),t.end());
pair<int,int>a,b;
a.s=0;b.s=0;
por(i,0,n){
    if(a.s<t[i].f) a=t[i];
    else if(b.s<t[i].f) b=t[i];
    else{cout<<"NO";return 0;}

}
cout<<"YES";

return 0;}


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
//por(i,0,n) cout<<t[i].f<<" "<<t[i].s<<endl;
sort(t.begin(),t.end());
//por(i,0,n) cout<<t[i].f<<" "<<t[i].s<<endl;
//cout<<1<<endl;
por(i,1,n) if(t[i-1].f==t[i].f){cout<<"NO";return 0;}
//cout<<2<<endl;
por(i,1,n) if(t[i].f<t[i-1].s){cout<<"NO";return 0;}
cout<<"YES";

return 0;}


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
//fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
sort(t.begin(),t.end());
pair<int,int>a,b;
a.s=0;b.s=0;
por(i,0,n){
    if(a.s<t[i].f) a=t[i];
    else if(b.s<t[i].f) b=t[i];
    else cout<<"NO";}
cout<<"YES";return 0;}


#include<bits/stdc++.h>
#define por(i,a,b) for(i=a;i<b;i++)
#define fich(ch) freopen(ch,"r",stdin);
#define ll long long
#define f first
#define s second
#define pb push_back
#define vite ios::sync_with_stdio(0);cin.tie(0)
using namespace std;

int main(){
vite;
//fich("abc.txt");
ll n,i,j;cin>>n;
vector<pair<int,int>>t(n);
por(i,0,n) cin>>t[i].f>>t[i].s;
sort(t.begin(),t.end());
pair<int,int>a,b;
a.s=-1;b.s=-1;
por(i,0,n){
    if(a.s<t[i].f) a=t[i];
    else if(b.s<t[i].f) b=t[i];
    else{cout<<"NO";return 0;}

}
cout<<"YES";

return 0;}


#include <iostream>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];
void qsort(int x, int y)
{
    int l=x, r=y, mid=show[(l+r)/2].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    qsort(1,n);
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }

        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;

            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;

                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
        if (TV_on[0] && TV_on[1]) BothNotAvail=true;
    }
    if (BothNotAvail) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];
void qsort(int x, int y)
{
    int l=x, r=y, ind=rand()%(r-l+1)+1, mid;
    mid=show[ind].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
bool acompare (TVProgram A, TVProgram B)
{
    return (A.left<B.left);
}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;

    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    sort(show+1,show+1+n,acompare);
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }

        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;

            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;

                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
    }
    if (BothNotAvail) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];

void qsort(int x, int y)
{
    int l=x, r=y, ind=l+rand()%(r-l+1)+1, mid;
    mid=show[ind].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
bool acompare (TVProgram A, TVProgram B)
{
    return (A.left<B.left);
}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;

    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    qsort(1,n);
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }

        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;

            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;

                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
    }
    if (BothNotAvail) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>
#include <stdlib.h>
#include <algorithm>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];

void qsort(int x, int y)
{
    int l=x, r=y, ind=l+rand()%(r-l+1)+1, mid;
    mid=show[ind].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
bool acompare (TVProgram A, TVProgram B)
{
    return (A.left<B.left);
}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;

    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    qsort(1,n)
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }

        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;

            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;

                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
    }
    if (BothNotAvail) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];
void qsort(int x, int y)
{
    int l=x, r=y, mid=show[(l+r)/2].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    qsort(1,n);
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }

        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;

            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;

                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
    }
    if (BothNotAvail) cout<<"NO";
    else cout<<"YES";
    return 0;
}


#include <iostream>
#define maxN 200004

using namespace std;
struct TVProgram
{
    int left, right;
} show[maxN];
void qsort(int x, int y)
{
    int l=x, r=y, mid=show[(l+r)/2].left;
    while (l<=r)
    {
        while (show[l].left<mid) l++;
        while (mid<show[r].left) r--;
        if (l<=r)
        {
            swap(show[l],show[r]);
            l++;
            r--;
        }
    }
    if (x<r) qsort(x,r);
    if (l<y) qsort(l,y);

}
int main()
{
    int n, tvnum=0, TV_stop[2];
    bool TV_on[2]={false,false}, BothNotAvail=false;
    cin>>n;
    for (int i=1; i<=n; i++)
        cin>>show[i].left>>show[i].right;
    show[0].left=0;
    show[0].right=0;
    qsort(1,n);
    for (int i=1; i<=n; i++)
    {
        if (BothNotAvail)
        {
            cout<<"NO";
            return 0;
        }
        if (!TV_on[tvnum])
        {
            TV_on[tvnum]=true;
            TV_stop[tvnum]=show[i].right;
        }
        else
        {
            if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
            else tvnum=1-tvnum;
            if (!TV_on[tvnum])
            {
                TV_on[tvnum]=true;
                TV_stop[tvnum]=show[i].right;
            }
            else
            {
                if (show[i].left>TV_stop[tvnum]) TV_on[tvnum]=false;
                if (!TV_on[tvnum])
                {
                    TV_on[tvnum]=true;
                    TV_stop[tvnum]=show[i].right;
                }
                else BothNotAvail=true;
            }
        }
    }
    cout<<"YES";
    return 0;
}