Under construction

Still being built. Things may change

Sorting Points by Coordinates

Interview

Time limit1sMemory limit256 MB

Summary
Sort N planar points by increasing x coordinate, breaking ties by increasing y, and print them in order.
Level

Easy3 of 10

Topics
Sorting
Solved
No attempts yet

Problem

You are given NN points on a two-dimensional plane. Write a program that sorts the points by increasing xx coordinate, and by increasing yy coordinate when the xx coordinates are equal, then prints them.

Input

The first line contains the number of points NN (1≤N≤100,0001 \le N \le 100{,}000). Each of the next NN lines contains the coordinates xix_i and yiy_i of the ii-th point, separated by a space (−100,000≤xi,yi≤100,000-100{,}000 \le x_i, y_i \le 100{,}000). All coordinates are integers, and no two points share the same position.

Output

Print the sorted points on NN lines, one point per line. On each line print the xx coordinate and the yy coordinate separated by a space.

Examples4

  1. Example 1

    Input
    5
    3 4
    1 1
    1 -1
    2 2
    3 3
    
    Expected output
    1 -1
    1 1
    2 2
    3 3
    3 4
    
  2. Example 2

    Input
    1
    0 0
    
    Expected output
    0 0
    
  3. Example 3

    Input
    2
    1 5
    1 -5
    
    Expected output
    1 -5
    1 5
    
  4. Example 4

    Input
    4
    -100000 -100000
    100000 100000
    -100000 100000
    100000 -100000
    
    Expected output
    -100000 -100000
    -100000 100000
    100000 -100000
    100000 100000