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 JavaScript (judge verdict: Accepted)

const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const merge = (arr1, arr2) => {
    if (arr1.length === 0) return arr2;
    if (arr2.length === 0) return arr1;
    const head1 = arr1[0];
    const tail1 = arr1.slice(1);
    const head2 = arr2[0];
    const tail2 = arr2.slice(1);

    if (head1[1] <= head2[1]) return [head1, ...merge(tail1, arr2)];
    else return [head2, ...merge(arr1, tail2)];
};

const msort = arr => {
    if (arr.length <= 1) return arr;
    const n = Math.floor(arr.length / 2);
    const t = arr.slice(0, n);
    const b = arr.slice(n);
    return merge(msort(t), msort(b));
};


const partition = arr => {
    const x = arr[arr.length-1][1];
    const result = [...arr];
    let i = -1;
    for (let j = 0; j < arr.length - 1; j++) {
        if (result[j][1] <= x) {
            i++;
            const tmp = result[i];
            result[i] = result[j];
            result[j] = tmp;
        }
    }
    const tmp = result[i+1];
    result[i+1] = result[arr.length-1];
    result[arr.length-1] = tmp;

    return [i+1, result];
}

const qsort = arr => {
    if (arr.length <= 1) return arr;
    const newArr = partition(arr);
    const mid = newArr[1][newArr[0]];
    const l = newArr[1].slice(0, newArr[0]);
    const r = newArr[1].slice(newArr[0]+1);
    return [...qsort(l), mid, ...qsort(r)];
};

const check = target => {
    for (let i = 1; i < target.length; i++) {
        if (target[i][1] === target[i-1][1] && target[i][2] < target[i-1][2]) {
            return false;
        }
    }
    return true;
};

const data = line.slice(1, parseInt(line[0])+1)
                 .map(x => x.split(' '))
                 .map((xs, i) => [xs[0], Number(xs[1]), i]);

const qsorted = qsort(data);

console.log(check(qsorted) ? 'Stable' : 'Not stable');
qsorted.map(x => x.slice(0, 2))
       .map(x => x.join(' '))
       .forEach(x => console.log(x));