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

using System;
using System.IO;

namespace Sort_II
{
    class Quick_Sort
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var A = new Card[n];
            var B = new Card[n];
            for (int i = 0; i < n; i++)
            {
                var token = Console.ReadLine().Split(' ');
                A[i] = B[i] = new Card(token[0][0], int.Parse(token[1]));
            }
            var p = 0;
            var r = A.Length - 1;

            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            QuickSort(A, p, r);
            MergeSort(B, p, r + 1);

            if (IsStable(A, B)) Console.WriteLine("Stable");
            else Console.WriteLine("Not stable");

            for (int i = 0; i < r; i++)
                Console.WriteLine(A[i]);
            Console.WriteLine(A[r]);

            Console.Out.Flush();
        }

        static bool IsStable(Card[] A, Card[] B)
        {
            var f = true;
            for (int i = 0; i < A.Length; i++)
            {
                if (!A[i].Equals(B[i])) f = false;
            }
            return f;
        }

        static public void QuickSort(Card[] A, int p, int r)
        {
            if (p < r)
            {
                var q = Partition(A, p, r);
                QuickSort(A, p, q - 1);
                QuickSort(A, q + 1, r);
            }
        }

        static public int Partition(Card[] A, int p, int r)
        {
            var x = A[r].rank;
            var i = p - 1;
            for (int j = p; j < r; j++)
                if (A[j].rank <= x)
                {
                    i++;
                    var temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            var tmp = A[i + 1];
            A[i + 1] = A[r];
            A[r] = tmp;

            return i + 1;
        }

        public struct Card
        {
            public int rank;
            char suit;
            public Card(char c, int r)
            {
                rank = r; suit = c;
            }
            public override string ToString()
            {
                return suit + " " + rank;
            }
        }

        static void Merge(Card[] A, int left, int mid, int right)
        {
            var n1 = mid - left;
            var n2 = right - mid;
            var L = new Card[n1 + 1];
            var R = new Card[n2 + 1];
            for (int i = 0; i < n1; i++)
                L[i] = A[left + i];
            for (int i = 0; i < n2; i++)
                R[i] = A[mid + i];
            L[n1] = R[n2] = new Card('s', int.MaxValue);
            var p = 0; var q = 0;
            for (int k = left; k < right; k++)
                if (L[p].rank <= R[q].rank) A[k] = L[p++];
                else A[k] = R[q++];
        }

        static void MergeSort(Card[] A, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }
    }
}