14555 - Merging for migration-2   

Description

Elephants form two types of formations during migration:

  1. Sorted by Age: Ensures that older elephants can correctly lead the group to their destination.
  2. Sorted by Height: Ensures that elephants at the rear can see every elephant in front of them.

Elephants prefer using merge sort in ascending order. Please help them sort by age, and if the ages are identical, sort by height. If both age and height are the same, maintain the original relative order of the index (stable sort).

This is a partial judge problem. You only need to implement merge_elephants() function, the output function has already been provided for you.

Input

The first line contains a single integer n - the number of elephants.

 2 ≤ n  ≤ 105

The following n lines each line contain two integer ah - the age and height of i-th elephant.

≤ ah ≤ 109
(Elephants are tall and long-lived animals.)

 

Output

Output the result of the index in each merge section, the format has already been implemented in the given function.

Sample Input  Download

Sample Output  Download

Partial Judge Code

14555.c

Partial Judge Header

14555.h

Tags




Discuss