Problem:
Quick Sort

Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode:

Partition(A, p, r)
1 x = A[r]
2 i = p-1
3 for j = p to r-1
4 do if A[j] <= x
5 then i = i+1
6 exchange A[i] and A[j]
7 exchange A[i+1] and A[r]
8 return i+1

Quicksort(A, p, r)
1 if p < r
2 then q = Partition(A, p, r)
3 run Quicksort(A, p, q-1)
4 run Quicksort(A, q+1, r)

Here, A is an array which represents a deck of cards and comparison operations are performed based on the numbers.

Your program should also report the stability of the output for the given input (instance). Here, 'stability of the output' means that: cards with the same value appear in the output in the same order as they do in the input (instance).

Input

The first line contains an integer n, the number of cards.

n cards are given in the following lines. Each card is given in a line and represented by a pair of a character and an integer separated by a single space.

Output

In the first line, print the stability ("Stable" or "Not stable") of this output.

In the following lines, print the arranged cards in the same manner of that of the input.

Constraints

1 ≤ n ≤ 100,000

1 ≤ the number of a card ≤ 109

There are no identical card in the input

Sample Input 1

6
D 3
H 2
D 1
S 3
D 2
C 1

Sample Output 1

Not stable
D 1
C 1
D 2
H 2
D 3
S 3

Sample Input 2

2
S 1
H 1

Sample Output 2

Stable
S 1
H 1

Solution in Rust (judge verdict: Accepted)

fn qsort<T: std::cmp::PartialOrd + Copy + std::fmt::Debug>(a: &mut Vec<T>, l: usize, r: usize) {
    if l + 1 >= r {
        return;
    }
    // let p = (r + l) / 2;
    let p = r - 1;
    let e = a[p];
    a.swap(p, r - 1);
    let mut b = l;
    for i in l..r - 1 {
        if a[i] <= e {
            a.swap(i, b);
            b += 1;
        }
    }
    a.swap(b, r - 1);
    qsort(a, l, b);
    qsort(a, b + 1, r);
}

fn msort<T: std::cmp::PartialOrd + Copy + std::fmt::Debug>(a: &mut Vec<T>, l: usize, r: usize) {
    if l + 1 >= r {
        return;
    }
    let m = (l + r) / 2;
    msort(a, l, m);
    msort(a, m, r);
    // merge
    let mut b0 = l;
    let mut b1 = m;
    let mut res = vec![];
    while !(b0 == m && b1 == r) {
        if b0 == m {
            res.push(a[b1]);
            b1 += 1;
        } else if b1 == r {
            res.push(a[b0]);
            b0 += 1;
        } else {
            if a[b0] <= a[b1] {
                res.push(a[b0]);
                b0 += 1;
            } else {
                res.push(a[b1]);
                b1 += 1;
            }
        }
    }
    for i in l..r {
        a[i] = res[i - l];
    }
}

#[derive(Eq, PartialEq, Clone, Copy, Debug)]
struct Card {
    c: char,
    i: usize,
}
impl std::cmp::PartialOrd for Card {
    fn partial_cmp(&self, rhs: &Card) -> Option<std::cmp::Ordering> {
        self.i.partial_cmp(&rhs.i)
    }
}
impl std::cmp::Ord for Card {
    fn cmp(&self, rhs: &Card) -> std::cmp::Ordering {
        self.i.cmp(&rhs.i)
    }
}

fn solve() {
    let n: usize = read();
    let mut v = vec![];
    let mut vc = vec![];
    for _ in 0..n {
        let mut s: String = read();
        let c = s.pop().expect("u");
        let i = read();
        v.push(Card { c, i });
        vc.push(Card { c, i });
    }
    qsort(&mut v, 0, n);
    msort(&mut vc, 0, n);
    let mut st = true;
    for i in 0..n {
        if v[i] != vc[i] {
            println!("Not stable");
            st = false;
            break;
        }
    }
    if st {
        println!("Stable");
    }
    for e in v {
        println!("{} {}", e.c, e.i);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========