output_description: 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.
input_description: 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.
attempt: from copy import copy
  
  
  def merge(arr, left, middle, right):
      L = arr[left:middle]
      L.append([None, float("inf")])
      R = arr[middle:right]
      R.append([None, float("inf")])
  
      iterL, iterR = iter(L), iter(R)
      l, r = next(iterL), next(iterR)
  
      for index in range(left, right):
          if l[1] <= r[1]:
              arr[index] = l
              l = next(iterL)
          else:
              arr[index] = r
              r = next(iterR)
  
  
  def merge_sort(arr, left, right):
      if left + 1 < right:
          pivot = (left + right) // 2
          merge_sort(arr, left, pivot)
          merge_sort(arr, pivot, right)
          merge(arr, left, pivot, right)
  
  
  def partition(arr, start, end):
      criteria = arr[end][1]
      idx1 = start
      for idx2 in range(start, end):
          if arr[idx2][1] <= criteria:
              arr[idx1], arr[idx2] = arr[idx2], arr[idx1]
              idx1 += 1
      arr[idx1], arr[end] = arr[end], arr[idx1]
      return idx1
  
  
  def quick_sort(arr, start, end):
      if start < end:
          pivot = partition(arr, start, end)
          quick_sort(arr, start, pivot - 1)
          quick_sort(arr, pivot + 1, end)
  
  
  num = int(input())
  arr = []
  for index in range(num):
      sign, number = input().split()
      arr.append([sign, int(number)])
  
  arr1 = copy(arr)
  arr2 = copy(arr)
  
  merge_sort(arr1, 0, num)
  quick_sort(arr2, 0, num - 1)
  
  print("Stable" if arr1 == arr2 else "Not stable")
  for sign, number in arr2:
      print(sign + " " + str(number))
  
problem_description: 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).
samples: [{"input": "6\n    D 3\n    H 2\n    D 1\n    S 3\n    D 2\n    C 1", "output": "Not stable\n    D 1\n    C 1\n    D 2\n    H 2\n    D 3\n    S 3"}, {"input": "2\n    S 1\n    H 1", "output": "Stable\n    S 1\n    H 1"}]