Problem:
Sorting Pairs

Write a program which print coordinates $(x_i, y_i)$ of given $n$ points on the plane by the following criteria.

first by $x$-coordinate

in case of a tie, by $y$-coordinate

Input

The input is given in the following format.

$n$
$x_0 \; y_0$
$x_1 \; y_1$
:
$x_{n-1} \; y_{n-1}$

In the first line, the number of points $n$ is given. In the following $n$ lines, coordinates of each point are given.

Output

Print coordinate of given points in order.

Constraints

$1 \leq n \leq 100,000$

$-1,000,000,000 \leq x_i, y_i \leq 1,000,000,000$

Sample Input 1

5
4 7
5 5
2 3
6 8
2 1

Sample Output 1

2 1
2 3
4 7
5 5
6 8

Solution in C (judge verdict: Accepted)

#include<stdio.h>
#include<stdlib.h>
#define N 100000

typedef struct point{
	int x;
	int y;
}point;


int compare_pointX(const void *a,const void *b){
	point *A=(point *)a;
	point *B=(point *)b;
	return A->x-B->x;
}

int compare_pointY(const void *a,const void *b){
	point *A=(point *)a;
	point *B=(point *)b;
	return A->y-B->y;
}


int main(){
	int n,i,cnt;
	point P[N];
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&P[i].x,&P[i].y);
	}
	
	qsort(P,n,sizeof(point),compare_pointX);
	
	cnt=1;
	for(i=1;i<n;i++){
		if(P[i].x==P[i-1].x)cnt++;
		else {
			qsort(&P[i-cnt],cnt,sizeof(point),compare_pointY);
			cnt=1;
		}
	}
	if(cnt!=1)qsort(&P[n-cnt],cnt,sizeof(point),compare_pointY);
	
	
	for(i=0;i<n;i++){
		printf("%d %d\n",P[i].x,P[i].y);
	}
	
	return 0;
	
}