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)

#include <stdio.h>
#define M 100000
#define N 2000000000

typedef struct{
  char x;
  int y;
}card;

card L[M/2+2];
card R[M/2+2];

void meg(card *A,int z,int l,int m,int r){
  int s1,s2,i,j,k;

  s1=m-l;
  s2=r-m;
  
  for(i=0;i<s1;i++){
    L[i]=A[l+i];
  }
  for(i=0;i<s2;i++){
    R[i]=A[m+i];
  }

  L[s1].y=R[s2].y=N;
  i=j=0;
  for(k=l;k<r;k++){
    if(L[i].y<=R[j].y){
      A[k]=L[i++];
    }
    else {
      A[k]=R[j++];
    }
  }
}

void meg_sort(card *A,int z,int left,int right){
  if(left+1<right){
    int m=(left+right)/2;
    meg_sort(A,z,left,m);
    meg_sort(A,z,m,right);
    meg(A,z,left,m,right);
  }
}

int partition_s(card *A,int g,int h){
  int i,z;
  card o,s;
  o=A[h];
  i=g-1;
  for(z=g;z<h;z++){
    if(A[z].y<=o.y){
      i++;
      s=A[i];
      A[i]=A[z];
      A[z]=s;
    }
  }
  s=A[i+1];
  A[i+1]=A[h];
  A[h]=s;
  return i+1;
}

void quick(card *A,int i,int g,int h){
  int s;
  if(g<h){
    s=partition_s(A,g,h);
    quick(A,i,g,s-1);
    quick(A,i,s+1,h);
  }
}

void stable(card *A,card *B, int a) {
  int i,count=0;
  for(i=0;i<a;i++) {
    if(A[i].x!=B[i].x) count++;
  }
  if(count==0) printf("Stable\n");
  else printf("Not stable\n");
}

    
int main(){
  int i,order,number;
  char pic[10];
  card A[M];
  card B[M];
  
  scanf("%d",&order);

  for(i=0;i<order;i++){
    scanf("%s %d",pic,&number);
      A[i].x=B[i].x=pic[0];
      A[i].y=B[i].y=number;
    }
  
    meg_sort(A,order,0,order);
    quick(B,order,0,order-1);

    stable(A,B,order);

    for(i=0;i<order;i++){
      printf("%c %d\n",B[i].x,B[i].y);
    }
  
  return 0;
}