#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <algorithm>

using namespace std;

int			n;
vector<int> v;
int main(void){
	#ifndef ONLINE_JUDGE
	freopen("source.txt","r",stdin);
	#endif
	cin>>n;
	for(int i=0,x; i<n;i++){
		cin>>x;
		v.push_back(x);
	}
	int r=1;
	while(r==n-2){
		int max=0,min=0;
		if(r%2==0){
			for(int j=1;j<n;j++){
				if(v[j]>v[max])
					max=j;
			}
			if(max==min)
				max++;

		v.erase(v.begin()+max);
	}
	if(r%2){
		for(int j=1;j<n;j++){
			if(v[j]<v[min])
				min=j;
		}
		v.erase(v.begin()+min);
	}
	r++;

	}
	cout<<v[0]<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

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


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

int main(){
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> number;
        storageNumber[i]=number;
    }
    sort(storageNumber, storageNumber+n);
    int a=0;
    for(i=1,j=0;i<n;i++){
      storageNumber[n-j]=0;
      j++;
      i++;
      storageNumber[a]=0;
      a++;
    }
    for(i=1;i<=n;i++){
        if(storageNumber[i]!=0){
            cout<<storageNumber[i];
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

int main(){
    cin >> n;
    for(i=0;i<n;i++){
        cin >> number;
        storageNumber[i]=number;
    }
    sort(storageNumber, storageNumber+n);
    int a=0;
    for(i=1,j=1;i<n;i++){
      storageNumber[n-j]=0;
      j++;
      i++;
      storageNumber[a]=0;
      a++;
    }
    for(i=0;i<n;i++){
        if(storageNumber[i]!=0){
            cout<<storageNumber[i];
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

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


#include <bits/stdc++.h>

using namespace std;

int i,n,number;
int storageNumber[1001];

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


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

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


#include <bits/stdc++.h>

using namespace std;

int i,j,n,number;
int storageNumber[1001];

int main(){
    cin >> n;
    for(i=1;i<=n;i++){
        cin >> number;
        storageNumber[i]=number;
    }
    sort(storageNumber, storageNumber+n);
    int a=1;
    for(i=1,j=0;i<n;i++){
      storageNumber[n-j]=0;
      j++;
      i++;
      storageNumber[a]=0;
      a++;
    }
    for(i=1;i<=n;i++){
        if(storageNumber[i]!=0){
            cout<<storageNumber[i];
        }
    }
}


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

int main ()
{
    int n;
    cin>>n;
    int arr[n];

    for(int i=0; i<n; i++)
        cin>>arr[i];
    sort(arr, arr+n);

    cout<<arr[n/2];

    return 0;
}


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

int main ()
{
    int n;
    cin>>n;
    int arr[n], l=n;

    while(l--)
        cin>>arr[l];

    sort(arr, arr+n);

    l=n/2;
    if(n%2!=0)
        cout<<arr[l];
    else
        cout<<arr[l-1];

    return 0;
}


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

int main ()
{
    int n;
    cin>>n;
    int arr[n], l=n;

    while(l--)
        cin>>arr[l];

    sort(arr, arr+n);

    l=n/2;
    if(n%2!=0)
        cout<<arr[l];
    else
        cout<<arr[l+1];

    return 0;
}


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

int main ()
{
    int n;
    cin>>n;
    int arr[n], l=n;

    while(l--)
        cin>>arr[l];

    sort(arr, arr+n);

    cout<<arr[n/2];

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;  i<n; i++)
	{
		cin>>arr[i];
	}
	sort(arr, arr+n);
	int i=0, j=n-1;
	while(i<j)
	{
		i++;
		j--;
		if(i==j)
		{
			cout<<arr[i];
			break;
		}
	}
	cout<<endl;
}


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

	}

	cout<<endl;
}


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

	}
	cout<<arr[i];
	cout<<endl;
}


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

	}

	cout<<endl;
}


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

	}
	cout<<arr[i];
	cout<<endl;
}


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

const int N = int(2e5 + 5);
const int M = int(1e5);

struct rr {
	int ans;
	rr *l, *r;
	rr() : ans(0), l(NULL), r(NULL) { }
};

typedef rr * prr;

prr root = new rr();

void build(prr v, int tl, int tr) {
	if(tl == tr) {
		return;
	} else {
		int tm = (tl + tr) >> 1;
		v -> l = new rr();
		build(v -> l, tl, tm);
		v -> r = new rr();
		build(v -> r, tm + 1, tr);
	}
}

void update(prr v, int tl, int tr, int l, int r, int q) {
	if(l > r) {
		return;
	}
	if(tl == l && tr == r) {
		v -> ans = max(v -> ans, q);
	} else {
		int tm = (tl + tr) >> 1;
		update(v -> l, tl, tm, l, min(tm, r), q);
		update(v -> r, tm + 1, tr, max(tm + 1, l), r, q);
		v -> ans = max(v -> ans, max(v -> l -> ans, v -> r -> ans));
	}
}

int get(prr v, int tl, int tr, int l, int r) {
	if(l > r) {
		return 0;
	}
	if(tl == l && tr == r) {
		return v -> ans;
	} else {
		int tm = (tl + tr) >> 1;
		return max(v -> ans, max(get(v -> l, tl, tm, l, min(tm, r)), get(v -> r, tm + 1, tr, max(tm + 1, l), r)));
	}
}

int n;
vector<pair<int, int> > g[N], ans;
int it[N];

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if(a.first != b.first) {
		return a.first < b.first;
	}
	return a.second < b.second;
}

int main (int argc, char *argv[])
{
	build(root, 0, M);
	scanf("%d", &n);
	ans.resize(n);
	memset(it, 0, sizeof(it));
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int s = y - x + M;
		g[s].push_back(make_pair(x, y));
	}
	for(int i = 0; i < N; ++i) {
		if(g[i].size()) {
			sort(g[i].begin(), g[i].end(), cmp);
		}
	}
	for(int i = 0; i < n; ++i) {
		int w;
		scanf("%d", &w);
		w += M;
		if(it[w] != g[w].size()) {
			ans[i].first = g[w][it[w]].first;
			ans[i].second = g[w][it[w]].second;
			it[w]++;
		} else {
			printf("NO");
			return 0;
		}
	}
	int mx = 0;
	for(int i = 0; i < n; ++i) {
		int q = get(root, 0, M, ans[i].first, M);
		if(q > ans[i].second && ans[i].first <= mx) {
			printf("NO");
			return 0;
		}
		mx = max(mx, ans[i].first);
		update(root, 0, M, ans[i].first, M, ans[i].second);
	}

	printf("YES\n");
	for(int i = 0; i < n; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}

	return 0;
}


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

const int N = int(2e5 + 5);
const int M = int(1e5);

struct rr {
	int ans;
	rr *l, *r;
	rr() : ans(0), l(NULL), r(NULL) { }
};

typedef rr * prr;

prr root = new rr();

void build(prr v, int tl, int tr) {
	if(tl == tr) {
		return;
	} else {
		int tm = (tl + tr) >> 1;
		v -> l = new rr();
		build(v -> l, tl, tm);
		v -> r = new rr();
		build(v -> r, tm + 1, tr);
	}
}

void update(prr v, int tl, int tr, int l, int r, int q) {
	if(l > r) {
		return;
	}
	if(tl == l && tr == r) {
		v -> ans = max(v -> ans, q);
	} else {
		int tm = (tl + tr) >> 1;
		update(v -> l, tl, tm, l, min(tm, r), q);
		update(v -> r, tm + 1, tr, max(tm + 1, l), r, q);
		v -> ans = max(v -> ans, max(v -> l -> ans, v -> r -> ans));
	}
}

int get(prr v, int tl, int tr, int l, int r) {
	if(l > r) {
		return 0;
	}
	if(tl == l && tr == r) {
		return v -> ans;
	} else {
		int tm = (tl + tr) >> 1;
		return max(v -> ans, max(get(v -> l, tl, tm, l, min(tm, r)), get(v -> r, tm + 1, tr, max(tm + 1, l), r)));
	}
}

int n;
vector<pair<int, int> > g[N], ans;
int it[N];

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if(a.first != b.first) {
		return a.first < b.first;
	}
	return a.second < b.second;
}

int main (int argc, char *argv[])
{
	build(root, 0, M);
	scanf("%d", &n);
	ans.resize(n);
	memset(it, 0, sizeof(it));
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int s = y - x + M;
		g[s].push_back(make_pair(x, y));
	}
	for(int i = 0; i < N; ++i) {
		if(g[i].size()) {
			sort(g[i].begin(), g[i].end(), cmp);
		}
	}
	for(int i = 0; i < n; ++i) {
		int w;
		scanf("%d", &w);
		w += M;
		if(it[w] != g[w].size()) {
			ans[i].first = g[w][it[w]].first;
			ans[i].second = g[w][it[w]].second;
			it[w]++;
		} else {
			printf("NO");
			return 0;
		}
	}
	int mx = 0;
	for(int i = 0; i < n; ++i) {
		int q = get(root, 0, M, ans[i].first, M);
		if(q > ans[i].second && ans[i].first <= mx) {
			printf("NO");
			return 0;
		}
		mx = max(mx, ans[i].first);
		update(root, 0, M, 0, ans[i].first, ans[i].second);
	}

	printf("YES\n");
	for(int i = 0; i < n; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}

	return 0;
}


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

const int N = int(2e5 + 5);
const int M = int(1e5);

struct rr {
	int ans;
	rr *l, *r;
	rr() : ans(0), l(NULL), r(NULL) { }
};

typedef rr * prr;

prr root = new rr();

void build(prr v, int tl, int tr) {
	if(tl == tr) {
		return;
	} else {
		int tm = (tl + tr) >> 1;
		v -> l = new rr();
		build(v -> l, tl, tm);
		v -> r = new rr();
		build(v -> r, tm + 1, tr);
	}
}

void update(prr v, int tl, int tr, int l, int r, int q) {
	if(l > r) {
		return;
	}
	if(tl == l && tr == r) {
		v -> ans = max(v -> ans, q);
	} else {
		int tm = (tl + tr) >> 1;
		update(v -> l, tl, tm, l, min(tm, r), q);
		update(v -> r, tm + 1, tr, max(tm + 1, l), r, q);
		v -> ans = max(v -> ans, max(v -> l -> ans, v -> r -> ans));
	}
}

int get(prr v, int tl, int tr, int l, int r) {
	if(l > r) {
		return 0;
	}
	if(tl == l && tr == r) {
		return v -> ans;
	} else {
		int tm = (tl + tr) >> 1;
		return max(get(v -> l, tl, tm, l, min(tm, r)), get(v -> r, tm + 1, tr, max(tm + 1, l), r));
	}
}

int n;
vector<pair<int, int> > g[N], ans;
int it[N];

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if(a.first != b.first) {
		return a.first < b.first;
	}
	return a.second < b.second;
}

int main (int argc, char *argv[])
{
	build(root, 0, M);
	scanf("%d", &n);
	ans.resize(n);
	memset(it, 0, sizeof(it));
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int s = y - x + M;
		g[s].push_back(make_pair(x, y));
	}
	for(int i = 0; i < N; ++i) {
		if(g[i].size()) {
			sort(g[i].begin(), g[i].end(), cmp);
		}
	}
	for(int i = 0; i < n; ++i) {
		int w;
		scanf("%d", &w);
		w += M;
		if(it[w] != g[w].size()) {
			ans[i].first = g[w][it[w]].first;
			ans[i].second = g[w][it[w]].second;
			it[w]++;
		} else {
			printf("NO");
			return 0;
		}
	}
	int mx = 0;
	for(int i = 0; i < n; ++i) {
		int q = get(root, 0, M, ans[i].first, M);
		if(q > ans[i].second && ans[i].first <= mx) {
			printf("NO");
			return 0;
		}
		mx = max(mx, ans[i].first);
		update(root, 0, M, 0, ans[i].first, ans[i].second);
	}

	printf("YES\n");
	for(int i = 0; i < n; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}

	return 0;
}


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

const int N = int(2e5 + 5);
const int M = int(1e5);

int n;
vector<pair<int, int> > g[N], ans;
int it[N];

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if(a.first != b.first) {
		return a.first < b.first;
	}
	return a.second < b.second;
}

int main (int argc, char *argv[])
{
	scanf("%d", &n);
	ans.resize(n);
	memset(it, 0, sizeof(it));
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int s = y - x + M;
		g[s].push_back(make_pair(x, y));
	}
	for(int i = 0; i < N; ++i) {
		if(g[i].size()) {
			sort(g[i].begin(), g[i].end(), cmp);
		}
	}
	for(int i = 0; i < n; ++i) {
		int w;
		scanf("%d", &w);
		w += M;
		if(it[w] != g[w].size()) {
			//cout << g[w][it[w]].first << " " << g[w][it[w]].second << endl;
			ans[i].first = g[w][it[w]].first;
			ans[i].second = g[w][it[w]].second;
			it[w]++;
		} else {
			printf("NO");
			return 0;
		}
	}
	for(int i = 1; i < n; ++i) {
		if(ans[i].first < ans[i - 1].first && ans[i].second < ans[i - 1].second) {
			printf("NO");
			return 0;
		}
	}
	printf("YES\n");
	for(int i = 0; i < n; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}

	return 0;
}


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

const int N = int(2e5 + 5);
const int M = int(1e5);

struct rr {
	int ans;
	rr *l, *r;
	rr() : ans(0), l(NULL), r(NULL) { }
};

typedef rr * prr;

prr root = new rr();

void build(prr v, int tl, int tr) {
	if(tl == tr) {
		return;
	} else {
		int tm = (tl + tr) >> 1;
		v -> l = new rr();
		build(v -> l, tl, tm);
		v -> r = new rr();
		build(v -> r, tm + 1, tr);
	}
}

void update(prr v, int tl, int tr, int l, int r, int q) {
	if(l > r) {
		return;
	}
	if(tl == l && tr == r) {
		v -> ans = max(v -> ans, q);
	} else {
		int tm = (tl + tr) >> 1;
		update(v -> l, tl, tm, l, min(tm, r), q);
		update(v -> r, tm + 1, tr, max(tm + 1, l), r, q);
		v -> ans = max(v -> ans, max(v -> l -> ans, v -> r -> ans));
	}
}

int get(prr v, int tl, int tr, int l, int r) {
	if(l > r) {
		return 0;
	}
	if(tl == l && tr == r) {
		return v -> ans;
	} else {
		int tm = (tl + tr) >> 1;
		return max(get(v -> l, tl, tm, l, min(tm, r)), get(v -> r, tm + 1, tr, max(tm + 1, l), r));
	}
}

int n;
vector<pair<int, int> > g[N], ans;
int it[N];

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
	if(a.first != b.first) {
		return a.first < b.first;
	}
	return a.second < b.second;
}

int main (int argc, char *argv[])
{
	build(root, 0, M);
	scanf("%d", &n);
	ans.resize(n);
	memset(it, 0, sizeof(it));
	for(int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		int s = y - x + M;
		g[s].push_back(make_pair(x, y));
	}
	for(int i = 0; i < N; ++i) {
		if(g[i].size()) {
			sort(g[i].begin(), g[i].end(), cmp);
		}
	}
	for(int i = 0; i < n; ++i) {
		int w;
		scanf("%d", &w);
		w += M;
		if(it[w] != g[w].size()) {
			ans[i].first = g[w][it[w]].first;
			ans[i].second = g[w][it[w]].second;
			it[w]++;
		} else {
			printf("NO");
			return 0;
		}
	}
	int mx = 0;
	for(int i = 0; i < n; ++i) {
		int q = get(root, 0, M, ans[i].first, M);
		if(q > ans[i].second) {
			printf("NO");
			return 0;
		}
		mx = max(mx, ans[i].first);
		update(root, 0, M, 0, ans[i].first, ans[i].second);
	}

	printf("YES\n");
	for(int i = 0; i < n; ++i) {
		printf("%d %d\n", ans[i].first, ans[i].second);
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define slli(n) scanf("%llid",&n)
#define lldout(n) printf("%llid\n",n)
const int N = (int)2e5 + 10;
//vvi v;
//lli vis[N];
//int vis1[52][52],v[52][52];
/*int dfs(int t){
	vis[t]=1;
	//v[i][j]=val;
	rep(i,0,v[t].size()){
		if(vis[t]==0){
			dfs(v[t][i]);
		}
	}
	// if(v[i][j-1]==-1 and vis1[i][j-1]==0 and v[i+1][j-1]!=v[i][j] and v[i][j-2]!=v[i][j] and v[i-1][j-1]!=v[i][j])dfs(i,j-1,val);
	// if(v[i][j+1]==-1 and vis1[i][j+1]==0 and v[i][j+2]!=v[i][j] and v[i+1][j+1]!=v[i][j] and v[i-1][j+1]!=v[i][j])dfs(i,j+1,val);
	// if(v[i-1][j]==-1 and vis1[i-1][j]==0 and v[i-1][j-1]!=v[i][j] and v[i-1][j+1]!=v[i][j] and v[i-2][j]!=v[i][j])dfs(i-1,j,val);
	// if(v[i+1][j]==-1 and vis1[i+1][j]==0 and v[i+2][j]!=v[i][j] and v[i+1][j-1]!=v[i][j] and v[i+1][j+1]!=v[i][j])dfs(i+1,j,val);
	// return 0;
}*/
lli lcm(lli a,lli b) { return a*(b/__gcd(a,b));}
lli pow(lli x, lli y, lli p) {
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
map<int,int> vis1,vis;
map<pair<int,int> ,int >  gg;
int main(){
	int n;
	cin>>n;
	vector<pair<int,int> > v;
	int w[n+5];
	int ans1[n+5],ans2[n+5];
	vector<int> v1;
	map<int,vector<int> > ph;
	int flag=0;
	//v.resize(n+5);
	rep(i,0,n){
		int x,y;
		cin>>x>>y;
		v.pb(mp(x,y));
		//v1.pb(mp(y,x));
	}
	rep(i,0,n){
		cin>>w[i];
		ph[w[i]].pb(i);
	//	ph[w[i]].pb(i);
//		ph1[w[i]]=0;
	}
	rep(i,0,n){
		if(vis[w[i]]==0)
		{sort(ph[w[i]].begin(),ph[w[i]].end());v1.pb(w[i]);}
		vis[w[i]]=1;
		//reverse(ph[w[i]].begin(),ph[w[i]].end());
	}
	rep(i,0,sz(v1)){
		int x,y;
		if(v1[i]>=0)
		 {x=0;y=v1[i];}
		else{x=-1*v1[i];y=0;}
		//if(vis1[w[i]]==0){
			rep(j,0,sz(ph[v1[i]])){
				ans1[ph[v1[i]][j]]=x;
				ans2[ph[v1[i]][j]]=y;
				gg[mp(x,y)]=1;
				//cout<<x<<" "<<y<<" "<<" "<<ph[v1[i]][j]<<endl;
				x+=1;y+=1;
			}
//		}
	}
	int m1=ans1[n-1];int m2=ans2[n-1];
	repv(i,0,n-1){
		//cout<<ans1[i]<<" "<<ans2[i]<<" "<<m1<<" "<<m2<<endl;
		if(ans1[i]>=m1 and ans2[i]>=m2){flag=1;break;}
		m1=max(m1,ans1[i]);
		m2=max(m2,ans2[i]);
	}
	rep(i,0,n){
		if(gg[v[i]]==0)flag=1;
	}
	if(flag==0){
		cout<<"YES"<<endl;
		rep(i,0,n)cout<<ans1[i]<<" "<<ans2[i]<<endl;
	}
	else cout<<"NO"<<endl;

/*	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	reverse(v.begin(),v.end());
	reverse(v1.begin(),v1.end());
	rep(i,0,n){
		if(w[n-i-1]!=v[i].second-v[i].first){cout<<i<<" "<<v[i].first<<" "<<v[i].second<<endl;flag=1;break;}
	}
	if(flag==0){
		cout<<"YES"<<endl;
		repv(i,0,n){
			cout<<v[i].first<<" "<<v[i].second<<endl;
		}
	}
	else{
		flag=0;
		rep(i,0,n){
			if(w[n-1-i]!=v1[i].second-v1[i].first){flag=1;break;}
		}
		if(flag==0){
			cout<<"YES"<<endl;
			repv(i,0,n){
				cout<<v1[i].first<<" "<<v1[i].second<<endl;
			}
		}
		else cout<<"NO"<<endl;
	}*/
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector< ii > vii;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef	vector<pair<int,pair<int,int > > > viii;
typedef long long int lli;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(a) (int)(a.size())

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define slli(n) scanf("%llid",&n)
#define lldout(n) printf("%llid\n",n)
const int N = (int)2e5 + 10;
//vvi v;
//lli vis[N];
//int vis1[52][52],v[52][52];
/*int dfs(int t){
	vis[t]=1;
	//v[i][j]=val;
	rep(i,0,v[t].size()){
		if(vis[t]==0){
			dfs(v[t][i]);
		}
	}
	// if(v[i][j-1]==-1 and vis1[i][j-1]==0 and v[i+1][j-1]!=v[i][j] and v[i][j-2]!=v[i][j] and v[i-1][j-1]!=v[i][j])dfs(i,j-1,val);
	// if(v[i][j+1]==-1 and vis1[i][j+1]==0 and v[i][j+2]!=v[i][j] and v[i+1][j+1]!=v[i][j] and v[i-1][j+1]!=v[i][j])dfs(i,j+1,val);
	// if(v[i-1][j]==-1 and vis1[i-1][j]==0 and v[i-1][j-1]!=v[i][j] and v[i-1][j+1]!=v[i][j] and v[i-2][j]!=v[i][j])dfs(i-1,j,val);
	// if(v[i+1][j]==-1 and vis1[i+1][j]==0 and v[i+2][j]!=v[i][j] and v[i+1][j-1]!=v[i][j] and v[i+1][j+1]!=v[i][j])dfs(i+1,j,val);
	// return 0;
}*/
lli lcm(lli a,lli b) { return a*(b/__gcd(a,b));}
lli pow(lli x, lli y, lli p) {
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
map<int,int> vis1,vis;
map<pair<int,int> ,int >  gg;
int main(){
	int n;
	cin>>n;
	vector<pair<int,int> > v;
	int w[n+5];
	int ans1[n+5],ans2[n+5];
	vector<int> v1;
	map<int,vector<int> > ph;
	int flag=0;
	//v.resize(n+5);
	rep(i,0,n){
		int x,y;
		cin>>x>>y;
		v.pb(mp(x,y));
		//v1.pb(mp(y,x));
	}
	rep(i,0,n){
		cin>>w[i];
		ph[w[i]].pb(i);
	//	ph[w[i]].pb(i);
//		ph1[w[i]]=0;
	}
	rep(i,0,n){
		if(vis[w[i]]==0)
		{sort(ph[w[i]].begin(),ph[w[i]].end());v1.pb(w[i]);}
		vis[w[i]]=1;
		//reverse(ph[w[i]].begin(),ph[w[i]].end());
	}
	rep(i,0,sz(v1)){
		int x,y;
		if(v1[i]>=0)
		 {x=0;y=v1[i];}
		else{x=-1*v1[i];y=0;}
		//if(vis1[w[i]]==0){
			rep(j,0,sz(ph[v1[i]])){
				ans1[ph[v1[i]][j]]=x;
				ans2[ph[v1[i]][j]]=y;
				gg[mp(x,y)]=1;
				//cout<<x<<" "<<y<<" "<<" "<<ph[v1[i]][j]<<endl;
				x+=1;y+=1;
			}
//		}
	}
	int m1=ans1[n-1];int m2=ans2[n-1];int m3=ans1[n-1];int m4=ans2[n-1];
	repv(i,0,n-1){
		//cout<<ans1[i]<<" "<<ans2[i]<<" "<<m1<<" "<<m2<<endl;
		if((ans1[i]>=m1 and ans2[i]>=m2) or (ans1[i]>=m3 and ans2[i]>=m4)){flag=1;break;}
		//m1=max(m1,ans1[i]);
		if(ans1[i]>m1){m1=ans1[i];m2=ans2[i];}
		if(ans2[i]>m4){m3=ans1[i];m4=ans2[i];}
		//m2=max(m2,ans2[i]);
	}
	rep(i,0,n){
		if(gg[v[i]]==0)flag=1;
	}
	if(flag==0){
		cout<<"YES"<<endl;
		rep(i,0,n)cout<<ans1[i]<<" "<<ans2[i]<<endl;
	}
	else cout<<"NO"<<endl;

/*	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	reverse(v.begin(),v.end());
	reverse(v1.begin(),v1.end());
	rep(i,0,n){
		if(w[n-i-1]!=v[i].second-v[i].first){cout<<i<<" "<<v[i].first<<" "<<v[i].second<<endl;flag=1;break;}
	}
	if(flag==0){
		cout<<"YES"<<endl;
		repv(i,0,n){
			cout<<v[i].first<<" "<<v[i].second<<endl;
		}
	}
	else{
		flag=0;
		rep(i,0,n){
			if(w[n-1-i]!=v1[i].second-v1[i].first){flag=1;break;}
		}
		if(flag==0){
			cout<<"YES"<<endl;
			repv(i,0,n){
				cout<<v1[i].first<<" "<<v1[i].second<<endl;
			}
		}
		else cout<<"NO"<<endl;
	}*/
	return 0;
}


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

const int maxn = 1e5 + 10;
int w[maxn], ans[maxn], mx[maxn << 1], anss[maxn];
vector<int> ind[maxn << 1], pi[maxn << 1];
pair<int, int> p[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        pi[p[i].second - p[i].first + maxn].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        ind[w[i] + maxn].push_back(i);
    }
    for (int i = 0; i < maxn * 2; ++i) if (ind[i].size()) {
        if (pi[i].size() != ind[i].size()) return cout << "NO" << endl, 0;
        sort(pi[i].begin(), pi[i].end(), [](const int& a, const int& b) {
            return p[a] < p[b];
        });
        for (int j = 0; j < ind[i].size(); ++j) ans[ind[i][j]] = pi[i][j], anss[pi[i][j]] = ind[i][j];
    }
    // vector<pair<int, int>> ps(p, p + n);
    vector<pair<pair<int, int>, int>> vec;
    for (int i = 0; i < n; ++i) vec.push_back(make_pair(p[i], i));
    sort(vec.begin(), vec.end());
    int cur = 0;
    for (int i = 0; i < maxn; ++i) {
        int ind = cur; while (vec[ind].first.first == i) ++ind;
        // if (ind > cur) cout << "ind = " << ind << " cur = " << cur << endl;
        for (int j = cur; j < ind; ++j) {
            mx[vec[j].first.second + maxn] = max(mx[vec[j].first.second + maxn], mx[vec[j].first.second - 1 + maxn]);
            if (anss[vec[j].second] < mx[vec[j].first.second + maxn]) return cout << "NO" << endl, 0;
            mx[vec[j].first.second + maxn] = max(mx[vec[j].first.second + maxn], anss[vec[j].second]);
        }
        cur = ind;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << p[ans[i]].first << ' ' << p[ans[i]].second << endl;
    return 0;

}


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

const int maxn = 1e5 + 10;
int w[maxn], ans[maxn], mx[maxn], anss[maxn];
vector<int> ind[maxn << 1], pi[maxn << 1];
pair<int, int> p[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        pi[p[i].second - p[i].first + maxn].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        ind[w[i] + maxn].push_back(i);
    }
    for (int i = 0; i < maxn * 2; ++i) if (ind[i].size()) {
        if (pi[i].size() != ind[i].size()) return cout << "NO" << endl, 0;
        sort(pi[i].begin(), pi[i].end(), [](const int& a, const int& b) {
            return p[a] < p[b];
        });
        for (int j = 0; j < ind[i].size(); ++j) ans[ind[i][j]] = pi[i][j], anss[pi[i][j]] = ind[i][j];
    }
    // vector<pair<int, int>> ps(p, p + n);
    vector<pair<pair<int, int>, int>> vec;
    for (int i = 0; i < n; ++i) vec.push_back(make_pair(p[i], i));
    sort(vec.begin(), vec.end());
    int cur = 0;
    for (int i = 0; i < maxn; ++i) {
        int ind = cur; while (ind < vec.size() && vec[ind].first.first == i) ++ind;
        // if (ind > cur) cout << "ind = " << ind << " cur = " << cur << endl;
        for (int j = cur; j < ind; ++j) {
            mx[vec[j].first.second] = max(mx[vec[j].first.second], mx[vec[j].first.second - 1]);
            if (anss[vec[j].second] < mx[vec[j].first.second]) return cout << "NO" << endl, 0;
            mx[vec[j].first.second] = max(mx[vec[j].first.second], anss[vec[j].second]);
        }
        cur = ind;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << p[ans[i]].first << ' ' << p[ans[i]].second << endl;
    return 0;

}


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

const int maxn = 1e5 + 10;
int w[maxn], ans[maxn];
vector<int> ind[maxn << 1], pi[maxn << 1];
pair<int, int> p[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        pi[p[i].second - p[i].first + maxn].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        ind[w[i] + maxn].push_back(i);
    }
    for (int i = 0; i < maxn * 2; ++i) if (ind[i].size()) {
        if (pi[i].size() != ind[i].size()) return cout << "NO" << endl, 0;
        sort(pi[i].begin(), pi[i].end(), [](const int& a, const int& b) {
            return p[a] < p[b];
        });
        for (int j = 0; j < ind[i].size(); ++j) ans[ind[i][j]] = pi[i][j];
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << p[ans[i]].first << ' ' << p[ans[i]].second << endl;
    return 0;

}


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

const int maxn = 1e5 + 10;
int w[maxn], ans[maxn], mx[maxn], anss[maxn];
vector<int> ind[maxn << 1], pi[maxn << 1];
pair<int, int> p[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        pi[p[i].second - p[i].first + maxn].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        ind[w[i] + maxn].push_back(i);
    }
    for (int i = 0; i < maxn * 2; ++i) if (ind[i].size()) {
        if (pi[i].size() != ind[i].size()) return cout << "NO" << endl, 0;
        sort(pi[i].begin(), pi[i].end(), [](const int& a, const int& b) {
            return p[a] < p[b];
        });
        for (int j = 0; j < ind[i].size(); ++j) ans[ind[i][j]] = pi[i][j], anss[pi[i][j]] = ind[i][j];
    }
    // vector<pair<int, int>> ps(p, p + n);
    vector<pair<pair<int, int>, int>> vec;
    for (int i = 0; i < n; ++i) vec.push_back(make_pair(p[i], i));
    sort(vec.begin(), vec.end());
    int cur = 0;
    for (int i = 0; i < maxn * 2; ++i) {
        int ind = cur; while (vec[ind].first.first == i) ++ind;
        // if (ind > cur) cout << "ind = " << ind << " cur = " << cur << endl;
        for (int j = cur; j < ind; ++j) {
            mx[vec[j].first.second] = max(mx[vec[j].first.second], mx[vec[j].first.second - 1]);
            if (anss[vec[j].second] < mx[vec[j].first.second]) return cout << "NO" << endl, 0;
            mx[vec[j].first.second] = max(mx[vec[j].first.second], anss[vec[j].second]);
        }
        cur = ind;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << p[ans[i]].first << ' ' << p[ans[i]].second << endl;
    return 0;

}


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

const int maxn = 1e5 + 10;
int w[maxn], ans[maxn], mx[maxn], anss[maxn];
vector<int> ind[maxn << 1], pi[maxn << 1];
pair<int, int> p[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> p[i].first >> p[i].second;
        pi[p[i].second - p[i].first + maxn].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        cin >> w[i];
        ind[w[i] + maxn].push_back(i);
    }
    for (int i = 0; i < maxn * 2; ++i) if (ind[i].size()) {
        if (pi[i].size() != ind[i].size()) return cout << "NO" << endl, 0;
        sort(pi[i].begin(), pi[i].end(), [](const int& a, const int& b) {
            return p[a] < p[b];
        });
        for (int j = 0; j < ind[i].size(); ++j) ans[ind[i][j]] = pi[i][j], anss[pi[i][j]] = ind[i][j];
    }
    // vector<pair<int, int>> ps(p, p + n);
    vector<pair<pair<int, int>, int>> vec;
    for (int i = 0; i < n; ++i) vec.push_back(make_pair(p[i], i));
    sort(vec.begin(), vec.end());
    int cur = 0;
    for (int i = 0; i < maxn; ++i) {
        int ind = cur; while (vec[ind].first.first == i) ++ind;
        // if (ind > cur) cout << "ind = " << ind << " cur = " << cur << endl;
        for (int j = cur; j < ind; ++j) {
            mx[vec[j].first.second] = max(mx[vec[j].first.second], mx[vec[j].first.second - 1]);
            if (anss[vec[j].second] < mx[vec[j].first.second]) return cout << "NO" << endl, 0;
            mx[vec[j].first.second] = max(mx[vec[j].first.second], anss[vec[j].second]);
        }
        cur = ind;
    }
    cout << "YES" << endl;
    for (int i = 1; i <= n; ++i) cout << p[ans[i]].first << ' ' << p[ans[i]].second << endl;
    return 0;

}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N; Si(N);
		m.clear();
		for(int i = 0; i < N; i++)
		{
			int x, y;
			Si(x); Si(y);
			m[y - x].push(node(x, y));
		}
		int x, y, cnt = 0;
		x = y = 0;
		bool is = true;
		for(int i = 0; i < N; i++)
		{
			int w;
			Si(w);
			if(!m[w].size())
			{
				is = false;
				break;
			}
			node no = m[w].top();
			m[w].pop();
			p[cnt++] = no;
			x = no.a, y = no.b;
		}
			if(is)
			{
				printf("YES\n");
				for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
			}
			else printf("NO\n");
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N; Si(N);
	m.clear();
	for(int i = 0; i < N; i++)
	{
		int x, y;
		Si(x); Si(y);
		m[y - x].push(node(x, y));
	}
	int x, y, cnt = 0;
	x = y = 0;
	for(int i = 0; i < N; i++)
	{
		int w; Si(w);
		if(!m[w].size())
		{
			printf("NO\n");
			return 0;
		}
		node no = m[w].top();
		if(no.a < x && no.b < y)
		{
			printf("NO\n");
			return 0;
		}
		m[w].pop();
		p[cnt++] = no;
	}
	printf("YES\n");
	for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N;Si(N);
		m.clear();
		for(int i = 0; i < N; i++)
		{
			int x, y;
			Si(x); Si(y);
			m[y - x].push(node(x, y));
		}
		int x, y, cnt = 0;
		x = -1, y = -1;
		bool is = true;
		for(int i = 0; i < N; i++)
		{
			int w;
			Si(w);
			if(!m[w].size())
			{
				is = false;
				break;
			}
			node no = m[w].top();
			if(no.a <= x && no.b <= y)
			{
				is = false;
				break;
			}
			m[w].pop();
			p[cnt++] = no;
			x = no.a, y = no.b;
		}
			if(is)
			{
				printf("YES\n");
				for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
			}
			else printf("NO\n");
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;//
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N; Si(N);
	m.clear();
	for(int i = 0; i < N; i++)
	{
		int x, y;
		Si(x); Si(y);
		m[y - x].push(node(x, y));
	}
	int x, y, cnt = 0;
	x = y = 0;
	for(int i = 0; i < N; i++)
	{
		int w; Si(w);
		if(!m[w].size())
		{
			printf("NO\n");
			return 0;
		}
		node no = m[w].top();
		if(no.a < x && no.b < y)
		{
			printf("NO\n");
			return 0;
		}
		m[w].pop();
		p[cnt++] = no;
	}
	printf("YES\n");
	for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N;
	while(Si(N) != EOF)
	{
	m.clear();
	for(int i = 0; i < N; i++)
	{
		int x, y;
		Si(x); Si(y);
		m[y - x].push(node(x, y));
	}
	int x, y, cnt = 0;
	x = y = 0;
	for(int i = 0; i < N; i++)
	{
		int w; Si(w);
		if(!m[w].size())
		{
			printf("NO\n");
			return 0;
		}
		node no = m[w].top();
		if(no.a < x && no.b < y)
		{
			printf("NO\n");
			return 0;
		}
		m[w].pop();
		p[cnt++] = no;
	}
	printf("YES\n");
	for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
	}
	return 0;
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (100000+10)
#define MAXM (50000000)
#define Si(a) scanf("%d", &a)
#define Sl(a) scanf("%lld", &a)
#define Sf(a) scanf("%lf", &a)
#define Ss(a) scanf("%s", a)
#define Sc(a) scanf(" %c", &a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define MOD 1000000007
#define LL long long
#define lson  l, mid, o<<1
#define rson mid+1, r, o<<1|1
#define lowbits(x) (x & -x)
using namespace std;
const int maxn = 100000 + 10;
struct node{
	int a, b;
	node(){}
	node(int a, int b){
		this->a = a;
		this->b = b;
	}
	bool operator < (const node & op) const{
		return  (a > op.a) && (b > op.b);
	}
};
map<int, priority_queue<node> > m;
node p[maxn];
int main(void)
{
	int N;Si(N);
		m.clear();
		for(int i = 0; i < N; i++)
		{
			int x, y;
			Si(x); Si(y);
			m[y - x].push(node(x, y));
		}
		int x, y, cnt = 0;
		x = y = 0;
		bool is = true;
		for(int i = 0; i < N; i++)
		{
			int w;
			Si(w);
			if(!m[w].size())
			{
				is = false;
				break;
			}
			node no = m[w].top();
			if(no.a <= x && no.b <= y)
			{
				is = false;
				break;
			}
			m[w].pop();
			p[cnt++] = no;
			x = no.a, y = no.b;
		}
			if(is)
			{
				printf("YES\n");
				for(int i = 0; i < cnt; i++)printf("%d %d\n", p[i].a, p[i].b);
			}
			else printf("NO\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <vector>
#include <string>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define xx first
#define yy second
const int mod = int(1e9) + 7, INF = 0x3fffffff, maxn = 1e5 + 40;
int n, m, a[maxn];
pii v[maxn], ans[maxn];
set<pii> st[maxn * 2];
set<pii>::iterator it;

int main(void) {
    scanf("%d", &n) ;
    for (int i = 0; i < n; i++)
        scanf("%d%d", &v[i].xx, &v[i].yy), st[v[i].yy - v[i].xx + maxn].insert(v[i]);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        a[i] += maxn;
    }
    bool ok = true;
    pii maxs(-INF, -INF);
    for (int i = 0; i < n; i++) {
        if (st[a[i]].empty()) {
            ok = false;
            break;
        }
        it = st[a[i]].begin();
        ans[i] = *it;
       st[a[i]].erase(it);
        if (ans[i].xx <= maxs.xx && ans[i].yy <= maxs.yy) {
            ok = false;
            break;
        }
        maxs = max(maxs, ans[i]);
    }
    if (ok) {
        puts("YES");
        for (int i = 0; i < n; i++) {
            printf("%d %d\n", ans[i].xx, ans[i].yy);
        }
    } else puts("NO");
    return 0;
}


#include <iostream>
#include <queue>
using namespace std;
const int N = 100000 + 10;
struct Nod {
    int x,y,id,ans;
    bool operator <(const Nod & o) const {
        return x+y < o.x+o.y;
    }
} nod[N];
bool cmp(Nod A, Nod B) {
    if(A.x==B.x) return A.y<B.y;
    return A.x<B.x;
}
int n,a[N<<1],res[N<<1];
int bit[N<<1],xx[N<<1],yy[N<<1];
void add(int x,int id) {
    while(x<N) {
        bit[x]=max(bit[x],id); x+=(x&(-x));
    }
}
int query(int x) {
    int ans=0; while(x) {ans=max(ans,bit[x]); x-=x&(-x);}
    return ans;
}
int main() {
    scanf("%d",&n);
    priority_queue<Nod> q[2*N];
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&nod[i].x,&nod[i].y); nod[i].id=i;
        q[nod[i].y-nod[i].x+N].push(nod[i]);
    }
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    //printf("ok\n");
    for(int i=n;i>=1;i--) {
        if(q[a[i]+N].size()==0) return !printf("NO\n");
        Nod now = q[a[i]+N].top(); q[a[i]+N].pop();
        res[now.id] = i;
    }
    for(int i=1;i<=n;i++) nod[i].ans = res[nod[i].id];
    //printf("ok\n");
    sort(nod+1,nod+1+n,cmp);

    bool ok = 1;
    for(int i=1;i<=n;i++) {
        if(query(nod[i].y+1)>nod[i].ans) ok=0;
        add(nod[i].y+1,nod[i].ans);
    }
    if(ok==0) return !printf("NO\n");
    printf("YES\n");
    for(int i=1;i<=n;i++) xx[nod[i].ans]=nod[i].x, yy[nod[i].ans]=nod[i].y;
    for(int i=1;i<=n;i++) printf("%d %d\n", xx[i],yy[i]);

}


#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int N = 100000 + 10;
struct Nod {
    int x,y,id,ans;
    bool operator <(const Nod & o) const {
        return x+y < o.x+o.y;
    }
} nod[N];
bool cmp(Nod A, Nod B) {
    if(A.x==B.x) return A.y<B.y;
    return A.x<B.x;
}
int n,a[N<<1],res[N<<1];
int bit[N<<1],xx[N<<1],yy[N<<1];
void add(int x,int id) {
    while(x<N) {
        bit[x]=max(bit[x],id); x+=(x&(-x));
    }
}
int query(int x) {
    int ans=0; while(x) {ans=max(ans,bit[x]); x-=x&(-x);}
    return ans;
}
int main() {
    scanf("%d",&n);
    priority_queue<Nod> q[2*N];
    for(int i=1;i<=n;i++) {
        scanf("%d%d",&nod[i].x,&nod[i].y); nod[i].id=i;
        q[nod[i].y-nod[i].x+N].push(nod[i]);
    }
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    //printf("ok\n");
    for(int i=n;i>=1;i--) {
        if(q[a[i]+N].size()==0) return !printf("NO\n");
        Nod now = q[a[i]+N].top(); q[a[i]+N].pop();
        res[now.id] = i;
    }
    for(int i=1;i<=n;i++) nod[i].ans = res[nod[i].id];
    //printf("ok\n");
    sort(nod+1,nod+1+n,cmp);

    bool ok = 1;
    for(int i=1;i<=n;i++) {
        if(query(nod[i].y+1)>nod[i].ans) ok=0;
        add(nod[i].y+1,nod[i].ans);
    }
    if(ok==0) return !printf("NO\n");
    printf("YES\n");
    for(int i=1;i<=n;i++) xx[nod[i].ans]=nod[i].x, yy[nod[i].ans]=nod[i].y;
    for(int i=1;i<=n;i++) printf("%d %d\n", xx[i],yy[i]);

}


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

using namespace std;

struct node
{
    int x,y;
    friend bool operator< (node a,node b)
    {
        if(a.x==b.x)
            return a.y<b.y;
        else
            return a.x<b.x;
    }

} p[100005],ans[100005];

int tp[100005];

set<int>s[200005];

int lb(int x)
{
    return x&(-x);
}

int c[100055];

void add(int x,int v)
{
    while(x<=100005)
    {
        c[x]=max(c[x],v);
        x+=lb(x);
    }
}

int qry(int x)
{
    int maxn=-1;
    while(x>=1)
    {
        maxn=max(maxn,c[x]);
        x-=lb(x);
    }
    return maxn;
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(c,-1,sizeof(c));

        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
            int w=p[i].y-p[i].x;
            s[w+100000].insert(p[i].x);
        }

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

        set<int>::iterator it;
        for(int i=0; i<n; i++)
        {
            int w=tp[i];
            it=s[w+100000].begin();
            while(1)
            {
                if(it==s[w+100000].end())
                {
                    f=0;
                    break;
                }

                int yy=(*it)+w;
                int xx=100005-(*it);
                s[w+100000].erase(it++);

                int maxy=qry(xx);
                if(maxy>=yy)
                {
                    it=s[w+100000].begin();
                }
                else
                {
                    ans[i].x=100005-xx;
                    ans[i].y=yy;
                    add(xx,yy);
                    break;
                }

            }
            if(f==0){
                //cout<<i<<endl;
                break;
            }
        }

        if(f==0)
            printf("NO\n");
        else
        {
            printf("YES\n");
            for(int i=0; i<n; i++)
            {
                printf("%d %d\n",ans[i].x,ans[i].y);
            }
        }

    }
}


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

using namespace std;

struct node
{
    int x,y;
    friend bool operator< (node a,node b)
    {
        if(a.x==b.x)
            return a.y<b.y;
        else
            return a.x<b.x;
    }

} p[100005],ans[100005];

int tp[100005];

set<int>s[200005];

int lb(int x)
{
    return x&(-x);
}

int c[100055];

void add(int x,int v)
{
    while(x<=100005)
    {
        c[x]=max(c[x],v);
        x+=lb(x);
    }
}

int qry(int x)
{
    int maxn=0;
    while(x>=1)
    {
        maxn=max(maxn,c[x]);
        x-=lb(x);
    }
    return maxn;
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        memset(c,0,sizeof(c));

        for(int i=0; i<n; i++)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
            int w=p[i].y-p[i].x;
            s[w+100000].insert(p[i].x);
        }

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

        set<int>::iterator it;
        for(int i=0; i<n; i++)
        {
            int w=tp[i];
            it=s[w+100000].begin();
            while(1)
            {
                if(it==s[w+100000].end())
                {
                    f=0;
                    break;
                }

                int yy=(*it)+w;
                int xx=100005-(*it);
                s[w+100000].erase(it++);

                int maxy=qry(xx);
                if(maxy>yy)
                {
                    it=s[w+100000].begin();
                }
                else
                {
                    ans[i].x=100005-xx;
                    ans[i].y=yy;
                    add(xx,yy);
                    break;
                }

            }
            if(f==0){
                //cout<<i<<endl;
                break;
            }
        }

        if(f==0)
            printf("NO\n");
        else
        {
            printf("YES\n");
            for(int i=0; i<n; i++)
            {
                printf("%d %d\n",ans[i].x,ans[i].y);
            }
        }

    }
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

vector<int>lst[130];

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    string s;

    cin>>s;

    if(s[0]==s[26] )
    {
        for(int i=0;i<13;i++)
        {
            pf("%c",s[i]);
        }

        pf("\n");

        for(int i=25;i>=13;i--)
            pf("%c",s[i]);
    }
    else
    {
        char idx;
        for(int i=0;i<27;i++)
        {
            lst[s[i] ].pb(i);

            if(sz(lst[s[i] ] )==2 )
            {
                idx=s[i];
                break;
            }
        }

        if( (lst[idx][1] - lst[idx][0] <2) || abs(sz(s)- lst[idx][1] -1- lst[idx][0] ) >1  )
            pf("Impossible\n");
        else
        {
           string res;

           if( (lst[idx][1] - lst[idx][0])%2 )
           {
                for(int i=0;i<=lst[idx][0];i++ )
                    res.pb(s[i]);

                for(int i=lst[idx][1]-1;i>lst[idx][0];i-- )
                    res.pb(s[i]);
                for(int i=lst[idx][1]+1;i<sz(s);i++ )
                    res.pb(s[i]);

            }
            else
            { what_is("hi")
                for(int i=0;i<lst[idx][0];i++ )
                    res.pb(s[i]);

                for(int i=lst[idx][1]-1;i>lst[idx][0];i-- )
                    res.pb(s[i]);
                for(int i=lst[idx][1];i<sz(s);i++ )
                    res.pb(s[i]);
            }

            for(int i=0;i<13;i++)
            {
                pf("%c",res[i]);
            }

            pf("\n");

            for(int i=25;i>=13;i--)
                pf("%c",res[i]);
        }

    }

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,stack<pair<int,int> > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);

        maps[b-a].push(mp(a,b) );
    }

    vector<pair<int,int> >res;
    int val;

    bool ok=true;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(maps[val].top() );
            maps[val].pop();
        }
    }

    pf("YES\n");

    for(auto i:res)
        pf("%d %d\n",i.F,i.S);

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    int val;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(maps[val].front() );
            maps[val].pop();
        }
    }

    bool ok=true;

    for(int i=1;i<sz(res) && ok;i++)
    {
        if(res[i].F<=res[i-1].F and res[i].S<=res[i-1].S )
            ok=false;
    }

    if(!ok)
    {
        pf("NO\n");
    }
    else
    {
        pf("YES\n");

        for(auto i:res)
            pf("%d %d\n",i.F,i.S);
    }

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    int val;

    bool ok=true;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(maps[val].front() );
            maps[val].pop();
        }
    }

    pf("YES\n");

    for(auto i:res)
        pf("%d %d\n",i.F,i.S);

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);

        maps[b-a].push(mp(a,b) );
    }

    vector<pair<int,int> >res;
    int val;

    bool ok=true;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(maps[val].front() );
            maps[val].pop();
        }
    }

    pf("YES\n");

    for(auto i:res)
        pf("%d %d\n",i.F,i.S);

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

class nod
{
public:
    int F,S;

    nod(int F,int S)
    {
        this->F=F;
        this->S=S;
    }

    bool operator < (const nod& a) const
    {
        if(F<a.F)
            return true;
    }
};

map<int,priority_queue<nod > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);

        maps[b-a].push(nod(a,b) );
    }

    vector<pair<int,int> >res;
    int val;

    bool ok=true;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(mp(maps[val].top().F,maps[val].top().S ) );
            maps[val].pop();
        }
    }

    pf("YES\n");

    for(auto i:res)
        pf("%d %d\n",i.F,i.S);

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int tree[4*200005];
int u,v,s;

void update(int nod,int l,int r)
{
    if(u<l or r<u) return;

    if(l==r)
    {
        tree[nod]=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    update(left,l,mid);
    update(right,mid+1,r);

    tree[nod]=max(tree[left],tree[right] );
}

void qu(int nod,int l,int r)
{
    if(v<l or r<u) return;

    if(u<=l && r<=v)
    {
        s=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    qu(left,l,mid);
    qu(right,mid+1,r);
}

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    bool ok=true;
    int val;

    for(int i=0;i<n && ok;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            s=0;
            u=maps[val].front().F+100001;
            v=200001;

            qu(1,1,v);

         //   pf("%d %d %d\n",maps[val].front().F,maps[val].front().S,s );

            if(s>=maps[val].front().S)
            {
                ok=false;
                continue;
            }

            res.pb(maps[val].front() );

            s=maps[val].front().S;
            update(1,1,200001);

            maps[val].pop();

        }
    }

    if(!ok)
    {
        pf("NO\n");
    }
    else
    {
        pf("YES\n");

        for(auto i:res)
            pf("%d %d\n",i.F,i.S);
    }

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    int val;

    for(int i=0;i<n;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            res.pb(maps[val].front() );
            maps[val].pop();
        }
    }

    bool ok=true;

    for(int i=1;i<sz(res) && ok;i++)
    {
        if(res[i].F<res[i-1].F and res[i].S<res[i-1].S )
            ok=false;
    }

    if(!ok)
    {
        pf("NO\n");
    }
    else
    {
        pf("YES\n");

        for(auto i:res)
            pf("%d %d\n",i.F,i.S);
    }

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int tree[4*200005];
int u,v,s;

void build(int nod,int l,int r)
{

    if(l==r)
    {
        tree[nod]=-inf;
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    build(left,l,mid);
    build(right,mid+1,r);

    tree[nod]=max(tree[left],tree[right] );
}

void update(int nod,int l,int r)
{
    if(u<l or r<u) return;

    if(l==r)
    {
        tree[nod]=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    update(left,l,mid);
    update(right,mid+1,r);

    tree[nod]=max(tree[left],tree[right] );
}

void qu(int nod,int l,int r)
{
    if(v<l or r<u) return;

    if(u<=l && r<=v)
    {
        s=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    qu(left,l,mid);
    qu(right,mid+1,r);
}

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    build(1,1,200001);

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    bool ok=true;
    int val;

    for(int i=0;i<n && ok;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            s=-inf;
            u=maps[val].front().F+100002;
            v=200001;

            qu(1,1,v);

          //  pf("%d %d %d\n",maps[val].front().F,maps[val].front().S,s );

            if(s>=maps[val].front().S)
            {
                ok=false;
                continue;
            }

//            u=maps[val].front().F+100002;
//            v=200001;
//
//            qu(1,1,v);

            res.pb(maps[val].front() );

            s=maps[val].front().S;
            update(1,1,200001);

            maps[val].pop();

        }
    }

    if(!ok)
    {
        pf("NO\n");
    }
    else
    {
        pf("YES\n");

        for(auto i:res)
            pf("%d %d\n",i.F,i.S);
    }

    return 0;
}


/*
 Problem name :
 Algorithm : Not Sure Yet
 Contest/Practice :
 Source :
 Comment : Whenever you start to believe  yourself, people also start to believe in you
 Date : --
 Last Update : 25-Mar-2015
*/

#include<bits/stdc++.h>

#define pause           system("pause");
#define FOR(s,e,inc)    for(int i=s;i<=e;i+=inc)
#define mod             1000000007
#define inf             1<<30
#define pb              push_back
#define ppb             pop_back
#define mp              make_pair
#define F               first
#define S               second
#define sz(x)           ((int)x.size())
#define sqr(x)          ( (x)* (x) )
#define eps             1e-9
#define lcm(x,y)        (abs(x) /gcd(x,y))* abs(y)
#define on(x,w)         x|(1<<w)
#define check(x,w)      (x&(1<<w))
#define all(x)          (x).begin(),(x).end()
#define pf              printf
#define sf              scanf
#define pi              acos(-1.0)
#define reset(x,v)      memset(x,v,sizeof(x));
#define AND             &&
#define OR              ||
#define what_is(x)      cerr<<#x<<" is "<<x<<"\n";

typedef long long ll;
typedef unsigned long long llu;

using namespace std;

template<class T>
inline T mod_v(T num)
{
    if(num>=0)
        return num%mod;
    else
        return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
    a=abs(a);
    b=abs(b);

    while(b) b ^= a ^= b ^= a %= b;
    return a;
}

template<class T>
T fast_pow(T n , T p)
{
    if(p==0) return 1;
    if(p%2)
    {
        T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
        return g;
    }
    else
    {
        T g=fast_pow(n,p/2);
        g=mod_v( mod_v(g) * mod_v(g) ) ;
        return g;
    }
}

template<class T>
inline T modInverse(T n)
{
    return fast_pow(n,mod-2);
}

template<class T>
inline void debug(string S1,T S2,string S3)
{
    cout<<S1<<S2<<S3;
}

bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true;   else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}

template<class T>
inline int in(register T& num)
{
    register char c=0;
    num=0;
    bool n=false;
    while(c<33)c=getchar();
    while(c>33){
        if(c=='-')
            n=true;
        else num=num*10+c-'0';
        c=getchar();
    }
    num=n?-num:num;
    return 1;
}

/******* ! Code start from here ! *******/

map<int,queue<pair<int,int> > > maps;

int tree[4*200005];
int u,v,s;

void update(int nod,int l,int r)
{
    if(u<l or r<u) return;

    if(l==r)
    {
        tree[nod]=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    update(left,l,mid);
    update(right,mid+1,r);

    tree[nod]=max(tree[left],tree[right] );
}

void qu(int nod,int l,int r)
{
    if(v<l or r<u) return;

    if(u<=l && r<=v)
    {
        s=max(tree[nod],s);
        return;
    }

    int mid=(l+r)>>1;
    int left=nod<<1;
    int right=left|1;

    qu(left,l,mid);
    qu(right,mid+1,r);
}

int main()
{
//     std::ios_base::sync_with_stdio(false);

    #ifdef kimbbakar
        freopen ( "in.txt", "r", stdin );
//        freopen ( "out.txt", "w", stdout );
    #endif

    int n;
    in(n);

    int a,b;
    vector<pair<int,int> >res;

    for(int i=0;i<n;i++)
    {
        in(a),in(b);
        res.pb(mp (a,b));
    }

    sort(all(res) );

    for(auto i:res)
    {
        maps[i.S-i.F].push(i );
    }

    res.clear();

    bool ok=true;
    int val;

    for(int i=0;i<n && ok;i++)
    {
        in(val);

        if(maps[val].empty())
        {
            pf("NO\n");

            return 0;
        }
        else
        {
            s=0;
            u=maps[val].front().F+100001;
            v=200001;

            qu(1,1,v);

         //   pf("%d %d %d\n",maps[val].front().F,maps[val].front().S,s );

            if(s>maps[val].front().S)
            {
                ok=false;
                continue;
            }

            res.pb(maps[val].front() );

            s=maps[val].front().S;
            update(1,1,200001);

            maps[val].pop();

        }
    }

    if(!ok)
    {
        pf("NO\n");
    }
    else
    {
        pf("YES\n");

        for(auto i:res)
            pf("%d %d\n",i.F,i.S);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll x[100010],y[100010],cnt[100010],w[100010];
vector <ll> v[100010];
vector <pair<ll,ll> > res;
int main() {
    ll n,d;
    cin>>n;
    map <ll,ll> mp;
    for(ll i=0;i<n;i++)
        cin>>x[i]>>y[i];
    for(ll i=0;i<n;i++)
        cnt[i] = -LLONG_MAX;
    for(ll i=0;i<n;i++)
    {
        cin>>w[i];
        mp[w[i]] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        if(mp.find(temp)==mp.end())
        {
            cout<<"NO"<<endl;
            return 0;
        }
        ll rank = mp[temp];
        cnt[rank] = max(cnt[rank],min(y[i],x[i]));
    }
    for(ll i=0;i<n;i++)
    {
        if(cnt[i]>=0)
        v[i].resize(cnt[i]+1);
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        ll rank = mp[temp];
        v[rank][cnt[rank]-min(y[i],x[i])] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp  = mp[w[i]];
        if(v[temp].size()>0)
        {
            ll q = x[v[temp][v[temp].size()-1]];
            ll q1 = y[v[temp][v[temp].size()-1]];
            res.push_back(make_pair(q,q1));
            v[temp].pop_back();
        }
    }
    ll flag=1;
    for(ll i=1;i<res.size();i++)
    {
        if(res[i].first>=res[i-1].first&&res[i].second>=res[i-1].second)
            flag=1;
        else
            flag=0;
    }
    if(flag==1){
    cout<<"YES"<<endl;
    for(ll i=0;i<res.size();i++)
        cout<<res[i].first<<" "<<res[i].second<<endl;
    }
    else
    cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll x[100010],y[100010],cnt[100010],w[100010];
vector <ll> v[100010];
vector <pair<ll,ll> > res;
int main() {
    ll n,d;
    cin>>n;
    map <ll,ll> mp;
    for(ll i=0;i<n;i++)
        cin>>x[i]>>y[i];
    for(ll i=0;i<n;i++)
        cnt[i] = -LLONG_MAX;
    for(ll i=0;i<n;i++)
    {
        cin>>w[i];
        mp[w[i]] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        if(mp.find(temp)==mp.end())
        {
            cout<<"NO"<<endl;
            return 0;
        }
        ll rank = mp[temp];
        cnt[rank] = max(cnt[rank],min(y[i],x[i]));
    }
    //cout<<"pp"<<endl;
    for(ll i=0;i<n;i++)
    {
        if(cnt[i]>=0)
        v[i].resize(cnt[i]+1);
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        ll rank = mp[temp];
        v[rank][cnt[rank]-min(y[i],x[i])] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp  = mp[w[i]];
        if(v[temp].size()>0)
        {
            ll q = x[v[temp][v[temp].size()-1]];
            ll q1 = y[v[temp][v[temp].size()-1]];
            res.push_back(make_pair(q,q1));
            v[temp].pop_back();
        }
    }
    ll flag=1;
    for(ll i=1;i<res.size();i++)
    {
        if(res[i].first>=res[i-1].first||res[i].second>=res[i-1].second)
        {
            //cout<<i<<endl;
            flag=1;
        }
        else
            flag=0;
    }
    if(flag==1){
    cout<<"YES"<<endl;
    for(ll i=0;i<res.size();i++)
        cout<<res[i].first<<" "<<res[i].second<<endl;
    }
    else
    cout<<"NO"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll x[100010],y[100010],cnt[100010],w[100010];
vector <ll> v[100010];
vector <pair<ll,ll> > res;
int main() {
    ll n,d;
    cin>>n;
    map <ll,ll> mp;
    for(ll i=0;i<n;i++)
        cin>>x[i]>>y[i];
    for(ll i=0;i<n;i++)
        cnt[i] = -1;
    for(ll i=0;i<n;i++)
    {
        cin>>w[i];
        mp[w[i]] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        if(mp.find(temp)==mp.end())
        {
            cout<<"NO"<<endl;
            return 0;
        }
        ll rank = mp[temp];
        cnt[rank] = max(cnt[rank],min(y[i],x[i]));
    //    if(i==0)
    //    cout<<rank<<endl;
    }
    //cout<<"pp"<<endl;
    for(ll i=0;i<n;i++)
    {
        if(cnt[i]>=0)
        v[i].resize(cnt[i]+1);
        //if(i==0)
        //cout<<cnt[i]<<endl;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp = y[i]-x[i];
        ll rank = mp[temp];
        v[rank][cnt[rank]-min(y[i],x[i])] = i;
    }
    for(ll i=0;i<n;i++)
    {
        ll temp  = mp[w[i]];
        if(v[temp].size()>0)
        {
            ll q = x[v[temp][v[temp].size()-1]];
            ll q1 = y[v[temp][v[temp].size()-1]];
           // cout<<q<<" "<<q1<<endl;
            res.push_back(make_pair(q,q1));
            v[temp].pop_back();
        }
    }
    for(ll i=1;i<res.size();i++)
    {
        if(res[i].first<=res[i-1].first&&res[i].second<=res[i-1].second)
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    for(ll i=0;i<res.size();i++)
        cout<<res[i].first<<" "<<res[i].second<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

set <pii > se;
set <pair<int, pii > > se1;
set <pair<int, pii > > :: iterator it;
pii ans[100001], arr[100001];
pair<int, pii > p;

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

	int n, i, j, k, x, y, z, a, b, c;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> x >> y;
		arr[i+1] = mkp(x, y);
		se.insert(mkp(x, y));
	}
	se.erase(mkp(0, 0));
	se1.insert(mkp(0, mkp(0, 0)));

	for (i = 1; i <= n; ++i) {
		cin >> a;
		it = se1.lower_bound(mkp(a, mkp(-1, -1)));
		if (it == se1.end()) {
			cout << "NO" << endl;
			return 0;
		}
		p = *it;
		x = p.sc.fi;
		y = p.sc.sc;
		ans[i] = mkp(x, y);
		se1.erase(it);

		// first par
		if (se.find(mkp(x, y+1)) != se.end() && se.find(mkp(x-1, y+1)) == se.end() && se.find(mkp(x-1, y)) == se.end()) {
			se1.insert(mkp(y+1-x, mkp(x, y+1)));
			se.erase(mkp(x, y+1));
		}

		if (se.find(mkp(x+1, y)) != se.end() && se.find(mkp(x+1, y-1)) == se.end() && se.find(mkp(x, y-1)) == se.end()) {
			se1.insert(mkp(y-x-1, mkp(x+1, y)));
			se.erase(mkp(x+1, y));
		}
	}

	cout << "YES" << endl;
	for (i = 1; i <= n; ++i) {
		cout << ans[i].fi << " " << ans[i].sc << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

pii ans[100001], arr[100001], val[100001];
pair<int, pii > p;
map <int, pii > mp;

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

	int n, i, j, k, x, y, z, a, b, c;

	x = 100000;
	y = 0;
	for (i = -100000; i <= 100000; ++i) {
		mp[i] = mkp(x, y);
		if (x > 0) x--;
		else y++;
	}

	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> x >> y;
		arr[i] = mkp(x, y);
	}
	sort(arr, arr+n);

	for (i = 1; i <= n; ++i) {
		cin >> a;
		x = mp[a].fi;
		y = mp[a].sc;
		ans[i] = val[i-1] = mkp(x, y);
		mp[a] = mkp(x+1, y+1);
	}

	sort(val, val+n);

	for (i = 0; i < n; ++i) {
		if (arr[i] != val[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	for (i = 1; i <= n; ++i) cout << ans[i].fi << " " << ans[i].sc << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int>
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

pii ans[100001], arr[100001], val[100001];
pair<int, pii > p;
map <int, pii > mp;
map <pii, int> mp1;
set <pii > se1, se2;

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

	int n, i, j, k, x, y, z, a, b, c;

	x = 100000;
	y = 0;
	for (i = -100000; i <= 100000; ++i) {
		mp[i] = mkp(x, y);
		if (x > 0) x--;
		else y++;
	}

//	for (i = -5; i <= 5; ++i) cout << mp[i].fi << " " << mp[i].sc << endl;

	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> x >> y;
		arr[i] = mkp(x, y);
		se1.insert(mkp(x, y));
		se2.insert(mkp(y, x));
	}
	sort(arr, arr+n);

	for (i = 1; i <= n; ++i) {
		cin >> a;
		x = mp[a].fi;
		y = mp[a].sc;
		mp1[mkp(x, y)] = i;
		ans[i] = val[i-1] = mkp(x, y);
		mp[a] = mkp(x+1, y+1);
	}

	sort(val, val+n);

	for (i = 0; i < n; ++i) {
		if (arr[i] != val[i]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	for (i = 1; i <= n; ++i) {
		x = ans[i].fi;
		y = ans[i].sc;

		if (mp1[mkp(x, y)] < mp1[mkp(x-1, y)] || mp1[mkp(x, y)] < mp1[mkp(x, y-1)] || mp1[mkp(x, y)] < mp1[mkp(x-1, y-1)]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	for (i = 1; i <= n; ++i) cout << ans[i].fi << " " << ans[i].sc << endl;

	return 0;
}


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

int main(){

    map<long, set< pair<long, long> > > q;
    long n;
    cin >> n;
    for(long p = 0; p < n; p++){
        long x,y;
        cin>>x>>y;
        q[y - x].insert(make_pair(x, y));
    }

    vector<pair<long, long> > num(n);
    for(long p = 0; p < n; p++){
        long w;
        cin >> w;
        if(!q[w].size()){
        	cout << "NO" << endl;
        	return 0;
        }
        num[p] = *q[w].begin();
        q[w].erase(q[w].begin());
    }

    for(long p = 1; p < n; p++){
    	if(num[p - 1].first >= num[p].first && num[p - 1].second >= num[p].second){
    		cout << "NO" << endl;
    		return 0;
    	}
    }

    cout << "YES" << endl;
    for(long p = 0; p < n; p++){
    	cout << num[p].first << " " << num[p].second << endl;
    }

    return 0;

}


#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using pii=pair<int,int>;

const int V=100000;

int n;
vector<pii> a[200001];
pii ans[100001];

int main() {
    scanf("%d",&n);

    for(int i=0;i<n;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        a[y-x+V].push_back(pii(x,y));
    }
    for(int i=0;i<=2*V;i++) sort(a[i].begin(),a[i].end(),std::greater<pii>());

    set<pii> tr;
    for(int i=0,v;i<n;i++) {
        scanf("%d",&v);
        v+=V;
        if(a[v].empty()) {
            puts("NO"); return 0;
        }

        pii val = a[v].back(); a[v].pop_back();
        ans[i] = val;

        auto it=tr.lower_bound(val);
        if(it!=tr.end() && it->se >= val.se) {
            puts("NO"); return 0;
        }
        it = tr.upper_bound(val);
        while(it!=tr.begin()) {
            it--;
            if(it->se > val.se) break;
            it = tr.erase(it);
        }
        tr.insert(val);
    }
    puts("YES");
    for(int i=0;i<n;i++) printf("%d %d\n",ans[i].fi,ans[i].se);

    return 0;
}