> File Name: 5820.cpp
> Author: jiangyuzhu
> Mail: 834138558@qq.com
> Created Time: 2016/8/21 10:50:44
************************************************************************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 5e5 + 5, maxm = 20 * maxn;
int lson[maxm], rson[maxm], t[maxm], tree[maxm];
int c = 5e4, tot;
int build(int l, int r)
{
int root = tot++; tree[root] = 0;
int mid = l + r >> 1;
if(l == r) return root;
lson[root] = build(l, mid);
rson[root] = build(mid + 1, r);
return root;
}
int update(int root, int l, int r, int num)
{
int newroot = tot++;
tree[newroot] = tree[root] + 1;
if(l == r) return newroot;
int mid = l + r >> 1;
if(num <= mid){
lson[newroot] = update(lson[root], l, mid, num);
rson[newroot] = rson[root];
}else{
rson[newroot] = update(rson[root], mid + 1, r, num);
lson[newroot] = lson[root];
}
return newroot;
}
int query(int L, int R, int l, int r, int i)
{
if(l == L && r == R) return tree[i];
int mid = l + r >> 1;
if(R <= mid) return query(L, R, l, mid, lson[i]);
else if(L > mid) return query(L, R, mid + 1, r, rson[i]);
else return query(L, mid, l, mid, lson[i]) + query(mid + 1, R, mid + 1, r, rson[i]);
}
vector<int>v[maxn];
int pre[maxn];
int main (void)
{
int n;
while(~scanf("%d", &n) && n){
int x, y;
tot = 0;
for(int i = 1; i <= c; i++) v[i].clear();
memset(pre, 0, sizeof(pre));
for(int i = 0; i < n; i++){
scanf("%d%d", &x, &y);
v[x].push_back(y);
}
for(int i = 1; i <= c; i++){
if(!v[i].size()) continue;
sort(v[i].begin(), v[i].end());
v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
}
int up, down;
bool flag = true;
t[0] = build(1, c);
for(int i = 1; i <= c; i++){
t[i] = t[i - 1];
int sz = v[i].size();
if(!sz) continue;
for(int j = 0; j < sz; j++){
y = v[i][j];
up = j ? v[i][j - 1]:0;
down = j == v[i].size() - 1?c + 1:v[i][j + 1];
int cnt1 = query(up + 1, down - 1, 1, c, t[pre[y]]);
int cnt2 = query(up + 1, down - 1, 1, c, t[i]);
if(cnt1 != cnt2) flag = false;
if(!flag) break;
}
if(!flag) break;
for(int j = 0; j < sz; j++){
t[i] = update(t[i], 1, c, v[i][j]);
pre[v[i][j]] = i;
}
}
if(flag) puts("YES");
else puts("NO");
}
return 0;
}