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>

int xy[200000];
int tmp[200000];

void sort(int lb, int ub) {
	int i, j, k;
	if (ub - lb <= 1) return;
	int m = (lb + ub) >> 1;
	sort(lb, m);
	sort(m, ub);
	for (i = lb; i < ub; i++) {
		tmp[i << 1] = xy[i << 1];
		tmp[(i << 1) | 1] = xy[(i << 1) | 1];
	}
	for (i = lb, j = lb, k = m; i < ub; i++) {
		if (j == m) {
			xy[i << 1] = tmp[k << 1];
			xy[(i << 1) | 1] = tmp[(k << 1) | 1];
			++k;
		}
		else if (k == ub) {
			xy[i << 1] = tmp[j << 1];
			xy[(i << 1) | 1] = tmp[(j << 1) | 1];
			++j;
		}
		else if (tmp[j << 1] < tmp[k << 1] || (tmp[j << 1] == tmp[k << 1] && tmp[(j << 1) | 1] < tmp[(k << 1) | 1])) {
			xy[i << 1] = tmp[j << 1];
			xy[(i << 1) | 1] = tmp[(j << 1) | 1];
			++j;
		}
		else {
			xy[i << 1] = tmp[k << 1];
			xy[(i << 1) | 1] = tmp[(k << 1) | 1];
			++k;
		}
	}
}

int main(void)
{
	int n, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d", &xy[i << 1], &xy[(i << 1) | 1]);
	}
	sort(0, n);
	for (i = 0; i < n; i++) {
		printf("%d %d\n", xy[i << 1], xy[(i << 1) | 1]);
	}
	return 0;
}