Problem:
Score : 200 points

Problem Statement

You have decided to write a book introducing good restaurants.
There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point scale is P_i.
No two restaurants have the same score.

You want to introduce the restaurants in the following order:

The restaurants are arranged in lexicographical order of the names of their cities.

If there are multiple restaurants in the same city, they are arranged in descending order of score.

Print the identification numbers of the restaurants in the order they are introduced in the book.

Constraints

1 ≤ N ≤ 100

S is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

0 ≤ P_i ≤ 100

P_i is an integer.

P_i ≠ P_j (1 ≤ i < j ≤ N)

Input

Input is given from Standard Input in the following format:

N
S_1 P_1
:
S_N P_N

Output

Print N lines. The i-th line (1 ≤ i ≤ N) should contain the identification number of the restaurant that is introduced i-th in the book.

Sample Input 1

6
khabarovsk 20
moscow 10
kazan 50
kazan 35
moscow 60
khabarovsk 40

Sample Output 1

3
4
6
1
5
2

The lexicographical order of the names of the three cities is kazan < khabarovsk < moscow. For each of these cities, the restaurants in it are introduced in descending order of score. Thus, the restaurants are introduced in the order 3,4,6,1,5,2.

Sample Input 2

10
yakutsk 10
yakutsk 20
yakutsk 30
yakutsk 40
yakutsk 50
yakutsk 60
yakutsk 70
yakutsk 80
yakutsk 90
yakutsk 100

Sample Output 2

10
9
8
7
6
5
4
3
2
1

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::collections::HashSet;

//use std::collections::LinkedList;
use std::collections::VecDeque;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

type Idx = (usize, String, u32);

fn main() {
    let n = read::<usize>();
    let mut list: VecDeque<Idx> = VecDeque::new();

    for i in 1..n+1 {
        let sp = read_vec::<String>();
        let s = sp[0].to_string();
        let p_str = &sp[1];
        let p:u32 = p_str.parse().unwrap();
        let idx = (i, s, p);

        add_idx(&mut list, idx);

    }

    for x in &list {
        println!("{}", x.0);
    }
}

fn add_idx(list : &mut VecDeque<Idx>, idx:Idx) {
    let p = find_pos(list, &idx);
    list.insert(p, idx);
}

fn find_pos(list :&VecDeque<Idx>, x: &Idx) -> usize{
    if list.len() == 0 {
        return 0;
    }
    if !cond(&list[0], x) {
        return 0;
    }

    return binary_search(list, x, 0, list.len());
}

// [ o o o x x x] となっているときは2を返す。
// We do not care the case list[mid] == x
fn binary_search(list :&VecDeque<Idx>, x: &Idx, lb : usize, ub : usize) -> usize {
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        let mut lb1 = lb;
        let mut ub1 = ub;
        if cond(&list[mid], x) {
            lb1 = mid;
        } else {
            ub1 = mid;
        }
        return binary_search(list, x, lb1, ub1);
    }
    return ub;
}

fn cond(x : &Idx, y : &Idx) -> bool {
    if x.1 < y.1 {
        return true;
    }
    if x.1 == y.1 && x.2 > y.2 {
        return true;
    }
    return false;
}