id
stringclasses
1 value
instruction
stringclasses
206 values
trajectory
listlengths
2
297
length
int64
2
297
public_tests
listlengths
1
6
generated_tests
listlengths
4
100
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A1 = []\nA2 = []\n", "A1 = []\nA2 = []\n\n\nquick_sort(A1, 0, N - 1)\n", "A1 = []\nA2 = []\n\n\nquick_sort(A1, 0, N - 1)\n\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\n\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\n\n\ndef partition:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\n\n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\n\n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\n", "A1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1:\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1:\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1:\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1:\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1:\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort:\n \n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n \n \nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \n i, j = 0, 0\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \n i, j = 0, 0\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n \n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n i += 1\n \n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in :\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n \n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n", "N = int(input())\nA1 = []\nA2 = []\nfor _ in range(N):\n a = input().split()\n A1.append((a[0], int(a[1])))\n A2.append((a[0], int(a[1])))\n\nsnt = 10 ** 9 + 1\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x[1]:\n i += 1\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [('SNT', snt)]\n R = A[mid:right] + [('SNT', snt)]\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nquick_sort(A1, 0, N - 1)\nmerge_sort(A2, 0, N)\n\nprint('Stable' if A1 == A2 else 'Not stable')\nfor a1 in A1: print(*a1)\n" ]
37
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "a = []\n", "def partition:\n \n\na = []\n", "def partition:\n \n\nn = int(input())\na = []\n", "def partition:\n \n\nn = int(input())\na = []\n\n\nfor i in :\n", "def partition:\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \n\nfor i in :\n", "def partition:\n \n\ndef print_a(a):\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \n\nfor i in :\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \n\nfor i in :\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nprint_a(a)\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n \n\nn = int(input())\na = []\nfor _ in range(n):\n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nprint_a(a)\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nprint_a(a)\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \nelse:\n \n\nprint_a(a)\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \nelse:\n \n\nprint_a(a)\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n \n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n \n a[i+1] = a[r]\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n \n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n i = p - 1\n \n \n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n \nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n i = p - 1\n \n \n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n \n i = p - 1\n for j in :\n \n \n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n \n \n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n \n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n \n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n \n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n \n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n s = input().split()\n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n \n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n s = input().split()\n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in :\n if a[j][\"value\"] <= x:\n i += 1\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n s = input().split()\n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nprint_a(a)\n", "def partition(a, p, r):\n x = a[r][\"value\"]\n i = p - 1\n for j in range(p, r):\n if a[j][\"value\"] <= x:\n i += 1\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n tmp = a[i+1]\n a[i+1] = a[r]\n a[r] = tmp\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\ndef print_a(a):\n for x in a:\n print(x[\"design\"], x[\"value\"])\n\n\nn = int(input())\na = []\nfor _ in range(n):\n s = input().split()\n a.append({\"design\": s[0], \"value\": int(s[1])})\nb = a.copy()\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][\"value\"] == a[i+1][\"value\"]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nprint_a(a)\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "readline = sys.stdin.readline\n", "readline = sys.stdin.readline\n\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "readline = sys.stdin.readline\n\n\ndef isStable(A):\n \n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "readline = sys.stdin.readline\n\n\ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "readline = sys.stdin.readline\n\n\ndef quicksort:\n \ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\nreadline = sys.stdin.readline\n\n\ndef quicksort:\n \ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\n\nimport sys\nreadline = sys.stdin.readline\n\n\ndef quicksort:\n \ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\n\n\ndef quicksort:\n \ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\n\n\ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\n\ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\n\ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition:\n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition:\n \n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n \n \n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n \n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nimport sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n if A[i][1] == A[i + 1][1]:\n if A[i][2] > A[i + 1][2]:\n return False\n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b, c in A), sep=\"\\n\")\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# INPUT\n\n\n# PROCESS\n\n\n# OUTPUT\n", "# INPUT\nn = int(input())\n\n\n# PROCESS\n\n\n# OUTPUT\n", "def partition:\n \n\n# INPUT\nn = int(input())\n\n\n# PROCESS\n\n\n# OUTPUT\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\n\n# PROCESS\n\n\n# OUTPUT\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\n\n# PROCESS\n\n\n# OUTPUT\n\n\nfor card in list_card:\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\n\n\n# PROCESS\n\n\n# OUTPUT\n\n\nfor card in list_card:\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\n\n\n# PROCESS\nflag_stable = True\n\n\n# OUTPUT\n\n\nfor card in list_card:\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\n\n\nfor card in list_card:\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\n\n\nfor card in list_card:\n", "def partition:\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n \n\nfor card in list_card:\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n \n\nfor card in list_card:\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n \n\nfor card in list_card:\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n \nelse:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n \n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n \n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n \n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n \n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n for j in :\n \n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n global flag_stable\n\n \n for j in :\n \n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n global flag_stable\n\n \n for j in :\n \n\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n global flag_stable\n\n \n i = p - 1\n\n for j in :\n \n\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n global flag_stable\n\n \n i = p - 1\n\n for j in :\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n \n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n \n\n global flag_stable\n\n \n i = p - 1\n\n for j in :\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n \n i = p - 1\n\n for j in :\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n x = A[r][COLUMN_SORT]\n i = p - 1\n\n for j in :\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in :\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n x = A[r][COLUMN_SORT]\n i = p - 1\n\n for j in :\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in range(q + 1, r):\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n x = A[r][COLUMN_SORT]\n i = p - 1\n\n for j in range(p, r):\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in range(q + 1, r):\n \n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n x = A[r][COLUMN_SORT]\n i = p - 1\n\n for j in range(p, r):\n \n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in range(q + 1, r):\n if A[r] > A[i]:\n flag_stable = False\n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n", "def partition(A, p, r):\n COLUMN_SORT = 1\n\n global flag_stable\n\n x = A[r][COLUMN_SORT]\n i = p - 1\n\n for j in range(p, r):\n if A[j][COLUMN_SORT] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n q = i + 1\n A[q], A[r] = A[r], A[q]\n\n for i in range(q + 1, r):\n if A[r] > A[i]:\n flag_stable = False\n\n return q\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\n# INPUT\nn = int(input())\n\nlist_card = []\nfor _ in range(n):\n suit, num = input().split()\n list_card.append([suit, int(num)])\n\n\n# PROCESS\nflag_stable = True\n\nquicksort(list_card, 0, n-1)\n\n\n# OUTPUT\nif flag_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in list_card:\n print(*card)\n" ]
34
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "C = []\n", "def mergeSort:\n \n\nC = []\n", "def mergeSort:\n \n\nC = []\n\n\nif C==D:\n", "def mergeSort:\n \n\nC = []\n\n\nmergeSort(D,0,N)\n\nif C==D:\n", "def mergeSort:\n \n\nC = []\n\n\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "def merge:\n \n\ndef mergeSort:\n \n\nC = []\n\n\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "def Partition(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nC = []\n\n\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "def Partition(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nC = []\n\n\nD = copy.deepcopy(C)\n\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "def Partition(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\n\n\nD = copy.deepcopy(C)\n\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "def Partition(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\n\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "INF = 10000000000\ndef Partition(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\n\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "INF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\n\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\n\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n \n\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge:\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\n\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\n\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n\ndef Qsort(A,p,r):\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n \n \ndef Qsort(A,p,r):\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n \n \ndef Qsort(A,p,r):\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n \nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n \n \ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n \nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n \n \n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n \nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n \n \n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n \nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n \n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n \n \nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n \n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n \nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n \n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n countL = mergeSort(A, left, mid)\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n \n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n i = i + 1\n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n", "import copy\nINF = 10000000000\ndef Partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n flag = 1\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef Qsort(A,p,r):\n if p < r:\n q = Partition(A,p,r)\n Qsort(A,p,q-1)\n Qsort(A,q+1,r)\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\nN = int(input())\nC = []\nfor i in range(N):\n C.append(input().split())\n C[i][1] = int(C[i][1])\n\nD = copy.deepcopy(C)\nQsort(C,0,N-1)\nmergeSort(D,0,N)\n\nif C==D:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in range(N):\n print(C[i][0]+\" \"+str(C[i][1]))\n" ]
59
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "n = int(input())\n", "n = int(input())\n\n\nmergeSort(A,0,n)\n", "n = int(input())\n\n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\n", "import copy\n\nn = int(input())\n\n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\n", "import copy\n\nn = int(input())\n\n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\n", "import copy\n\nn = int(input())\n\n\ninf = 10**9\n\n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\n", "import copy\n\nn = int(input())\n\nfor i in range(n):\n \ninf = 10**9\n\n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\n", "import copy\n\nn = int(input())\n\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\n", "import copy\n\nn = int(input())\n\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\n", "import copy\n\nn = int(input())\n\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nn = int(input())\n\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge:\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n \ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n \ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n \n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n \n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n \ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n for k in :\n #cnt += 1\n \n\ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n for k in :\n #cnt += 1\n \n\ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in range(p,r):\n \n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n for k in :\n #cnt += 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in range(p,r):\n \n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n for k in :\n #cnt += 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in range(p,r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i = i+1\n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n", "import math\nimport copy\n\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = [a, int(b)]\ninf = 10**9\n\ndef merge(A,left,mid,right):\n #global cnt\n L = A[left:mid] + [[inf,inf]]\n R = A[mid:right] + [[inf,inf]]\n i = 0\n j = 0\n\n for k in range(left,right):\n #cnt += 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef mergeSort(A,left,right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A,left,mid)\n mergeSort(A,mid,right)\n merge(A,left,mid,right)\n\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p\n for j in range(p,r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i = i+1\n A[i], A[r] = A[r], A[i]\n\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\n\nB = copy.deepcopy(A)\nmergeSort(A,0,n)\nquickSort(B,0,n-1)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in B]\nans = '\\n'.join(ans)\nprint(ans)\n" ]
40
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "cards = []\n", "cards = []\n\n\nif :\n", "def partition:\n \n\ncards = []\n\n\nif :\n", "def partition:\n \n\ncards = []\nfor i in range(n):\n \n\nif :\n", "def partition:\n \n\ndef swap:\n \n\ncards = []\nfor i in range(n):\n \n\nif :\n", "def partition:\n \n\ndef swap:\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\n\nif :\n", "def quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\n\nif :\n", "def quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\n\nif :\n \n\nfor i in range(n):\n", "def quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif :\n \n\nfor i in range(n):\n", "def quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ndef check_stability(cards):\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ndef check_stability(cards):\n \n\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n\ndef check_stability(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n \ndef check_stability(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n \ndef check_stability(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n \ndef check_stability(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap:\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition:\n \n\ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition(cards, p, r):\n \n\ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition(cards, p, r):\n \n\ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n", "class Card:\n \n \ndef quick_sort:\n \n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef quick_sort(cards, p, r):\n \n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n \nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n \n \ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n \n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n \n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n i = p - 1\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n i = p - 1\n for j in :\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n \n i = p - 1\n for j in :\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in :\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n \n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__:\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n def __str__(self):\n \n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n \n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n \n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n \n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n \n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n \n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n \n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n \n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n c2 = cards[i]\n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n c2 = cards[i]\n if :\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n c2 = cards[i]\n if and :\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n c2 = cards[i]\n if c1.num == c2.num and :\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n def __init__(self, mark, num, order):\n self.mark = mark\n self.num = num\n self.order = order\n def __str__(self):\n return self.mark + ' ' + str(self.num)\n\ndef quick_sort(cards, p, r):\n if p < r:\n q = partition(cards, p, r)\n quick_sort(cards, p, q - 1)\n quick_sort(cards, q + 1, r)\n\ndef partition(cards, p, r):\n x = cards[r].num\n i = p - 1\n for j in range(p, r):\n if cards[j].num <= x:\n i += 1;\n swap(cards, i, j)\n swap(cards, i + 1, r)\n return i + 1\n\ndef swap(cards, i, j):\n tmp = cards[i]\n cards[i] = cards[j]\n cards[j] = tmp\n\ndef check_stability(cards):\n for i in range(1, len(cards)):\n c1 = cards[i-1]\n c2 = cards[i]\n if c1.num == c2.num and c1.order > c2.order:\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n mark, num = map(str, input().split())\n cards.append(Card(mark, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nstable = check_stability(cards)\nif stable == True:\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n" ]
58
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\nA = []\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\nA = []\n\n\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\nA = []\nfor i in range(n):\n \n\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\ndef quick_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\ndef quick_sort:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n", "#ALDS1_6_C Quick Sort\n\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n \n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n \nelse:\n \n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n \nelse:\n \n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n \nelse:\n \n\nfor i in range(n):\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n \nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition:\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge:\n \n\ndef merge_sort:\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge:\n \n \n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n \n j = p\n \n \n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n \n j = p\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n r = A[mid: right]\n\n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n \n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n r = A[mid: right]\n\n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n \n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n \nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n \n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n A.append([suit, int(num)])\nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in :\n if A[i][1] <= q:\n A[i], A[j] = A[j], A[i]\n j += 1\n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n A.append([suit, int(num)])\nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in range(p, r):\n if A[i][1] <= q:\n A[i], A[j] = A[j], A[i]\n j += 1\n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n A.append([suit, int(num)])\nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in range(p, r):\n if A[i][1] <= q:\n A[i], A[j] = A[j], A[i]\n j += 1\n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in :\n if l[i][1] <= r[j][1]:\n A[k] = l[i]\n i += 1\n else:\n A[k] = r[j]\n j += 1\n\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n A.append([suit, int(num)])\nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n", "#ALDS1_6_C Quick Sort\nimport sys\n# sys.setrecursionlimit(10000)\ndef partition(A, p, r):\n q = A[r][1]\n j = p\n for i in range(p, r):\n if A[i][1] <= q:\n A[i], A[j] = A[j], A[i]\n j += 1\n A[j], A[r] = A[r], A[j]\n return j\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n l = A[left: mid]\n r = A[mid: right]\n\n l.append([None, float('inf')])\n r.append([None, float('inf')])\n\n i = 0\n j = 0\n\n for k in range(left, right, 1):\n if l[i][1] <= r[j][1]:\n A[k] = l[i]\n i += 1\n else:\n A[k] = r[j]\n j += 1\n\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n suit, num = input().split()\n A.append([suit, int(num)])\nA1 = A.copy()\n\nquick_sort(A, 0, n-1)\nmerge_sort(A1, 0, n)\n\nif A != A1:\n print('Not stable')\nelse:\n print('Stable')\n\nfor i in range(n):\n print(' '.join(map(str, A[i])))\n" ]
41
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# -*- coding: utf-8 -*-\n\na = []\n", "# -*- coding: utf-8 -*-\n\na = []\n\n\na_in = a.copy()\n", "# -*- coding: utf-8 -*-\n\na = []\n\n\na_in = a.copy()\n\ndef is_stable(a, b):\n", "# -*- coding: utf-8 -*-\n\na = []\n\n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\n\n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\n\n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\n\n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\nfor i in range(n):\n \n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\nfor i in range(n):\n \n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nif :\n \n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\na = []\nn = int(input())\nfor i in range(n):\n \n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n \n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n \n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n\na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition:\n \n\ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition:\n \n \ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif :\n print('Stable')\n\nfor i in :\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif is_stable:\n print('Stable')\n\nfor i in :\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n \n\nquick_sort(a, 0, len(a)-1)\nif is_stable:\n print('Stable')\nelse:\n \nfor i in :\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable:\n print('Stable')\nelse:\n \nfor i in :\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable:\n print('Stable')\nelse:\n \nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n \nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n \nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \n a[r] = temp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n \nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \n temp = a[i+1]\n \n a[r] = temp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n \nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \n temp = a[i+1]\n \n a[r] = temp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \n temp = a[i+1]\n \n a[r] = temp\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n \n \n temp = a[i+1]\n \n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n temp = a[i+1]\n \n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n \na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n \n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n s = input().split()\n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n s = input().split()\n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n \n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n s = input().split()\n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in :\n if b[i+1][1] == b[i][1]:\n j = a.index(b[i])\n k = a.index(b[i+1])\n if j > k:\n s = False\n return s\n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n s = input().split()\n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in range(n-1):\n if b[i+1][1] == b[i][1]:\n j = a.index(b[i])\n k = a.index(b[i+1])\n if j > k:\n s = False\n return s\n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n \n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n", "# -*- coding: utf-8 -*-\n\"\"\"\nCreated on Thu May 3 21:24:25 2018\nALDS1_6_C\n@author: maezawa\n\"\"\"\na = []\nn = int(input())\nfor i in range(n):\n s = input().split()\n a.append([s[0], int(s[1])])\n\na_in = a.copy()\n\ndef is_stable(a, b):\n s = True\n for i in range(n-1):\n if b[i+1][1] == b[i][1]:\n j = a.index(b[i])\n k = a.index(b[i+1])\n if j > k:\n s = False\n return s\n return s\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n temp = a[i]\n a[i] = a[j]\n a[j] = temp\n temp = a[i+1]\n a[i+1] = a[r]\n a[r] = temp\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\nquick_sort(a, 0, len(a)-1)\nif is_stable(a_in, a):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(len(a)):\n print('{} {}'.format(a[i][0],a[i][1]))\n" ]
39
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "n = int(input())\nA = []\n", "import copy\nn = int(input())\nA = []\n", "import copy\nn = int(input())\nA = []\n\n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\n\nB.sort(key = lambda x: int(x[1]))\n\n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\n\nB.sort(key = lambda x: int(x[1]))\n\n\nQuickSort(A, 0, n-1)\n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\n\nB.sort(key = lambda x: int(x[1]))\n\n\nQuickSort(A, 0, n-1)\nif A == B:\n \n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\n\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\nQuickSort(A, 0, n-1)\nif A == B:\n \n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\n\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n \n\nQuickSort(A, 0, n-1)\nif A == B:\n \n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n \n\nQuickSort(A, 0, n-1)\nif A == B:\n \n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n \nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n \n\nQuickSort(A, 0, n-1)\nif A == B:\n \n\nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n \nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n \n\nQuickSort(A, 0, n-1)\nif A == B:\n \nelse:\n \nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n \nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n \nelse:\n \nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n \nelse:\n \nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition:\n \n\ndef QuickSort:\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n \n\ndef QuickSort:\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n \n\ndef QuickSort:\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n \n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n \n \ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n \n \n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n \n \n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n \n \n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n for j in :\n if int(A[j][1]) <= int(A[r][1]):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor ni in range(n):\n print(*A[ni], sep=\" \")\n", "import copy\nn = int(input())\nA = []\nfor ni in range(n):\n A.append(input().split())\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[1]))\n\ndef Partition(A, p, r):\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= int(A[r][1]):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\ndef QuickSort(A, p, r):\n if p >= r:\n return None\n else:\n q, A = Partition(A, p, r)\n QuickSort(A, p, q-1)\n QuickSort(A, q+1, r)\n return A\n\nQuickSort(A, 0, n-1)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor ni in range(n):\n print(*A[ni], sep=\" \")\n" ]
27
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "b = a[:]\n", "b = a[:]\n\n\nquick_sort(b, 0, n - 1, partition_stable)\n", "def partition_not_stable:\n \n\nb = a[:]\n\n\nquick_sort(b, 0, n - 1, partition_stable)\n", "def make_card:\n \n\ndef partition_not_stable:\n \n\nb = a[:]\n\n\nquick_sort(b, 0, n - 1, partition_stable)\n", "def make_card:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\n\nb = a[:]\n\n\nquick_sort(b, 0, n - 1, partition_stable)\n", "def make_card:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\n\nb = a[:]\n\n\nquick_sort(b, 0, n - 1, partition_stable)\n\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\n\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\n\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\n\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_stable:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\n\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_stable:\n \n\ndef partition_not_stable:\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_stable:\n \n\ndef partition_not_stable:\n \n\ndef quick_sort:\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_stable:\n \n\ndef partition_not_stable:\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card:\n \n\ndef partition_stable:\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable:\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n\ndef partition_stable:\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable:\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable:\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable:\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable:\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(a, p, r, func):\n \n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n \ndef partition_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n \n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n \n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n \n for j in :\n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in :\n \n i += 1\n \n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n \n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n x, i = a[r][0], p - 1\n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in range(p, r):\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n x, i = a[r][0], p - 1\n for j in :\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in range(p, r):\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n x, i = a[r][0], p - 1\n for j in range(p, r):\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in range(p, r):\n \n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n x, i = a[r][0], p - 1\n for j in range(p, r):\n if a[j][0] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n", "def make_card(i, card):\n suit, value = card.split()\n return (int(value), i, card)\n\n\ndef partition_stable(a, p, r):\n x, i = a[r], p - 1\n for j in range(p, r):\n if a[j] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef partition_not_stable(a, p, r):\n x, i = a[r][0], p - 1\n for j in range(p, r):\n if a[j][0] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n i += 1\n a[i], a[r] = a[r], a[i]\n return i\n\n\ndef quick_sort(a, p, r, func):\n if p < r:\n q = func(a, p, r)\n quick_sort(a, p, q - 1, func)\n quick_sort(a, q + 1, r, func)\n\n\nn = int(input())\na = list(make_card(i, input()) for i in range(n))\nb = a[:]\n\nquick_sort(a, 0, n - 1, partition_not_stable)\nquick_sort(b, 0, n - 1, partition_stable)\nprint(('S' if a == b else 'Not s') + 'table')\nprint('\\n'.join(card[2] for card in a))\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def mergeSort:\n", "def mergeSort:\n \n\nif :\n", "def quickSort:\n \n\ndef mergeSort:\n \n\nif :\n", "def quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif :\n", "class Card:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n\nif :\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n\nif :\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort:\n \n\nif :\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort:\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif :\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort:\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\ndef partition(A, p, r):\n x = A[r]\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n \n\n mergeSort(B, 0, n)\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n \n\n mergeSort(B, 0, n)\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n \n\n mergeSort(B, 0, n)\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n for _ in range(n):\n \n\n mergeSort(B, 0, n)\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n \n A = []\n for _ in range(n):\n \n\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n \n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n \n \n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__:\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n \n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n \n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n \n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n \n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n \n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n \n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in :\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n \n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n \n \n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n \n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n \n \n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n suit, value = input().split()\n \n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n \n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n suit, value = input().split()\n A.append(Card(suit, int(value)))\n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n self.value = value\n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n suit, value = input().split()\n A.append(Card(suit, int(value)))\n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n \n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n self.value = value\n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n suit, value = input().split()\n A.append(Card(suit, int(value)))\n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card)\n", "INF = 1000000000\n\nclass Card:\n def __init__(self, suit, value):\n self.suit = suit\n self.value = value\n\n def __repr__(self):\n return self.suit + ' ' + str(self.value)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if A[j].value <= x.value:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(Card(\"INF\", INF))\n R.append(Card(\"INF\", INF))\n i = 0\n j = 0\n for k in range(left, right):\n if L[i].value <= R[j].value:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n A = []\n for _ in range(n):\n suit, value = input().split()\n A.append(Card(suit, int(value)))\n\n B = A.copy()\n quickSort(A, 0, n - 1)\n mergeSort(B, 0, n)\n if A == B:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card)\n" ]
53
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#クイックソート\n", "#クイックソート\n\n\nif A == B:\n", "#クイックソート\n\n\nA = [(a[0], int(a[1])) for a in A]\n\n\nif A == B:\n", "#クイックソート\nimport copy\n\n\nA = [(a[0], int(a[1])) for a in A]\n\n\nif A == B:\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nA = [(a[0], int(a[1])) for a in A]\n\n\nif A == B:\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nA = [(a[0], int(a[1])) for a in A]\n\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition(A, p, r):\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition(A, p, r):\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n \ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge:\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n \n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n i, j = 0, 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in :\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in :\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in :\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n \n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in :\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in :\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n \n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n \n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n \n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n \n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n \n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n i = i + 1\n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n j = j + 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "#クイックソート\nimport copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p\n for j in range(p, r):\n if A[j][1] <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n\n\n A[i], A[r] = A[r], A[i]\n\n return i\n\nn = int(input())\nA = [input().split() for _ in range(n)]\nA = [(a[0], int(a[1])) for a in A]\nB = [(a[0], int(a[1])) for a in A]\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print('Stable')\nelse:\n print(\"Not stable\")\n\nans = [str(a[0])+\" \"+str(a[1]) for a in A]\nans = '\\n'.join(ans)\nprint(ans)\n" ]
59
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "if :\n", "def quickSort(A,p,r):\n \n\nif :\n", "def quickSort(A,p,r):\n \n\ndef mergeSort(A):\n \n\nif :\n", "def quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from import \n\n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from import \nCard = namedtuple('Card', 'suit value')\n\n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from import \nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from collections import \nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from collections import \nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n \n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n\nif :\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n \nif :\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n \n A = []\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n \n A = []\n \n L.append(Card('X',-1))\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n \n Cq = Co[:]\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n \n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n \n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n \n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n \n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n \n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n \n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \nif __name__=='__main__':\n \n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n \n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n \n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n \n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n \n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n \n \n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if : return A\n \n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if : return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if : return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n \n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if : return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq:\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if : return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq: print(c.suit,c.value)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n \n return A\n\ndef mergeSort(A):\n if len(A)==1: return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq: print(c.suit,c.value)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in :\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n if L[i].value > R[j].value:\n A.append(L[i])\n i += 1\n else:\n A.append(R[j])\n j += 1\n return A\n\ndef mergeSort(A):\n if len(A)==1: return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq: print(c.suit,c.value)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in range(p,r):\n \n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n if L[i].value > R[j].value:\n A.append(L[i])\n i += 1\n else:\n A.append(R[j])\n j += 1\n return A\n\ndef mergeSort(A):\n if len(A)==1: return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq: print(c.suit,c.value)\n", "from collections import namedtuple\nCard = namedtuple('Card', 'suit value')\n\ndef partition(A,p,r):\n x = A[r]\n i = p\n for j in range(p,r):\n if A[j].value <= x.value:\n A[i],A[j] = A[j],A[i]\n i += 1\n A[i],A[r] = A[r],A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\ndef merge(L,R):\n global cnt\n n = len(L)+len(R)\n A = []\n i = j = 0\n L.append(Card('X',-1))\n R.append(Card('X',-1))\n for _ in range(n):\n if L[i].value > R[j].value:\n A.append(L[i])\n i += 1\n else:\n A.append(R[j])\n j += 1\n return A\n\ndef mergeSort(A):\n if len(A)==1: return A\n m = len(A)//2\n return merge(mergeSort(A[:m]),mergeSort(A[m:]))\n\nif __name__=='__main__':\n n = int(input())\n Co = list(map(lambda X: Card(X[0],int(X[1])), [input().split() for _ in range(n)]))\n Cq = Co[:]\n Cm = mergeSort(Co[:])\n quickSort(Cq,0,n-1)\n print(\"Stable\" if Cq==Cm[::-1] else \"Not stable\")\n for c in Cq: print(c.suit,c.value)\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# -*- coding: utf-8 -*-\n\n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\n\n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\n\n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\n# 安定比較用にライブラリで安定ソートする\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\n\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n", "# -*- coding: utf-8 -*-\n\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n \nelse:\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n \nelse:\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n \n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n \nelse:\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif :\n \nelse:\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n \nelse:\n \n\nfor i in range(N):\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n \nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n \n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n \n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n \n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n \ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n aN[i][0] = suit\n \n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n \n aN[i][0] = suit\n aN[i][1] = int(num)\n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n suit, num = input().split()\n aN[i][0] = suit\n aN[i][1] = int(num)\n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n \n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n suit, num = input().split()\n aN[i][0] = suit\n aN[i][1] = int(num)\n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n \n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n suit, num = input().split()\n aN[i][0] = suit\n aN[i][1] = int(num)\n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in :\n if aN[j][1] <= x:\n i = i+1\n aN[i], aN[j] = aN[j], aN[i]\n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(N):\n print(*aN[i])\n", "# -*- coding: utf-8 -*-\n\n\"\"\"\nクイックソート\n\"\"\"\n\nN = int(input())\naN = [[None] * 2 for i in range(N)]\nfor i in range(N):\n suit, num = input().split()\n aN[i][0] = suit\n aN[i][1] = int(num)\n\ndef partition(p, r):\n # 今回は基準xの選び方が最後尾固定だけど、\n # これをうまく選ぶ方がクイックソートは高速になる\n x = aN[r][1]\n i = p-1\n for j in range(p, r):\n if aN[j][1] <= x:\n i = i+1\n aN[i], aN[j] = aN[j], aN[i]\n aN[i+1], aN[r] = aN[r], aN[i+1]\n # 基準となった末尾要素のindex\n return i+1\n\ndef quick_sort(p, r):\n if p < r:\n # 再帰処理の中でパーティションを使う\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n# 安定比較用にライブラリで安定ソートする\naN2 = sorted(aN, key=lambda x: x[1])\nquick_sort(0, N-1)\n\n# クイックソートは安定ではないが、\n# マージソートに対して、メモリ領域を使わない利点がある\nif all([aN[i][0] == aN2[i][0] for i in range(N)]):\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(N):\n print(*aN[i])\n" ]
29
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "quick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\nn = int(input())\n\n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\ndef merge:\n \n\nn = int(input())\n\n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\ndef merge:\n \n\nn = int(input())\nA = read_n_lows_input(n)\n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\n\nquick_sort(A, 0, n-1)\n", "def swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\n\nquick_sort(A, 0, n-1)\n\nif A == B:\n", "def swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\n\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n", "def swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n", "import copy\n\ndef swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n", "import copy\n\ndef swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n\ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n\ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \n\nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n\ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n \ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition:\n \n \ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n \nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n \n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n return A\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge:\n \n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n \nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n \n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n \n R = A[mid:right]\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n \n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n \n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in :\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n \n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i+1\n A[i], A[j] = swap(A[i], A[j])\n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i+1\n A[i], A[j] = swap(A[i], A[j])\n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n \n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i+1\n A[i], A[j] = swap(A[i], A[j])\n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n \n \n quick_sort(A, q+1, r)\n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i+1\n A[i], A[j] = swap(A[i], A[j])\n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n \n quick_sort(A, q+1, r)\n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n", "import copy\n\ndef swap(a, b):\n return b, a\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i+1\n A[i], A[j] = swap(A[i], A[j])\n A[i+1], A[r] = swap(A[i+1], A[r])\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n return A\n\ndef merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(['X', float('inf')])\n R.append(['X', float('inf')])\n i = 0\n j = 0\n for k in range(left, right):\n if float(L[i][1]) <= float(R[j][1]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return A\n\ndef merge_sort(A, left, right):\n if left+1 < right:\n mid = (left + right) >> 1\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n return merge(A, left, mid, right)\n\ndef read_n_lows_input(n):\n Alist=[[j for j in input().split()] for i in range(n)]\n return Alist\n\nn = int(input())\nA = read_n_lows_input(n)\nB = copy.deepcopy(A)\nquick_sort(A, 0, n-1)\nmerge_sort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(*i, sep=\" \")\n" ]
50
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "for c in card:\n", "quicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\nquicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\nquicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\nfor i in range(n):\n \n\nquicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\ncard = []\nfor i in range(n):\n \n\nquicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n\nquicksort(card, 0, n-1)\n\n\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort:\n \n\nn = int(input())\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ncard = []\nfor i in range(n):\n \n\ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n", "def partition:\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n \n \n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n \n \n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n for i in :\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n \n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n \ndef checkstable(card):\n for i in :\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n \n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n \nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n \n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n \n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in :\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n \n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in range(len(card) - 1):\n \n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n \n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in range(len(card) - 1):\n if card[i][1] == card[i + 1][1] and card[i][2] > card[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n memo = A[i]\n A[i] = A[j]\n A[j] = memo\n memo = A[i+1]\n A[i+1] = A[r]\n A[r] = memo\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ncard = []\nfor i in range(n):\n word, num = input().split()\n card.append([word, int(num), int(i)])\n\ndef checkstable(card):\n for i in range(len(card) - 1):\n if card[i][1] == card[i + 1][1] and card[i][2] > card[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nquicksort(card, 0, n-1)\n\nprint(checkstable(card))\nfor c in card:\n print(c[0], c[1])\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def decode():\n", "def decode():\n \n\ndef quicksort:\n", "def decode():\n \n\ndef disp(cards):\n \n\ndef quicksort:\n", "def decode():\n \n\ndef partition:\n \n\ndef disp(cards):\n \n\ndef quicksort:\n", "def decode():\n \n\ndef partition:\n \n\ndef disp(cards):\n \n\ndef quicksort:\n \n\ndef isstable(cards):\n", "def decode():\n \n\ndef partition:\n \n\ndef disp(cards):\n \n\ndef quicksort:\n \n\ndef isstable(cards):\n \n\nif :\n", "def decode():\n \n\ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n \n\ndef quicksort:\n \n\ndef isstable(cards):\n \n\nif :\n", "def decode():\n \n\ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n \n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n\nif :\n", "def decode():\n \n\ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n\nif :\n", "def decode():\n \n \ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n\nif :\n", "def decode():\n \n \ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n\nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n \nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition:\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n \nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition(a, p, r):\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n \n \nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition(a, p, r):\n \n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n \nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n \nif __name__ == '__main__':\n", "def decode():\n \n \ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n \nif __name__ == '__main__':\n \n\n if :\n", "def decode():\n \n cards = []\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n \nif __name__ == '__main__':\n \n\n if :\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n \nif __name__ == '__main__':\n \n\n if :\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n if :\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n \n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n \ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n \n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n \n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n \n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n \n i = p - 1\n\n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n \n \n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in :\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n \n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n \n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in :\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in range(len(cards) - 1):\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if :\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in range(len(cards) - 1):\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if isstable(cards):\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n [m, v] = input().split()\n \n\n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in range(len(cards) - 1):\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if isstable(cards):\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n [m, v] = input().split()\n cards.append((m, int(v), i))\n\n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in range(len(cards) - 1):\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if isstable(cards):\n print(\"Stable\")\n else:\n \n\n disp(cards)\n", "def decode():\n n = int(input())\n cards = []\n for i in range(n):\n [m, v] = input().split()\n cards.append((m, int(v), i))\n\n return n, cards\n\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n t = a[j]\n a[j] = a[i]\n a[i] = t\n t = a[i+1]\n a[i+1] = a[r]\n a[r] = t\n\n return i+1\n\n\ndef disp(cards):\n for (m, n, _) in cards:\n print(\"{0} {1}\".format(m, n))\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(cards):\n for i in range(len(cards) - 1):\n if cards[i][1] == cards[i+1][1]:\n if cards[i][2] < cards[i+1][2]:\n pass\n else:\n return False\n return True\n\nif __name__ == '__main__':\n n, cards = decode()\n\n quicksort(cards, 0, n-1)\n\n if isstable(cards):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n disp(cards)\n" ]
42
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "if:\n", "def m():\n \nif:\n", "def s(A):\n \ndef m():\n \nif:\n", "import sys\n\n\ndef s(A):\n \ndef m():\n \nif:\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \ndef m():\n \nif:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \ndef m():\n \nif:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \ndef m():\n \nif'__main__'==__name__:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \ndef m():\n \nif'__main__'==__name__:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \ndef m():\n \nif'__main__'==__name__:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \ndef m():\n \nif'__main__'==__name__:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \ndef m():\n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \ndef m():\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \ndef m():\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \ndef m():\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n \n \nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n \n \n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n \n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n \n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n \n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n print(s(A)+'table')\n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n print(s(A)+'table')\n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n print(s(A)+'table')\n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n print(s(A)+'table')\n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\ndef m():\n A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n k(A,0,n-1)\n print(s(A)+'table')\n print('\\n'.join(f'{a} {b}'for a,b,_ in A))\nif'__main__'==__name__: n=int(input());m()\n" ]
27
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "b.sort(key=lambda x:x[1])\n", "b.sort(key=lambda x:x[1])\n\n\nfor i in range(r):\n", "a=[list(input().split()) for _ in range(r)]\n\n\nb.sort(key=lambda x:x[1])\n\n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\na=[list(input().split()) for _ in range(r)]\n\n\nb.sort(key=lambda x:x[1])\n\n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\na=[list(input().split()) for _ in range(r)]\n\n\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\n\n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\na=[list(input().split()) for _ in range(r)]\n\n\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\na=[list(input().split()) for _ in range(r)]\n\n\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\na=[list(input().split()) for _ in range(r)]\n\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\n\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def quicksort(a,p,r):\n \n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n \nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n \nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n \nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n \nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\n\n\nfor i in range(r):\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n \nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n \n\nfor i in range(r):\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n \n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n \n i=p-1\n \n \n a[i+1]=a[r]\n \n \ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n \n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n \n i=p-1\n \n \n a[i+1]=a[r]\n \n \ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n \n \n a[i+1]=a[r]\n \n \ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n \n \n a[i+1]=a[r]\n a[r]=temp\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n \n temp=a[i+1]\n a[i+1]=a[r]\n a[r]=temp\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n temp=a[i+1]\n a[i+1]=a[r]\n a[r]=temp\n \n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n temp=a[i+1]\n a[i+1]=a[r]\n a[r]=temp\n return i+1\n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n if a[j][1]<=x:\n i+=1\n temp=a[i]\n a[i]=a[j]\n a[j]=temp\n temp=a[i+1]\n a[i+1]=a[r]\n a[r]=temp\n return i+1\n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n", "def partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n temp=a[i]\n a[i]=a[j]\n a[j]=temp\n temp=a[i+1]\n a[i+1]=a[r]\n a[r]=temp\n return i+1\n\ndef quicksort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\n\nr=int(input())\na=[list(input().split()) for _ in range(r)]\nfor i in range(r):\n a[i][1]=int(a[i][1])\nimport copy\nb=copy.deepcopy(a)\nb.sort(key=lambda x:x[1])\nquicksort(a,0,r-1)\n\n\nif a==b:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(r):\n print(a[i][0],a[i][1])\n" ]
27
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "c = 0\n", "c = 0\n\n\nquicksort(data, 0, n-1)\n", "data = list(input().split() for _ in range(n))\nc = 0\n\n\nquicksort(data, 0, n-1)\n", "data = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\nquicksort(data, 0, n-1)\n", "data = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n", "data = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n", "data = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n \n\nfor l in range(n):\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\n\nif c == 0:\n \n\nfor l in range(n):\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n \n\nfor l in range(n):\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n \n\nfor l in range(n):\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange:\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n \n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange(a, i, j):\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n \n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange(a, i, j):\n \n\ndef partition:\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n \n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange(a, i, j):\n \n\ndef partition:\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n \n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition:\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition:\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition(a, p, r):\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n \n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition(a, p, r):\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in :\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition(a, p, r):\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n \n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n \n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n \n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n \n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n \n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n \n exchange(a, i+1, r)\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n \n i = p-1\n for j in :\n \n exchange(a, i+1, r)\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p-1\n for j in :\n \n exchange(a, i+1, r)\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p-1\n for j in range(p, r):\n \n exchange(a, i+1, r)\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n", "n = int(input())\ndata = list(input().split() for _ in range(n))\nc = 0\n\nfor k in range(n):\n data[k].append(str(k))\n\n\ndef exchange(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n return a\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p-1\n for j in range(p, r):\n if int(a[j][1]) <= x:\n i += 1\n a = exchange(a, i, j)\n exchange(a, i+1, r)\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\nquicksort(data, 0, n-1)\n\nfor l in range(n-1):\n if int(data[l][1]) == int(data[l+1][1]):\n if int(data[l][2]) > int(data[l+1][2]):\n print('Not stable')\n c = 1\n break\n\nif c == 0:\n print('Stable')\n\nfor l in range(n):\n print(data[l][0], data[l][1])\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# Quick Sort\n\n\nA = []\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\n\nA = []\n\n\ndef quick_sort(p, r):\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\ndef quick_sort(p, r):\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef quick_sort(p, r):\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\n\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n \n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nINF = float('inf')\n\n\ndef merge:\n \n \n l = 0\n r = 0\n\n \ndef merge_sort:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge:\n \n \n l = 0\n r = 0\n\n \ndef merge_sort:\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge:\n \n \n l = 0\n r = 0\n\n \ndef merge_sort(left, right):\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge:\n \n \n l = 0\n r = 0\n\n \ndef merge_sort(left, right):\n \n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge:\n \n \n l = 0\n r = 0\n\n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n \n l = 0\n r = 0\n\n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n \n \n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n \n\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n \n\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n \n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n \n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in :\n \n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in :\n \n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n \n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in :\n \n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n L = B[left:mid]+[('sentinel', INF)]\n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n L = B[left:mid]+[('sentinel', INF)]\n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n L = B[left:mid]+[('sentinel', INF)]\n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n L = B[left:mid]+[('sentinel', INF)]\n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in :\n if L[l][1] <= R[r][1]:\n B[i] = L[l]\n l += 1\n else:\n B[i] = R[r]\n r += 1\n\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n", "# Quick Sort\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, a = input().split()\n A.append((s, int(a)))\n\nB = [a for a in A]\n\n\ndef partition(p, r):\n i = p-1\n x = A[r][1]\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\n\nINF = float('inf')\n\n\ndef merge(left, mid, right):\n L = B[left:mid]+[('sentinel', INF)]\n R = B[mid:right]+[('sentinel', INF)]\n l = 0\n r = 0\n\n for i in range(left, right):\n if L[l][1] <= R[r][1]:\n B[i] = L[l]\n l += 1\n else:\n B[i] = R[r]\n r += 1\n\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = (left+right)//2\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nprint('Stable' if A == B else 'Not stable')\nfor s, v in A:\n print(s, v)\n\n\n# print('Merge')\n# for s, v in B:\n# print(s, v)\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def merge:\n", "def merge:\n \n\ndef quicksort:\n", "def merge:\n \n\ndef partition:\n \n\ndef quicksort:\n", "def mergesort:\n \n\ndef merge:\n \n\ndef partition:\n \n\ndef quicksort:\n", "def mergesort:\n \n\ndef merge:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nif :\n", "def mergesort(A, s, e):\n \n\ndef merge:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nif :\n", "def mergesort(A, s, e):\n \n\ndef merge:\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n \n\ndef merge:\n \n \ndef partition:\n \n\ndef quicksort:\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge:\n \n \ndef partition:\n \n\ndef quicksort:\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge:\n \n \ndef partition:\n \n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge:\n \n \ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif :\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n \n quicksort(AA, 0, len(AA) - 1)\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n \n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n \n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n \n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n \n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n \n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n \n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in :\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if :\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n \n for key, val in AA:\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n \n for key, val in AA:\n print('{} {}'.format(key, val))\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n \n for key, val in AA:\n print('{} {}'.format(key, val))\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n print('Not stable')\n for key, val in AA:\n print('{} {}'.format(key, val))\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n \n val = int(val)\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n print('Not stable')\n for key, val in AA:\n print('{} {}'.format(key, val))\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n key, val = input().strip().split()\n val = int(val)\n \n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n print('Not stable')\n for key, val in AA:\n print('{} {}'.format(key, val))\n", "def mergesort(A, s, e):\n if s + 1 < e:\n m = (e + s) // 2\n mergesort(A, s, m)\n mergesort(A, m, e)\n merge(A, s, m, e)\n\n\ndef merge(A, s, m, e):\n L = A[s:m] + [('*', 1E10)]\n R = A[m:e] + [('*', 1E10)]\n ix_l = ix_r = 0\n for ix in range(s, e):\n if L[ix_l][1] <= R[ix_r][1]:\n A[ix] = L[ix_l]\n ix_l += 1\n else:\n A[ix] = R[ix_r]\n ix_r += 1\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n i = partition(A, p, r)\n quicksort(A, p, i - 1)\n quicksort(A, i + 1, r)\n\n\nif __name__ == '__main__':\n N = int(input().strip())\n AA = [0] * N\n for i in range(N):\n key, val = input().strip().split()\n val = int(val)\n AA[i] = (key, val)\n AA2 = AA[:]\n quicksort(AA, 0, len(AA) - 1)\n mergesort(AA2, 0, len(AA2))\n if all([a == a2 for a, a2 in zip(AA, AA2)]):\n print('Stable')\n else:\n print('Not stable')\n for key, val in AA:\n print('{} {}'.format(key, val))\n" ]
45
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#print(card)\n#print(card2)\n", "#print(card)\n#print(card2)\n\n\nfor i in range(N):\n", "for i in range(N):\n \n\n#print(card)\n#print(card2)\n\n\nfor i in range(N):\n", "for i in range(N):\n \n\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nfor i in range(N):\n", "for i in range(N):\n \n\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nprint(ans)\nfor i in range(N):\n", "card = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nprint(ans)\nfor i in range(N):\n", "card = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nprint(ans)\nfor i in range(N):\n", "def quickSort(A,p,r):\n \n\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nprint(ans)\nfor i in range(N):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nprint(ans)\nfor i in range(N):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\n\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\n\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "import copy\n\ndef partition(A,p,r):\n \n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n \n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n", "import copy\n\ndef partition(A,p,r):\n \n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n \n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n \n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n \nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n \n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n \n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n \n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n \ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n for j in range(p,r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n", "import copy\n\ndef partition(A,p,r):\n x = A[r][1]\n i = p-1\n # iは必ず1ずつ増える、jでx以下の要素を検出し、iの位置に持って行く\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nN = int(input())\ncard = [input().split() for i in range(N)]\nfor i in range(N):\n card[i][1] = int(card[i][1])\n\ncard2 = copy.deepcopy(card)\ncard2.sort(key=lambda x: x[1])\n\nquickSort(card,0,N-1)\n#print(card)\n#print(card2)\n\nans = 'Stable'\nfor i in range(N):\n if card[i][0] != card2[i][0]:\n ans = 'Not stable'\n break\nprint(ans)\nfor i in range(N):\n print(' '.join(map(str,card[i])))\n" ]
26
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "B = A[:]\n", "A = [input() for _ in range(n)]\nB = A[:]\n", "def is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\n", "def num(card):\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\n", "def num(card):\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\n\n\nfor card in B:\n", "def num(card):\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\n\nfor card in B:\n", "def num(card):\n \n\ndef partition:\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\n\nfor card in B:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\n\nfor card in B:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n \n\ndef partition:\n \n \ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n \n\ndef partition(A, p, r):\n \n \ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \ndef quicksort:\n \n\ndef is_stable(A, B):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \ndef quicksort:\n \n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \ndef quicksort:\n \n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n \n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n \nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in :\n \n \n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n \n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n \n \n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n \n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n \n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n elif :\n \n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n elif == :\n \n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n elif == :\n return False\n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n elif == num(card):\n return False\n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n", "def num(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in range(p, r):\n if num(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\ndef is_stable(A, B):\n C = B[:]\n for card in A:\n i = C.index(card)\n if i == 0:\n pass\n elif num(C[i - 1]) == num(card):\n return False\n del C[i]\n return True\n\nn = int(input())\nA = [input() for _ in range(n)]\nB = A[:]\nquicksort(B, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor card in B:\n print(card)\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def partition:\n", "def partition:\n \n\ndef main():\n", "def partition:\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort:\n \n\ndef makedic(A, n):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n \n return i\n\n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n \n\ndef main():\n \n A = []\n \n\nif :\n main()\n", "def partition:\n \n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\nif :\n main()\n", "def partition(A, p, r):\n \n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\nif :\n main()\n", "def partition(A, p, r):\n \n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n \n return d\n\ndef main():\n \n A = []\n \n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n \n A = []\n \n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n \n A = []\n \n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n \n A = []\n \n\n sd = makedic(A, N)\n \n \n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n \n A = []\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n \n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n N = int(input())\n A = []\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n \n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n \n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n \n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n \n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n \n \n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n \n \n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n \n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n \n \n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n key = A[i][1]\n \n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n key = A[i][1]\n value = A[i][0]\n if key in d:\n \n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n key = A[i][1]\n value = A[i][0]\n if key in d:\n d[key] += value\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n key = A[i][1]\n value = A[i][0]\n if key in d:\n d[key] += value\n else:\n \n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r + 1):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n return i\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\ndef makedic(A, n):\n d = {}\n for i in range(n):\n key = A[i][1]\n value = A[i][0]\n if key in d:\n d[key] += value\n else:\n d[key] = value\n return d\n\ndef main():\n N = int(input())\n A = []\n for i in range(N):\n a, v = input().split()\n v = int(v)\n A.append((a, v))\n\n sd = makedic(A, N)\n quicksort(A, 0, N - 1)\n ed = makedic(A, N)\n\n print('Stable' if sd == ed else 'Not stable')\n\n for l in A:\n print(l[0], l[1])\n\nif __name__ == '__main__':\n main()\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# coding: utf-8\n# Your code here!\n\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef quick_sort:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef quick_sort:\n \n\nconfirm_cards = cards[:]\n\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef quick_sort:\n \n\nconfirm_cards = cards[:]\n\n\nif :\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\n\nconfirm_cards = cards[:]\n\n\nif :\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\n\nconfirm_cards = cards[:]\n\n\nif :\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\n\n\nif :\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\n\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\n\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n\ndef merge_sort(A, l, r):\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif :\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n\ndef quick_sort(A, l, r):\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \nelse:\n \n\nfor card in cards:\n \n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n \n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n \n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n \nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge:\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n \n \ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n \n \n for k in :\n \n\ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n \n \n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n \n \n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n \n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n \n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n \n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n \n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n mid = (l + r) // 2\n\n \n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n \n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n mid = (l + r) // 2\n\n \n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n \n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n \n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n if :\n return\n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n \n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n if :\n return\n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n merge_sort(A, mid, r)\n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n \n\ndef merge_sort(A, l, r):\n if l + 1 >= r:\n return\n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n merge_sort(A, mid, r)\n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in :\n if a1[i][1] <= a2[j][1]:\n A[k] = a1[i]\n i += 1\n else:\n A[k] = a2[j]\n j += 1\n\ndef merge_sort(A, l, r):\n if l + 1 >= r:\n return\n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n merge_sort(A, mid, r)\n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n", "# coding: utf-8\n# Your code here!\nINF = 10**10\n\ndef merge(A, l, mid, r):\n a1 = A[l:mid] + [[None, INF]]\n a2 = A[mid:r] + [[None, INF]]\n i = j = 0\n for k in range(l, r):\n if a1[i][1] <= a2[j][1]:\n A[k] = a1[i]\n i += 1\n else:\n A[k] = a2[j]\n j += 1\n\ndef merge_sort(A, l, r):\n if l + 1 >= r:\n return\n mid = (l + r) // 2\n\n merge_sort(A, l, mid)\n merge_sort(A, mid, r)\n\n merge(A, l, mid, r)\n\n\ndef quick_sort(A, l, r):\n if l < r:\n #mid = (l + r) // 2\n mid = r\n pivot = A[mid][1]\n A[mid], A[r] = A[r], A[mid]\n i = 0\n for j in range(l, r):\n if A[j][1] <= pivot:\n A[l+i], A[j] = A[j], A[l+i]\n i += 1\n A[l+i], A[r] = A[r], A[l+i]\n\n quick_sort(A, l, l+i-1)\n quick_sort(A, l+i+1, r)\n\nn = int(input())\ncards = [input().split() for _ in range(n)]\n\nfor card in cards:\n card[1] = int(card[1])\n\nconfirm_cards = cards[:]\n\nquick_sort(cards, 0, n - 1)\nmerge_sort(confirm_cards, 0, n)\n\nif cards == confirm_cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor card in cards:\n print(*card)\n\n#print('-----')\n#for card in confirm_cards:\n# print(*card)\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "cL = []\n", "n = int(input())\ncL = []\n", "n = int(input())\ncL = []\n\n\ndef quickSort:\n", "n = int(input())\ncL = []\n\n\ndef quickSort:\n \n\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\n\n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n \n\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n \n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n \n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\n\n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n \n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\n\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n \n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort(A, l, r):\n \n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \n\nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif :\n \nelse:\n \nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n \nelse:\n \nfor v in quickSorted:\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n \nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition:\n \n \n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition(A, l, r):\n \n \n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n \n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition(A, l, r):\n \n \n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n \n \ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n \n \ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n \ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n \ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n \n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n \n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n \n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n \n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n \n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n \nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n \n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while :\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n while :\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n while rI < len(r):\n \n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n while rI < len(r):\n \n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n while rI < len(r):\n \n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while and :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n while rI < len(r):\n \n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while and :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n lI+=1\n while rI < len(r):\n \n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while and :\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n \n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n newL.append(l[lI])\n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n if :\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n newL.append(l[lI])\n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n if :\n minVI+=1\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n newL.append(l[lI])\n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n if A[i][1] <= pivot:\n minVI+=1\n \n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n newL.append(l[lI])\n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n", "n = int(input())\ncL = []\nfor i in range(n):\n inputS = input()\n inputL = inputS.split()\n cL.append([inputS, int(inputL[1])])\n\ndef partition(A, l, r):\n pivot = A[r][1]\n minVI = l-1\n i = l\n while i < r:\n if A[i][1] <= pivot:\n minVI+=1\n A[i], A[minVI] = A[minVI], A[i]\n i+=1\n A[minVI+1], A[i] = A[i], A[minVI+1]\n return minVI+1\n\ndef quickSort(A, l, r):\n if l < r:\n pivotI = partition(A, l, r)\n quickSort(A, l, pivotI-1)\n quickSort(A, pivotI+1, r)\n\ndef merge(l, r):\n lI = 0\n rI = 0\n newL = []\n while lI < len(l) and rI < len(r):\n if l[lI][1] <= r[rI][1]:\n newL.append(l[lI])\n lI+=1\n else:\n newL.append(r[rI])\n rI+=1\n while lI < len(l):\n newL.append(l[lI])\n lI+=1\n while rI < len(r):\n newL.append(r[rI])\n rI+=1\n return newL\n\ndef mergeSort(curL):\n if len(curL) <= 1:\n return curL\n else:\n mid = len(curL)//2\n left = mergeSort(curL[:mid])\n right = mergeSort(curL[mid:])\n return merge(left, right)\n\nmergeSorted = mergeSort(cL)\nquickSort(cL, 0, len(cL)-1)\nquickSorted = cL\nif mergeSorted == quickSorted:\n print('Stable')\nelse:\n print('Not stable')\nfor v in quickSorted:\n print(v[0])\n" ]
53
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "n = int(input())\nA = []\n", "n = int(input())\nA = []\n\n\nfor i in range(n):\n", "def quicksort(A,p,r):\n \n\nn = int(input())\nA = []\n\n\nfor i in range(n):\n", "def quicksort(A,p,r):\n \n\nn = int(input())\nA = []\n\n\nprint(stable)\nfor i in range(n):\n", "def quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\n\n\nprint(stable)\nfor i in range(n):\n", "def quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\n\n\nquicksort(A,0,n - 1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\n\n\nquicksort(A,0,n - 1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n\nquicksort(A,0,n - 1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n \n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n def storecards(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n \n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n \n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n \n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n \n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n \nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n \n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n \n\n def isstable(self,A):\n \n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n \n\n def isstable(self,A):\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n \n\n def isstable(self,A):\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j], A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j], A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n for i in :\n \n \nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j], A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j], A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n for i in :\n if self.d[A[i][1]].pop(0) != A[i][0]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j], A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\nclass checkstable:\n def __init__(self):\n self.d = {}\n def storecards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]] = [(A[i][0])]\n\n def isstable(self,A):\n for i in range(len(A)):\n if self.d[A[i][1]].pop(0) != A[i][0]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nA = []\nfor _ in range(n):\n mark,num = input().split()\n num = int(num)\n A.append([mark,num])\nquick = checkstable()\nquick.storecards(A)\n\nquicksort(A,0,n - 1)\nstable = quick.isstable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "def is_stable():\n \n\nA = []\n", "def quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\n", "import copy\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\n", "import copy\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\n\norig_list = copy.deepcopy(A)\n", "import copy\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\n\nis_stable = is_stable()\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \nelse:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n \n\ndef is_stable():\n idx = 0\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n \n \ndef is_stable():\n idx = 0\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n \n \ndef is_stable():\n idx = 0\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n \n \ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n \n \ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n \ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n \ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n \ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while :\n \n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n \n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n \n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n \n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n \n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if :\n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == :\n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == :\n \n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == :\n num = A[idx][1]\n \n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == :\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n \n \n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == :\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n \n \n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n \n \n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n \n \n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n orig_suits = correct_same_num_suits(orig_list, num)\n \n \n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n orig_suits = correct_same_num_suits(orig_list, num)\n \n idx += len(sorted_suits)\n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n orig_suits = correct_same_num_suits(orig_list, num)\n if :\n \n idx += len(sorted_suits)\n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n orig_suits = correct_same_num_suits(orig_list, num)\n if :\n return False\n idx += len(sorted_suits)\n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef correct_same_num_suits(l, num):\n suits = []\n for card in l:\n if num == card[1]:\n suits.append(card[0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n idx_incr_flg = True\n if A[idx][1] == A[idx+1][1]:\n num = A[idx][1]\n sorted_suits = correct_same_num_suits(A, num)\n orig_suits = correct_same_num_suits(orig_list, num)\n if sorted_suits != orig_suits:\n return False\n idx += len(sorted_suits)\n idx_incr_flg = False\n if idx_incr_flg:\n idx += 1\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n" ]
53
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def partition:\n", "def partition:\n \n\nif :\n main()\n", "def partition:\n \n\ndef quickSort(A,p,r):\n \n\nif :\n main()\n", "def partition:\n \n\ndef quickSort(A,p,r):\n \n\ndef main():\n \n\nif :\n main()\n", "class Card:\n \n\ndef partition:\n \n\ndef quickSort(A,p,r):\n \n\ndef main():\n \n\nif :\n main()\n", "class Card:\n \n\ndef partition:\n \n\ndef quickSort(A,p,r):\n \n\ndef main():\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n \n\ndef partition:\n \n\ndef quickSort(A,p,r):\n \n\ndef main():\n \n A = []\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n \n\ndef partition:\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n \n\ndef main():\n \n A = []\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n \n\ndef partition:\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition:\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n for _ in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n \n \n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n \n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n \n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n \n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in :\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in :\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n \n\n for i in range(n):\n \n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in :\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n \n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n \n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n \n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n \n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n card.suit = _input[0]\n \n \n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n card.suit = _input[0]\n card.value = int(_input[1])\n \n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n card.suit = _input[0]\n card.value = int(_input[1])\n A.append(card)\n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n card = Card()\n \n card.suit = _input[0]\n card.value = int(_input[1])\n A.append(card)\n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n", "class Card:\n def __init__(self):\n self.suit = ''\n self.value = 0\n\ndef partition(A, p, r):\n x = A[r].value\n i = p\n for j in range(p, r):\n if A[j].value <= x:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[i], A[r] = A[r], A[i]\n return i\n\ndef quickSort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n card = Card()\n _input = input().split(\" \")\n card.suit = _input[0]\n card.value = int(_input[1])\n A.append(card)\n\n ind = dict((e, i) for i, e in enumerate(A))\n quickSort(A, 0, n-1)\n\n for i in range(n - 1):\n if A[i].value == A[i + 1].value:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n else:\n print('Stable')\n\n for i in range(n):\n print(A[i].suit, A[i].value)\n\nif __name__ == \"__main__\":\n main()\n" ]
34
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "for i in a:\n", "n = int(input())\n\n\nfor i in a:\n", "def partition:\n \n\nn = int(input())\n\n\nfor i in a:\n", "def partition:\n \n\nn = int(input())\n\n\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \n\nn = int(input())\n\n\nmergeSort(b, 0, n)\n\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \n\ndef merge:\n \n\nn = int(input())\n\n\nmergeSort(b, 0, n)\n\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \n\ndef merge:\n \n\nn = int(input())\n\n\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \n\ndef merge:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \ndef quickSort:\n \ndef merge:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \ndef quickSort:\n \ndef merge:\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \ndef quickSort:\n \ndef merge:\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n", "def partition:\n \ndef quickSort:\n \ndef merge:\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition:\n \ndef quickSort:\n \ndef merge:\n \n \n i = 0\n j = 0\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort:\n \ndef merge:\n \n \n i = 0\n j = 0\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort:\n \ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort:\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort:\n \nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort:\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort:\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n \n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n \n for i in :\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n \n for i in :\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n \n for i in :\n \n \n i = 0\n j = 0\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n \n for i in :\n \n \n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n \n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n \n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n L[n1] = ['last', 10**9 + 1]\n \n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n \n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n \n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n \n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n \ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n \n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in :\n L[i] = arr[left + i]\n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in range(n1):\n L[i] = arr[left + i]\n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in range(p, r):\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in range(n1):\n L[i] = arr[left + i]\n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in :\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in range(p, r):\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in range(n1):\n L[i] = arr[left + i]\n for i in :\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p - 1\n for j in range(p, r):\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\ndef quickSort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quickSort(arr, p, q - 1)\n quickSort(arr, q + 1, r)\ndef merge(arr, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = [i for i in range(n1 + 1)]\n R = [i for i in range(n2 + 1)]\n for i in range(n1):\n L[i] = arr[left + i]\n for i in range(n2):\n R[i] = arr[mid + i]\n L[n1] = ['last', 10**9 + 1]\n R[n2] = ['last', 10**9 + 1]\n i = 0\n j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(R[j][1]):\n arr[k] = L[i]\n i += 1\n else:\n arr[k] = R[j]\n j += 1\ndef mergeSort(arr, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(arr, left, mid)\n mergeSort(arr, mid, right)\n merge(arr, left, mid, right)\nn = int(input())\na = [list(input().split()) for i in range(n)]\nb = [i for i in a]\nmergeSort(b, 0, n)\nquickSort(a, 0, n - 1)\nprint('Stable' if a == b else 'Not stable')\nfor i in a:\n print(' '.join(i))\n" ]
43
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "a = []\nb = {}\n\n\nok = 1\n", "a = []\nb = {}\n\n\nb = {val: iter(s).__next__ for val, s in b.items()}\n\n\nok = 1\n", "a = []\nb = {}\n\n\nb = {val: iter(s).__next__ for val, s in b.items()}\n\n\nok = 1\nfor s, i in a:\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\n\nok = 1\nfor s, i in a:\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\n\nok = 1\nfor s, i in a:\n \n\nfor i in range(n):\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n \n\nfor i in range(n):\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n \n\nfor i in range(n):\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n \n\nfor i in range(n):\n", "a = []\nb = {}\n\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n \nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n \nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition:\n \n\ndef quickSort:\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n\ndef quickSort:\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n\ndef quickSort:\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n \ndef quickSort:\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n \ndef quickSort:\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n \ndef quickSort(a, left = 0, ):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n \ndef quickSort(a, left = 0, ):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n \ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n a += [(s, int(i))]\n \nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n \ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n \n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n \ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n \ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n \n a[cnt],a[right] = a[right], a[cnt]\n \n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n \n cnt = left\n for i in :\n \n a[cnt],a[right] = a[right], a[cnt]\n \n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n standard = a[right][1]\n cnt = left\n for i in :\n \n a[cnt],a[right] = a[right], a[cnt]\n \n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n standard = a[right][1]\n cnt = left\n for i in :\n \n a[cnt],a[right] = a[right], a[cnt]\n return cnt\n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n standard = a[right][1]\n cnt = left\n for i in range(left, right):\n \n a[cnt],a[right] = a[right], a[cnt]\n return cnt\n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n", "a = []\nb = {}\nn = int(input())\nfor _ in range(n):\n s, i = input().split()\n a += [(s, int(i))]\n b.setdefault(int(i), []).append(s)\nb = {val: iter(s).__next__ for val, s in b.items()}\n\ndef partition(a, left, right):\n standard = a[right][1]\n cnt = left\n for i in range(left, right):\n if a[i][1] <= standard:\n a[cnt],a[i] = a[i], a[cnt]\n cnt += 1\n a[cnt],a[right] = a[right], a[cnt]\n return cnt\n\ndef quickSort(a, left = 0, right = len(a) - 1):\n if 1 <= right - left:\n cnt_ = partition(a, left, right)\n quickSort(a,left, cnt_ - 1)\n quickSort(a,cnt_ + 1, right)\n\nquickSort(a, 0 , len(a)-1)\n\nok = 1\nfor s, i in a:\n if b[i]() != s:\n ok = 0\nprint(['Not stable','Stable'][ok])\n\n\nfor i in range(n):\n print(*a[i])\n" ]
29
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def main():\n", "import time\n\n\ndef main():\n", "import time\n\n\ndef main():\n \n\nif :\n main()\n", "import itertools\n\n\nimport time\n\n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport time\n\n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport time\n\n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport random\nimport time\n\n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport re\n\n\nimport random\nimport time\n\n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport re\n\n\nimport sys\nimport random\nimport time\n\n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport collections\nimport re\n\n\nimport sys\nimport random\nimport time\n\n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport collections\nimport re\n\n\nimport sys\nimport random\nimport time\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import string\nimport itertools\n\n\nimport collections\nimport re\n\nimport bisect\nimport sys\nimport random\nimport time\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\n\n\nimport collections\nimport re\n\nimport bisect\nimport sys\nimport random\nimport time\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\n\n\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\n\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\n\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition:\n # xがピボット\n \n\ndef quicksort(a, p, r):\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition:\n # xがピボット\n \n \ndef quicksort(a, p, r):\n \n\ndef main():\n \n\nif :\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition:\n # xがピボット\n \n \ndef quicksort(a, p, r):\n \n\ndef main():\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n \ndef quicksort(a, p, r):\n \n\ndef main():\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n \ndef quicksort(a, p, r):\n \n\ndef main():\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n \n\n if :\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n \n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n \nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n \n for card in cards:\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n \n else:\n \n\n for card in cards:\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n print('Not stable')\n else:\n \n\n for card in cards:\n \n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if :\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n \n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if cards != stable_sorted_cards:\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n \n cards.append((c[0], int(c[1])))\n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if cards != stable_sorted_cards:\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n c = input().split()\n cards.append((c[0], int(c[1])))\n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if cards != stable_sorted_cards:\n print('Not stable')\n else:\n \n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n", "import math\nimport string\nimport itertools\nimport fractions\nimport heapq\nimport collections\nimport re\nimport array\nimport bisect\nimport sys\nimport random\nimport time\ninf = 10**9\n\n\ndef partition(a, p, r):\n # xがピボット\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef main():\n n = int(input())\n cards = []\n for i in range(n):\n c = input().split()\n cards.append((c[0], int(c[1])))\n\n stable_sorted_cards = sorted(cards, key=lambda x: x[1])\n quicksort(cards, 0, n-1)\n\n if cards != stable_sorted_cards:\n print('Not stable')\n else:\n print('Stable')\n\n for card in cards:\n print(card[0], card[1])\n\n\nif __name__ == '__main__':\n main()\n" ]
46
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def QuickSort:\n", "from import \n\n\ndef QuickSort:\n", "from import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n", "from import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\n\n\nfor i in :\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\n\n\nQuickSort(A, 0, n)\n\nfor i in :\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\n\n\nQuickSort(A, 0, n)\n\nfor i in :\n \n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\nA = [None] * n\n\n\nQuickSort(A, 0, n)\n\nfor i in :\n \n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in :\n \n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in :\n \n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n \n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\n\n\nfor a in A:\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\n\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n \nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n \nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n \n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\n QuickSort(A, begin, left)\n \n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n \n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n for i in :\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n \n for i in :\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n piv = A[end - 1].value\n \n\n for i in :\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n piv = A[end - 1].value\n left, right = begin, begin\n\n for i in :\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n piv = A[end - 1].value\n left, right = begin, begin\n\n for i in range(begin, end - 1):\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if end - begin <= 1:\n return\n\n piv = A[end - 1].value\n left, right = begin, begin\n\n for i in range(begin, end - 1):\n \n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from sys import stdin\nfrom collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if end - begin <= 1:\n return\n\n piv = A[end - 1].value\n left, right = begin, begin\n\n for i in range(begin, end - 1):\n if A[i].value <= piv:\n if i - left > 0:\n A[left], A[i] = A[i], A[left]\n left += 1\n\n A[left], A[end - 1] = A[end - 1], A[left]\n\n QuickSort(A, begin, left)\n QuickSort(A, left + 1, end)\n\nn = int(stdin.readline())\nA = [None] * n\n\nfor i in range(n):\n suit, value = stdin.readline().split()\n A[i] = Card(suit, int(value), i)\n\nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n if A[i].value == A[i + 1].value and A[i].init > A[i + 1].init:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A=[]\n", "def quicksort(A,p,r):\n \n\nA=[]\n", "def quicksort(A,p,r):\n \n\nA=[]\n\nAcopy=A.copy()\n", "def quicksort(A,p,r):\n \n\nA=[]\n\nAcopy=A.copy()\nquicksort(A,0,n-1)\n", "def quicksort(A,p,r):\n \n\nA=[]\n\nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n", "def quicksort(A,p,r):\n \n\nA=[]\n\nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "def quicksort(A,p,r):\n \n\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "def quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "def partition(A,p,r):\n \ndef quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "def partition(A,p,r):\n \ndef quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\n\nfor i in :\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \ndef quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in :\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in :\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in :\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in :\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n \nprint(ans)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n \nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n \n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n \n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n \n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n m=A[i]\n A[i]=A[j]\n A[j]=m\n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n m=A[i]\n A[i]=A[j]\n A[j]=m\n m=A[i+1]\n A[i+1]=A[r]\n A[r]=m\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nn=int(input())\nA=[]\nfor _ in range(n):\n card=input().split()\n A.append([card[0],int(card[1])])\nAcopy=A.copy()\nquicksort(A,0,n-1)\nans=\"Stable\"\nfor i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if Acopy.index(A[i+1])<Acopy.index(A[i]):\n ans=\"Not stable\"\n break\nprint(ans)\nfor i in range(n):\n print(*A[i])\n" ]
26
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def quick_sort(A,p,r):\n", "def quick_sort(A,p,r):\n \n\nfor loop in range(n):\n", "def quick_sort(A,p,r):\n \n\noriginal_cards=[]\nfor loop in range(n):\n", "def quick_sort(A,p,r):\n \n\noriginal_cards=[]\nfor loop in range(n):\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\noriginal_cards=[]\nfor loop in range(n):\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nquick_sort(sorted_cards,0,n)\n\n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nquick_sort(sorted_cards,0,n)\n\n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n \nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge:\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n\ndef quick_sort(A,p,r):\n \n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n \ndef quick_sort(A,p,r):\n \n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif:\n \nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n \ndef quick_sort(A,p,r):\n \n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n \nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n \ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n \nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n \ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n \n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n \ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n \n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n \n i=p-1\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in :\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n \n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in :\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n \n j=-1\n \n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in :\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n \n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n \n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in :\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n \n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in :\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n \n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n \n\n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n \n\n while(1):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if:\n \n\n while(1):\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if:\n \n\n while(1):\n j+=1\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n \n\n while(1):\n j+=1\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n \n j=-1\n\n while(1):\n j+=1\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n x=sorted[i][1]\n j=-1\n\n while(1):\n j+=1\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n x=sorted[i][1]\n j=-1\n\n while(1):\n j+=1\n if:\n \n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n x=sorted[i][1]\n j=-1\n\n while(1):\n j+=1\n if:\n if(sorted[i][0]!=original[j][0]):\n return 0\n else:\n break\n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n x=sorted[i][1]\n j=-1\n\n while(1):\n j+=1\n if(x==original[j][1]):\n if(sorted[i][0]!=original[j][0]):\n return 0\n else:\n break\n return 1\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n", "def partition(A,p,r):#A[p]〜A[r-1]までのリストをpartitionする\n x=A[r-1][1]\n i=p-1\n for j in range(p,r-1):\n if(A[j][1] <= x):\n i+=1\n A[j],A[i]=A[i],A[j]\n A[i+1],A[r-1]=A[r-1],A[i+1]\n return i+1\n\n\ndef quick_sort(A,p,r):\n if( p < r-1 ):\n q=partition(A,p,r)\n quick_sort(A,p,q)\n quick_sort(A,q+1,r)\n\n\n\n\ndef stability_judge(sorted,original):\n n=len(sorted)\n j=-1\n x=sorted[0][1]\n for i in range(n):\n if(x!=sorted[i][1]):\n x=sorted[i][1]\n j=-1\n\n while(1):\n j+=1\n if(x==original[j][1]):\n if(sorted[i][0]!=original[j][0]):\n return 0\n else:\n break\n return 1\n\n\n\n\n\nn=int(input())\noriginal_cards=[]\nfor loop in range(n):\n original_cards.append(list(input().split()))\nfor card in original_cards:\n card[1]=int(card[1])\n\nsorted_cards=[card for card in original_cards]\nquick_sort(sorted_cards,0,n)\n\nif(stability_judge(sorted_cards,original_cards)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n\n\nfor card in sorted_cards:\n card[1]=str(card[1])\n print(\" \".join(card))\n" ]
44
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n", "li = [input().splitlines()[0] for x in range(n)]\n\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n", "def quick_sort:\n \n\nli = [input().splitlines()[0] for x in range(n)]\n\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\n\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\n\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n\nprint(\"table\")\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\n\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n\nprint(\"table\")\nfor i in li:\n print(i)\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\n\n# print(f\"{li=}\")\n\nprint(\"table\")\nfor i in li:\n print(i)\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\n\nprint(\"table\")\nfor i in li:\n print(i)\n", "def quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition:\n \n \ndef quick_sort:\n \n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition:\n \n \ndef quick_sort:\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \ndef quick_sort:\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \n \n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \"\"\"パーティション分割\"\"\"\n \n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \"\"\"パーティション分割\"\"\"\n x = int(a[r].split()[1])\n i = p - 1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \"\"\"パーティション分割\"\"\"\n x = int(a[r].split()[1])\n i = p - 1\n for j in :\n if int(a[j].split()[1]) <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n", "def partition(a, p, r):\n \"\"\"パーティション分割\"\"\"\n x = int(a[r].split()[1])\n i = p - 1\n for j in range(p, r):\n if int(a[j].split()[1]) <= x:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n # パーティション分割し、基準値を取得\n q = partition(a, p, r)\n\n # 基準値を境目に更にパーティション分割を実施\n quick_sort(a, p, q-1)\n quick_sort(a, q+1, r)\n\n\nn = int(input())\nli = [input().splitlines()[0] for x in range(n)]\nstable = sorted(li, key=lambda x: int(x.split()[1]))\n# print(f\"{li=}\")\n# print(f\"{stable=}\")\n\nquick_sort(li, 0, n - 1)\n# print(f\"{li=}\")\nprint(\"S\" if stable == li else \"Not s\", end=\"\")\nprint(\"table\")\nfor i in li:\n print(i)\n" ]
23
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "num = list(map(int,num))\n", "count = [i for i in range(n)]\n\nnum = list(map(int,num))\n", "def partition:\n \n\ncount = [i for i in range(n)]\n\nnum = list(map(int,num))\n", "def partition:\n \n\ncount = [i for i in range(n)]\n\nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\n", "def partition:\n \n\nnum = [0]*n\ncount = [i for i in range(n)]\n\nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\n", "def partition:\n \n\nnum = [0]*n\ncount = [i for i in range(n)]\n\nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef checkStable(a,b):\n \n\nnum = [0]*n\ncount = [i for i in range(n)]\n\nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef checkStable(a,b):\n \n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\n\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n \n\ndef quickSort:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n \nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n \n\ndef quickSort:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort:\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort(a,b,c,p,r):\n \n\ndef checkStable(a,b):\n \n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort(a,b,c,p,r):\n \n\ndef checkStable(a,b):\n \n \nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n \n \nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n \n \nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n \nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n \nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\n for j in :\n \n\n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\n for j in :\n \n\n a[i+1],a[r] = a[r],a[i+1]\n \n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n \n\n for j in :\n \n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in :\n \n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n \n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in :\n \n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in :\n if x >= a[j]:\n i += 1\n a[i],a[j] = a[j],a[i]\n b[i],b[j] = b[j],b[i]\n c[i],c[j] = c[j],c[i]\n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in :\n if x >= a[j]:\n i += 1\n a[i],a[j] = a[j],a[i]\n b[i],b[j] = b[j],b[i]\n c[i],c[j] = c[j],c[i]\n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in :\n if a[i-1] == a[i]:\n if b[i-1] > b[i]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in :\n if x >= a[j]:\n i += 1\n a[i],a[j] = a[j],a[i]\n b[i],b[j] = b[j],b[i]\n c[i],c[j] = c[j],c[i]\n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in range(1,len(a)):\n if a[i-1] == a[i]:\n if b[i-1] > b[i]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "def partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in range(p,r):\n if x >= a[j]:\n i += 1\n a[i],a[j] = a[j],a[i]\n b[i],b[j] = b[j],b[i]\n c[i],c[j] = c[j],c[i]\n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in range(1,len(a)):\n if a[i-1] == a[i]:\n if b[i-1] > b[i]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n", "\ndef partition(a,b,c,p,r):\n x = a[r]\n i = p - 1\n\n for j in range(p,r):\n if x >= a[j]:\n i += 1\n a[i],a[j] = a[j],a[i]\n b[i],b[j] = b[j],b[i]\n c[i],c[j] = c[j],c[i]\n\n a[i+1],a[r] = a[r],a[i+1]\n b[i+1],b[r] = b[r],b[i+1]\n c[i+1],c[r] = c[r],c[i+1]\n return i+1\n\ndef quickSort(a,b,c,p,r):\n if p < r:\n q = partition(a,b,c,p,r)\n quickSort(a,b,c,p,q-1)\n quickSort(a,b,c,q+1,r)\n\ndef checkStable(a,b):\n for i in range(1,len(a)):\n if a[i-1] == a[i]:\n if b[i-1] > b[i]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\nmark = [\"\"]*n\nnum = [0]*n\ncount = [i for i in range(n)]\nfor i in range(n):\n mark[i],num[i] = input().split()\nnum = list(map(int,num))\n\nquickSort(num,mark,count,0,n-1)\nprint(checkStable(num,count))\nfor i in range(n):\n print(mark[i],num[i])\n" ]
33
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "s = []\n", "s = []\n\n\nl = copy.deepcopy(s)\n", "s = []\n\n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n", "def quickSort:\n \n\ns = []\n\n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n", "def quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n", "def quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n\n\nfor v in s:\n", "import copy\n\n\ndef quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n\n\nfor v in s:\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n\n\nfor v in s:\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\n\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition:\n \n \ndef quickSort:\n \n\nn = int(input())\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition(a, p, r):\n \n \ndef quickSort:\n \n\nn = int(input())\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\nn = int(input())\ns = []\nfor i in range(n):\n \n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n", "import copy\n\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n \n \ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n \n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p - 1\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p - 1\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p - 1\n for j in range(p, r):\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n", "import copy\n\n\ndef partition(a, p, r):\n x = int(a[r][1])\n i = p - 1\n for j in range(p, r):\n if int(a[j][1]) <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\n\nn = int(input())\ns = []\nfor i in range(n):\n s.append(input().split())\n\nl = copy.deepcopy(s)\nl.sort(key=lambda x: x[1])\n\nquickSort(s, 0, n - 1)\n\nprint(\"Stable\" if s == l else \"Not stable\")\nfor v in s:\n print(\" \".join(v))\n" ]
25
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "INF = 10 ** 10\n", "INF = 10 ** 10\n\n\nn = int(input())\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\nn = int(input())\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef quickSort:\n \n\nn = int(input())\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\n\n\nif A == B:\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\n\n\nif A == B:\n", "INF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n", "import copy\n\nINF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n", "import copy\n\nINF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n", "import copy\n\nINF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\n\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n \n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n countL = mergeSort(A, left, mid)\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if :\n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if L[i][1] <= R[j][1]:\n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if L[i][1] <= R[j][1]:\n \n i += 1\n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if L[i][1] <= R[j][1]:\n \n i += 1\n else:\n \n j += 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n \n j += 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n", "import copy\n\nINF = 10 ** 10\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count += 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\nA = [None for _ in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n - 1)\nmergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(map(str, A[i])))\n" ]
60
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "def is_stable(A, B):\n \n\nA = []\n", "def is_stable(A, B):\n \n\nA = []\nr = int(input())\n", "def is_stable(A, B):\n \n\nA = []\nr = int(input())\n\n\nB = list(A)\n", "def partition:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\n\n\nB = list(A)\n", "def partition:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\n\n\nB = list(A)\n\n\nif :\n", "def partition:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\n\n\nif :\n", "def partition:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\n\n\nif :\n \n\nfor x in A:\n", "def partition:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \n\nfor x in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \n\nfor x in A:\n", "def partition:\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \n\nfor x in A:\n", "def partition:\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \n\nfor x in A:\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \n\nfor x in A:\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n \nelse:\n \n\nfor x in A:\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n print('Stable')\nelse:\n \n\nfor x in A:\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif :\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n \n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n\nA = []\nr = int(input())\nfor _ in range(r):\n \n \nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n \nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n \nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n \nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n \n # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n q = A[r][1]\n # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n \n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n \n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in :\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in :\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n \n \nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in :\n \n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in :\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n \n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n \n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n if i == 0:\n pass\n \n \n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n if i == 0:\n pass\n \n del cA[i]\n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n if i == 0:\n pass\n elif :\n \n del cA[i]\n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n if i == 0:\n pass\n elif cA[i - 1][1] == x[1]:\n \n del cA[i]\n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n", "def partition(A, l, r):\n \"\"\" partition A[l:r] using q(A[r]) and return q's index\n \"\"\"\n q = A[r][1]\n sep_i = l # left elements of seq <= q < right ones\n for j in range(l, r):\n if A[j][1] <= q:\n # A[j] is left element\n\n # add A[j] to last of left, and replace first of right to last\n A[sep_i], A[j] = A[j], A[sep_i]\n sep_i += 1 # update separator\n else:\n # A[j] is right element\n pass\n\n A[sep_i], A[r] = A[r], A[sep_i]\n\n return sep_i\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r-1)\n quick_sort(A, l, q)\n quick_sort(A, q+1, r)\n\ndef is_stable(A, B):\n cA = list(A)\n for x in B:\n i = cA.index(x)\n if i == 0:\n pass\n elif cA[i - 1][1] == x[1]:\n return False\n del cA[i]\n return True\n\nA = []\nr = int(input())\nfor _ in range(r):\n mark, num = input().split()\n A.append([mark, int(num)])\n\nB = list(A)\nquick_sort(A, 0, r)\n\nif is_stable(A, B):\n print('Stable')\nelse:\n print('Not stable')\n\nfor x in A:\n print(*x)\n" ]
42
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def quicksort:\n", "def quicksort:\n \n\ndef main():\n", "def quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort:\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort(A, p, r):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\nif :\n main()\n", "def partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\nif :\n main()\n", "def partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n \n\n for i in :\n \n \nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n \n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n \n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n \n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in :\n \n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n \n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n if B[i][1] == B[i + 1][1]:\n if A.index(B[i]) > A.index(B[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n \n A.append([m, s])\n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n if B[i][1] == B[i + 1][1]:\n if A.index(B[i]) > A.index(B[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n s = int(s)\n A.append([m, s])\n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n if B[i][1] == B[i + 1][1]:\n if A.index(B[i]) > A.index(B[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n \n s = int(s)\n A.append([m, s])\n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n if B[i][1] == B[i + 1][1]:\n if A.index(B[i]) > A.index(B[i + 1]):\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for i in range(n):\n m, s = input().split()\n s = int(s)\n A.append([m, s])\n B = A[:]\n quicksort(B, 0, n-1)\n\n for i in range(n-1):\n if B[i][1] == B[i + 1][1]:\n if A.index(B[i]) > A.index(B[i + 1]):\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for i in range(n):\n print(*B[i])\n\n\nif __name__ == '__main__':\n main()\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "for card in cards:\n", "quick_sort(cards, 0, n - 1)\n\n\nfor card in cards:\n", "quick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "stable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "cards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "n = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n", "def partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n \n i = p-1\n \n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n \n i = p-1\n \n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n x = int(a[r].split()[1])\n i = p-1\n \n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n x = int(a[r].split()[1])\n i = p-1\n for j in :\n \n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n x = int(a[r].split()[1])\n i = p-1\n for j in range(p, r):\n \n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n", "def partition(a, p, r):\n x = int(a[r].split()[1])\n i = p-1\n for j in range(p, r):\n if int(a[j].split()[1]) <= x:\n i = i+1\n a[i], a[j] = a[j], a[i]\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\nn = int(input())\ncards = [input() for i in range(n)]\nstable = sorted(cards, key=lambda x: int(x.split()[1]))\nquick_sort(cards, 0, n - 1)\n\nprint(\"Stable\" if stable == cards else \"Not stable\")\n\nfor card in cards:\n print(card)\n" ]
20
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def partition(A,p,r):\n", "def partition(A,p,r):\n \n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndata = []\n\n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndata = []\nfor i in range(n):\n \n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in :\n \n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \n\nfor i in data:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n \n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n m,num = map(str,input().split())\n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n m,num = map(str,input().split())\n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "def partition(A,p,r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i+=1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n m,num = map(str,input().split())\n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in data:\n print(' '.join(str(d) for d in i))\n", "\ndef partition(A,p,r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i+=1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nn = int(input())\ndata = []\nfor i in range(n):\n m,num = map(str,input().split())\n data.append([m, int(num)])\ndata1 = data[:]\n\nquickSort(data,0,n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in data:\n print(' '.join(str(d) for d in i))\n" ]
26
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "A = []\n\n\nprint(stable(A,Q))\n", "A = []\n\nQ = A.copy()\n\nprint(stable(A,Q))\n", "A = []\n\nQ = A.copy()\n\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\nA = []\n\nQ = A.copy()\n\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\nA = []\n\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nA = []\n\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef stable(A,Q):\n \n\nA = []\n\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef stable(A,Q):\n \n\nn = int(input())\nA = []\n\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef stable(A,Q):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n i = p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n i = p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n", "def partition(A,p,r):\n \n i = p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in :\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n a[1]=int(a[1])\n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n a[1]=int(a[1])\n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n \nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in :\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in :\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in :\n if int(Q[i-1][1]) == int(Q[i][1]):\n x = A.index(Q[i-1])\n y = A.index(Q[i])\n if y<x:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in :\n if int(Q[i-1][1]) == int(Q[i][1]):\n x = A.index(Q[i-1])\n y = A.index(Q[i])\n if y<x:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in range(1,len(Q)):\n if int(Q[i-1][1]) == int(Q[i][1]):\n x = A.index(Q[i-1])\n y = A.index(Q[i])\n if y<x:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n", "def partition(A,p,r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quicksort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\n\n\ndef stable(A,Q):\n for i in range(1,len(Q)):\n if int(Q[i-1][1]) == int(Q[i][1]):\n x = A.index(Q[i-1])\n y = A.index(Q[i])\n if y<x:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n a = input().split()\n a[1]=int(a[1])\n A.append(a)\nQ = A.copy()\nquicksort(Q, 0, n-1)\nprint(stable(A,Q))\nfor i in range(len(Q)):\n print(Q[i][0], Q[i][1])\n" ]
30
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "A = []\n\n\nif is_stable:\n", "def partition(p, r):\n \n\nA = []\n\n\nif is_stable:\n", "def partition(p, r):\n \n\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\n\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\n\n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n \norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "import copy\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n cnt = 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n cnt += 1\n elif A[i+1] == orig_list[j]:\n large_idx = j\n cnt += 1\n if cnt == 2:\n break\n if small_idx > large_idx:\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = copy.deepcopy(A)\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "def key(pair):\n \n\nA = []\n", "def key(pair):\n \n\ndef quick_sort:\n \n\nA = []\n", "def key(pair):\n \n\ndef quick_sort:\n \n\nA = []\n\n\nfor s, n in sorted_A:\n", "def key(pair):\n \n\ndef quick_sort:\n \n\nA = []\nfor _ in range(N):\n \n\nfor s, n in sorted_A:\n", "def key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nA = []\nfor _ in range(N):\n \n\nfor s, n in sorted_A:\n", "def key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nA = []\nfor _ in range(N):\n \n\nquick_sort(sorted_A, 0, N - 1)\n\nfor s, n in sorted_A:\n", "def key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nquick_sort(sorted_A, 0, N - 1)\n\nfor s, n in sorted_A:\n", "def key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\n\nfor s, n in sorted_A:\n", "from import \n\n\ndef key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\n\nfor s, n in sorted_A:\n", "from import \n\n\ndef key(pair):\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from import \n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from import \n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import \n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import \n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import \n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n\ndef partitionize:\n \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n\ndef partitionize:\n x = A[r]\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n\ndef partitionize:\n x = A[r]\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize:\n x = A[r]\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize:\n x = A[r]\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n \n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n \n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n \n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n \n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n \n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n \n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n \nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n \n for k in scanned_ordered:\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n \n for k in scanned_ordered:\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n \n for k in scanned_ordered:\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in :\n \n for k in scanned_ordered:\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in :\n \n for k in scanned_ordered:\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in :\n s, n = a\n \n t, m = b\n \n for k in scanned_ordered:\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in :\n s, n = a\n \n t, m = b\n \n for k in scanned_ordered:\n if scanned_ordered.get(k, \"__NaN_1__\") != scanned_original.get(k, \"__NaN_2__\"):\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in :\n s, n = a\n \n t, m = b\n \n for k in scanned_ordered:\n if scanned_ordered.get(k, \"__NaN_1__\") != scanned_original.get(k, \"__NaN_2__\"):\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in zip(ordered, original):\n s, n = a\n \n t, m = b\n \n for k in scanned_ordered:\n if scanned_ordered.get(k, \"__NaN_1__\") != scanned_original.get(k, \"__NaN_2__\"):\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in zip(ordered, original):\n s, n = a\n \n t, m = b\n scanned_original[m].append(t)\n for k in scanned_ordered:\n if scanned_ordered.get(k, \"__NaN_1__\") != scanned_original.get(k, \"__NaN_2__\"):\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n", "from collections import defaultdict\n\n\ndef key(pair):\n _, n = pair\n return n\n\n\ndef partitionize(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if key(A[j]) <= key(x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partitionize(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\n\ndef is_stable(ordered, original):\n scanned_ordered = defaultdict(list)\n scanned_original = defaultdict(list)\n for a, b in zip(ordered, original):\n s, n = a\n scanned_ordered[n].append(s)\n t, m = b\n scanned_original[m].append(t)\n for k in scanned_ordered:\n if scanned_ordered.get(k, \"__NaN_1__\") != scanned_original.get(k, \"__NaN_2__\"):\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n s, n = input().split()\n A.append((s, int(n)))\nsorted_A = A.copy()\nquick_sort(sorted_A, 0, N - 1)\nprint(\"Stable\" if is_stable(sorted_A, A) else \"Not stable\")\nfor s, n in sorted_A:\n print(s, n)\n" ]
43
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "A = []\n\n\nif A == B:\n", "A = []\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n", "n = int(input())\nA = []\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n", "def quickSort:\n \n\nn = int(input())\nA = []\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n", "def quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\n\nif A == B:\n", "def quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\n\nquickSort(A, 0, n-1)\n\nif A == B:\n", "def quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nfor i in range(n):\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\n\n\nfor i in range(n):\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition:\n \n\ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition:\n x = A[r]\n \n \n A[r] = z\n \n\ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n \n \n A[r] = z\n \n\ndef quickSort(A, p, r):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n \n \n A[r] = z\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n \n \n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n \n for j in :\n \n \n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n \n for j in :\n \n \n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n \n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n \n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n \n z = A[i+1]\n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in :\n if int(A[j][2:]) <= int(x[2:]):\n i = i + 1\n y = A[i]\n A[i] = A[j]\n A[j] = y\n z = A[i+1]\n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(n):\n print(A[i])\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 1\n for j in range(p, r):\n if int(A[j][2:]) <= int(x[2:]):\n i = i + 1\n y = A[i]\n A[i] = A[j]\n A[j] = y\n z = A[i+1]\n A[i+1] = A[r]\n A[r] = z\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\nn = int(input())\nA = []\nfor i in range(n):\n A.append(str(input()))\n\nB = copy.deepcopy(A)\nB.sort(key = lambda x: int(x[2:]))\n\nquickSort(A, 0, n-1)\n\nif A == B:\n print('Stable')\nelse:\n print('Not stable')\n\nfor i in range(n):\n print(A[i])\n" ]
28
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "A = []\n\norig_list = A[:]\n", "A = []\n\norig_list = A[:]\n\nquick_sort(0, N-1)\n", "A = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n", "def is_stable():\n \n\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n", "def is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n", "def is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "def partition(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n\n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n \nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n \norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in :\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n cnt = 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n cnt += 1\n elif A[i+1] == orig_list[j]:\n large_idx = j\n cnt += 1\n if cnt == 2:\n break\n if small_idx > large_idx:\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n \n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n cnt = 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n cnt += 1\n elif A[i+1] == orig_list[j]:\n large_idx = j\n cnt += 1\n if cnt == 2:\n break\n if small_idx > large_idx:\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in :\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n cnt = 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n cnt += 1\n elif A[i+1] == orig_list[j]:\n large_idx = j\n cnt += 1\n if cnt == 2:\n break\n if small_idx > large_idx:\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n", "def partition(p, r):\n i = p\n for j in range(p, r):\n if A[r][1] >= A[j][1]:\n A[i], A[j] = A[j], A[i]\n i += 1\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q-1)\n quick_sort(q+1, r)\n\ndef is_stable():\n for i in range(N-1):\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n cnt = 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n cnt += 1\n elif A[i+1] == orig_list[j]:\n large_idx = j\n cnt += 1\n if cnt == 2:\n break\n if small_idx > large_idx:\n return False\n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\norig_list = A[:]\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "num = int(input())\n", "num = int(input())\n\n\nfor i in :\n", "num = int(input())\n\n\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\n\n\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\n\n\nis_stable = True\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\n\ncard_list = [(t[0], int(t[1])) for t in card_list]\n\n\nis_stable = True\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\n\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\n\nis_stable = True\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\n\nis_stable = True\nfor i in :\n \n\nfor t in card_list:\n", "def quick_sort:\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition:\n \n\ndef quick_sort:\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition:\n \n\ndef quick_sort:\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition:\n \n \ndef quick_sort:\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition:\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n \n\nfor t in card_list:\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n \n\nif is_stable:\n print(\"Stable\")\n\n\nfor t in card_list:\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\n\n\nfor t in card_list:\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in :\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\n\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n \n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\n\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\n\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \n arr[i+1], arr[r] = arr[r], arr[i+1]\n \n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \n arr[i+1], arr[r] = arr[r], arr[i+1]\n \n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n \n for j in :\n \n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n \n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n i = p - 1\n for j in :\n \n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n \n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n \n i = p - 1\n for j in :\n \n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n return i+1\n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n x = arr[r][1]\n i = p - 1\n for j in :\n \n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n return i+1\n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n x = arr[r][1]\n i = p - 1\n for j in :\n if arr[j][1] <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n return i+1\n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n", "def partition(arr, p, r):\n x = arr[r][1]\n i = p - 1\n for j in range(p, r):\n if arr[j][1] <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n\n arr[i+1], arr[r] = arr[r], arr[i+1]\n return i+1\n\ndef quick_sort(arr, p, r):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q-1)\n quick_sort(arr, q+1, r)\n\nnum = int(input())\ncard_list = [input().split() for s in range(num)]\ncard_list = [(t[0], int(t[1])) for t in card_list]\ncp_card_list = card_list[:]\n\nquick_sort(card_list, 0, len(card_list) - 1)\n\nis_stable = True\nfor i in range(len(card_list) - 1):\n if card_list[i][1] == card_list[i+1][1]:\n if cp_card_list.index(card_list[i]) > cp_card_list.index(card_list[i+1]):\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor t in card_list:\n print(t[0], t[1])\n" ]
29
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "Main()\n", "def Partition:\n \n\nMain()\n", "def Partition:\n \n\ndef Main():\n\n \nMain()\n", "class card():\n \n\ndef Partition:\n \n\ndef Main():\n\n \nMain()\n", "class card():\n \n\ndef Partition:\n \n\ndef QuickSort:\n \n\ndef Main():\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition:\n \n\ndef QuickSort:\n \n\ndef Main():\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n\ndef QuickSort:\n \n\ndef Main():\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n\ndef QuickSort:\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n\ndef QuickSort:\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \n flag = 1\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \n flag = 1\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n \ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \n flag = 1\n\n \nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n \ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n i = p - 1\n\n \ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n \n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n i = p - 1\n\n \ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n i = p - 1\n\n for j in :\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n \n i = p - 1\n\n for j in :\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n \ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n \n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n if flag:\n \n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n if flag:\n \n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n if flag:\n \n \n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in :\n \n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n \n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n \n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n \n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n \n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n \n\n for i in :\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n \n\n for i in :\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n \n\n for i in range(len(cards)):\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n S, N = input().split()\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n \n\n for i in range(len(cards)):\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n S, N = input().split()\n \n \n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in range(len(cards)):\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n S, N = input().split()\n \n cards.append(c)\n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in range(len(cards)):\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n", "class card():\n def __init__(self, suit, number):\n self.s = suit\n self.n = number\n\ndef Partition(A, p, r):\n x = int(A[r].n)\n i = p - 1\n\n for j in range(p, r):\n if int(A[j].n) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n\n return i + 1\n\ndef QuickSort(A, p, r):\n if p < r:\n q = Partition(A, p, r)\n QuickSort(A, p, q - 1)\n QuickSort(A, q + 1, r)\n\ndef Main():\n\n n = int(input())\n cards = list()\n\n for i in range(n):\n S, N = input().split()\n c = card(S, N)\n cards.append(c)\n\n reference = sorted(cards, key=lambda x: int(x.n))\n QuickSort(cards, 0, len(cards) - 1)\n\n flag = 1\n\n for i in range(len(cards)):\n if cards[i].s != reference[i].s or cards[i].n != reference[i].n :\n flag = 0\n break;\n\n if flag:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in range(len(cards)):\n print(\"{0} {1}\".format(cards[i].s, cards[i].n))\n\nMain()\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "import sys\n", "import sys\n\n\ndef merge:\n", "import sys\n\n\ndef merge:\n \n\ndef merge_sort:\n", "import sys\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nif :\n", "import sys\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nif :\n", "import copy\nimport sys\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nif :\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nif :\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif :\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif :\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge:\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition:\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort:\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n \n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n \n \n k = left\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n \n \n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n \n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n \n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n \n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n \n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n \n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n \n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n \n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while :\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in :\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n \n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n print('Stable')\n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if :\n print('Stable')\n else:\n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n \n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n \n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n \n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if :\n \n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if :\n \n i += 1\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if :\n \n i += 1\n else:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if L[i][1] <= R[j][1]:\n \n i += 1\n else:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n \n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n \n j += 1\n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n", "import copy\nimport sys\n\ndef partition(A, p, r):\n key = A[r][1]\n i = p\n for j in range(p, r):\n # 把小的放在左边\n if A[j][1] <= key:\n A[i], A[j] = A[j], A[i]\n i += 1\n # 最后交换key值\n A[r], A[i] = A[i], A[r]\n return i\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid] + [(0, sys.maxsize)]\n R = A[mid: right] + [(0, sys.maxsize)]\n i = j = 0\n k = left\n while k < right:\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n k += 1\n\ndef merge_sort(A, left, right):\n if right - left > 1:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\n\nif __name__ == '__main__':\n n = int(input())\n numlist = []\n for _ in range(n):\n datas = input().split(' ')\n numlist.append((datas[0], int(datas[1])))\n list2 = copy.deepcopy(numlist)\n quick_sort(numlist, 0, n - 1)\n merge_sort(list2, 0, n)\n if list2 == numlist:\n print('Stable')\n else:\n print('Not stable')\n for c, num in numlist:\n print('%s %d' % (c, num))\n" ]
51
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def bubbleSort(a, n):\n", "def bubbleSort(a, n):\n \n\nif :\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n \n\nif :\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n \n\nif __name__ == '__main__':\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n \n b = cards[:]\n", "class Quicksort:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n \n b = cards[:]\n", "class Quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n \n b = cards[:]\n", "class Quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n \n b = cards[:]\n x = Quicksort()\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n \n b = cards[:]\n x = Quicksort()\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n \n b = cards[:]\n x = Quicksort()\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n \n b = sorted(b, key=lambda i: i[1])\n\n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while :\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while :\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n \n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while :\n \n \nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while :\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n \n \n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n \n\n for i in a:\n", "class Quicksort:\n def quicksort:\n \n\n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n \n\n for i in a:\n", "class Quicksort:\n def quicksort:\n \n \n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n \n\n for i in a:\n", "class Quicksort:\n def quicksort:\n \n \n def partion:\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n", "class Quicksort:\n def quicksort:\n \n \n def partion:\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n", "class Quicksort:\n def quicksort:\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n \n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n i = p - 1\n \n \ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n \n i = p - 1\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n \n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n \n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in :\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n \n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n if a[j][1] < a[j - 1][1]:\n a[j], a[j-1] = a[j-1], a[j]\n flag = 1\n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n self.quicksort(a, p, q - 1)\n \n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n if a[j][1] < a[j - 1][1]:\n a[j], a[j-1] = a[j-1], a[j]\n flag = 1\n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n \n self.quicksort(a, p, q - 1)\n self.quicksort(a, q + 1, r)\n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n if a[j][1] < a[j - 1][1]:\n a[j], a[j-1] = a[j-1], a[j]\n flag = 1\n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n", "class Quicksort:\n def quicksort(self, a, p, r):\n if p < r:\n q = self.partion(a, p, r)\n self.quicksort(a, p, q - 1)\n self.quicksort(a, q + 1, r)\n return(a)\n\n def partion(self, a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i+1)\n\ndef bubbleSort(a, n):\n flag = 1\n while flag == 1:\n flag = 0\n for j in range(n-1, 0, -1):\n if a[j][1] < a[j - 1][1]:\n a[j], a[j-1] = a[j-1], a[j]\n flag = 1\n return(a)\n\nif __name__ == '__main__':\n n = int(input().rstrip())\n cards = []\n for i in range(n):\n tmp = input().rstrip().split(\" \")\n tmp[1] = int(tmp[1])\n cards.append(tmp)\n a = cards[:]\n b = cards[:]\n x = Quicksort()\n a = x.quicksort(a, 0, n-1)\n b = sorted(b, key=lambda i: i[1])\n\n if a == b:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for i in a:\n i[1] = str(i[1])\n print(\" \".join(i))\n" ]
51
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "if :\n", "for i in range(N):\n \n\nif :\n", "for i in range(N):\n \ndef partition(A,p,r):\n \n\nif :\n", "N=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \n\nif :\n", "from sys import stdin\nN=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \n\nif :\n", "from sys import stdin\nN=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \n\ndef check(A):\n \n\nif :\n", "from sys import stdin\nN=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \n\ndef check(A):\n \n\nif :\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \ndef check(A):\n \n\nif :\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\n\nfor i in range(N):\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \ndef check(A):\n \nquicksort(num_list,0,N-1)\nif :\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \ndef check(A):\n \nquicksort(num_list,0,N-1)\nif :\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n \ndef check(A):\n \nquicksort(num_list,0,N-1)\nif :\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n \ndef check(A):\n \nquicksort(num_list,0,N-1)\nif check(num_list):\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \nquicksort(num_list,0,N-1)\nif check(num_list):\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \nquicksort(num_list,0,N-1)\nif check(num_list):\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n \n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\n\nfor i in num_list:\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\n\nfor i in num_list:\n del i[2]\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n \n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n \n \ndef partition(A,p,r):\n \n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n \ndef partition(A,p,r):\n \n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n \ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in :\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in range(N-1):\n \n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in range(N-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:\n return 0\n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n", "from sys import stdin\nN=int(input())\nnum_list=[]\nfor i in range(N):\n line = list(stdin.readline().strip().split())\n num_list.append([line[0],int(line[1]),i])\ndef partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\ndef check(A):\n for i in range(N-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:\n return 0\n return 1\nquicksort(num_list,0,N-1)\nif check(num_list):\n print(\"Stable\")\nelse:print(\"Not stable\")\nfor i in num_list:\n del i[2]\n print(*i)\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def isStable:\n", "def isStable:\n \n\nif :\n", "def qSort:\n \n\ndef isStable:\n \n\nif :\n", "def partition:\n \n\ndef qSort:\n \n\ndef isStable:\n \n\nif :\n", "def partition:\n \n\ndef qSort:\n \n\ndef isStable:\n \n \nif :\n", "def partition:\n \n\ndef qSort:\n \n\ndef isStable:\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n\ndef qSort:\n \n\ndef isStable:\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n\ndef qSort:\n \n\ndef isStable(input_array, output_array):\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n i = p-1\n \n \ndef qSort:\n \n\ndef isStable(input_array, output_array):\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n i = p-1\n \n \ndef qSort(hoge, p, r):\n \n\ndef isStable(input_array, output_array):\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n i = p-1\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n \n \nif __name__ == '__main__':\n", "def partition(hoge, p, r):\n \n i = p-1\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n \n \nif __name__ == '__main__':\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n \n i = p-1\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n \n i = p-1\n for j in :\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n \n i = p-1\n for j in :\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n \n i = p-1\n for j in :\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n \n \ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n \n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n \n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n \n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n \n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n \n for _ in :\n \n \n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n \n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in :\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n \n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in :\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n \n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if :\n \n \n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n \n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if :\n \n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n \n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if :\n \n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n \n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if :\n \n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if :\n \n else:\n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != :\n \n else:\n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != :\n \n \n else:\n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != :\n now_num = int(elem[1])\n \n else:\n \n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != :\n now_num = int(elem[1])\n \n else:\n for c in same_nums:\n if input_array.index(c) > input_array.index(elem):\n return 'Not stable'\n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != :\n now_num = int(elem[1])\n same_nums = list()\n else:\n for c in same_nums:\n if input_array.index(c) > input_array.index(elem):\n return 'Not stable'\n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n", "def partition(hoge, p, r):\n x = int(hoge[r][1])\n i = p-1\n for j in range(p, r):\n if int(hoge[j][1]) <= x:\n i += 1\n tmp = hoge[i]\n hoge[i] = hoge[j]\n hoge[j] = tmp\n tmp = hoge[i+1]\n hoge[i+1] = hoge[r]\n hoge[r] = tmp\n return i+1\n\ndef qSort(hoge, p, r):\n if p < r:\n q = partition(hoge, p, r)\n qSort(hoge, p, q-1)\n qSort(hoge, q+1, r)\n\ndef isStable(input_array, output_array):\n same_nums = list()\n now_num = 0\n for elem in output_array:\n if now_num != int(elem[1]):\n now_num = int(elem[1])\n same_nums = list()\n else:\n for c in same_nums:\n if input_array.index(c) > input_array.index(elem):\n return 'Not stable'\n same_nums.append(elem)\n return 'Stable'\n\nif __name__ == '__main__':\n num = int(input())\n hoge = list()\n for _ in range(num):\n c, s = input().split()\n hoge.append((c,s))\n origin = hoge[:]\n qSort(hoge, 0, len(hoge)-1)\n print(isStable(origin, hoge))\n print('\\n'.join(['{0[0]} {0[1]}'.format(x) for x in hoge]))\n" ]
45
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "main()\n", "from operator import \n\n\nmain()\n", "from operator import \n\n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef partition:\n \n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \nmain()\n", "from operator import \nclass Card:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n \n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n for _ in range(n):\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n for _ in range(n):\n \n \n quickSort(A, 0, n-1)\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n \n A = []\n for _ in range(n):\n \n \n quickSort(A, 0, n-1)\n if :\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n quickSort(A, 0, n-1)\n if :\n \n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n \n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n \n for p in A:\n \nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n \n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n else:\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j].number <= x.number:\n i = i + 1\n tp = A[j]\n A[j] = A[i]\n A[i] = tp\n else:\n continue\n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if :\n print('Stable')\n else:\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j].number <= x.number:\n i = i + 1\n tp = A[j]\n A[j] = A[i]\n A[i] = tp\n else:\n continue\n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n \n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if A == comp:\n print('Stable')\n else:\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j].number <= x.number:\n i = i + 1\n tp = A[j]\n A[j] = A[i]\n A[i] = tp\n else:\n continue\n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n \n A.append(Card(suit, int(num)))\n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if A == comp:\n print('Stable')\n else:\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j].number <= x.number:\n i = i + 1\n tp = A[j]\n A[j] = A[i]\n A[i] = tp\n else:\n continue\n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n suit, num = map(str, input().split())\n A.append(Card(suit, int(num)))\n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if A == comp:\n print('Stable')\n else:\n \n for p in A:\n print(p.suit, p.number)\nmain()\n", "from operator import attrgetter\nclass Card:\n def __init__(self, suit, number):\n self.suit = suit\n self.number = number\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j].number <= x.number:\n i = i + 1\n tp = A[j]\n A[j] = A[i]\n A[i] = tp\n else:\n continue\n A[r] = A[i+1]\n A[i+1] = x\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n for _ in range(n):\n suit, num = map(str, input().split())\n A.append(Card(suit, int(num)))\n comp = sorted(A, key=attrgetter('number'))\n quickSort(A, 0, n-1)\n if A == comp:\n print('Stable')\n else:\n print('Not stable')\n for p in A:\n print(p.suit, p.number)\nmain()\n" ]
34
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\nD = {}\n\n\nok = 1\n", "import sys\n\n\nA = []\nD = {}\n\n\nok = 1\n", "import sys\n\n\nA = []\nD = {}\n\n\nok = 1\n\n\nif ok:\n", "import sys\n\n\nA = []\nD = {}\nfor i in range(N):\n \n\nok = 1\n\n\nif ok:\n", "import sys\n\n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\n\nok = 1\n\n\nif ok:\n", "import sys\n\n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\n\nok = 1\n\n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\n\n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition:\n \n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\n\n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition:\n \n\ndef quickSort:\n \n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\n\n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition:\n \n\ndef quickSort:\n \n\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n \n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition:\n \n\ndef quickSort:\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n \n\nif ok:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition:\n \n\ndef quickSort:\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n \n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quickSort:\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n \n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quickSort:\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort:\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n \n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n A.append((v, int(d)))\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n A.append((v, int(d)))\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n \n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n \n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n \n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n A, q = partition(A, p, r)\n \n \n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n A, q = partition(A, p, r)\n \n A = quickSort(A, q+1, r)\n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n", "import sys\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return A, i+1\n\ndef quickSort(A, p, r):\n if p < r:\n A, q = partition(A, p, r)\n A = quickSort(A, p, q-1)\n A = quickSort(A, q+1, r)\n return A\n\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = sys.stdin.readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\nout_A = quickSort(A,0,N-1)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\n\nif ok:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(*out_A[i],sep=\" \")\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "for i in range(n):\n", "for i in range(n):\n \n\ndef partition(p, r):\n", "for i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n", "suits = [0] * n\n\n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n", "suits = [0] * n\n\n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n \n\nfor i in range(n):\n", "suits = [0] * n\nranks = [0] * n\n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n \n\nfor i in range(n):\n", "suits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n\ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n \nelse:\n \n\nfor i in range(n):\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n \nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\nfor i in :\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n \n i += 1\n \n \n return i\n\nquicksort(0, n-1)\n\nfor i in :\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n \n\ndef partition(p, r):\n \n \n i += 1\n \n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n \n \n i += 1\n \n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n \n i += 1\n \n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n \n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \n ranks[i] = int(rank)\n \n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n \n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \n ranks[i] = int(rank)\n \n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n i = p - 1\n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n \n i = p - 1\n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n \n \n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n \n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n \n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n \n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n \n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n \n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n suits[i], suits[r] = suits[r], suits[i]\n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n suits[i] = suit\n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n suits[i], suits[r] = suits[r], suits[i]\n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n \n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n suits[i] = suit\n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in :\n \n i += 1\n suits[i], suits[r] = suits[r], suits[i]\n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n suits[i] = suit\n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in range(p, r):\n \n i += 1\n suits[i], suits[r] = suits[r], suits[i]\n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor i in range(n):\n print(suits[i], ranks[i])\n", "n = int(input())\nsuits = [0] * n\nranks = [0] * n\norders = [0] * n\nfor i in range(n):\n suit, rank = input().split()\n suits[i] = suit\n ranks[i] = int(rank)\n orders[i] = i\n\ndef quicksort(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\ndef partition(p, r):\n global suits, ranks, orders\n x = ranks[r]\n i = p - 1\n for j in range(p, r):\n if ranks[j] <= x:\n i += 1\n suits[i], suits[j] = suits[j], suits[i]\n ranks[i], ranks[j] = ranks[j], ranks[i]\n orders[i], orders[j] = orders[j], orders[i]\n i += 1\n suits[i], suits[r] = suits[r], suits[i]\n ranks[i], ranks[r] = ranks[r], ranks[i]\n orders[i], orders[r] = orders[r], orders[i]\n return i\n\nquicksort(0, n-1)\n\nfor i in range(1, n):\n if ranks[i] == ranks[i-1] and orders[i] < orders[i-1]:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor i in range(n):\n print(suits[i], ranks[i])\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "X = []\n\n\nY = X[:]\n", "n = int(input())\nX = []\n\n\nY = X[:]\n", "n = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n", "def quicksort:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n\n\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n\n\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\n\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n \n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort:\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n \n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n \n\ndef merge:\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n \n\ndef merge(A, left, mid, right):\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n \n \ndef merge(A, left, mid, right):\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n \n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n \n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n \n L.append([0, 10**9])\n \n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n \n L.append([0, 10**9])\n \n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n for i in :\n \n \n L.append([0, 10**9])\n \n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n for i in :\n \n \n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n \nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n \ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n \n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n \n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n L.append(A[left+i])\n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in :\n L.append(A[left+i])\n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in :\n \n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in :\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in :\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in :\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in range(len(A)):\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in :\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in range(len(A)):\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in range(n2):\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in range(len(A)):\n \n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in range(n2):\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in range(len(A)):\n if A[i] != B[i]:\n return \"Not stable\"\n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in range(n2):\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n \n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n (A[i], A[j]) = (A[j], A[i])\n\n (A[i+1], A[r]) = (A[r], A[i+1])\n\n return i+1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef stable(A, B):\n for i in range(len(A)):\n if A[i] != B[i]:\n return \"Not stable\"\n return \"Stable\"\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = []\n R = []\n\n for i in range(n1):\n L.append(A[left+i])\n for i in range(n2):\n R.append(A[mid+i])\n\n L.append([0, 10**9])\n R.append([0, 10**9])\n\n i = 0\n j = 0\n\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right)//2\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\nX = []\nfor i in range(n):\n a = input().split()\n X.append([a[0], int(a[1])])\n\nY = X[:]\nquicksort(X, 0, n-1)\nmergeSort(Y, 0, n)\nprint(stable(X, Y))\nfor elem in X:\n print(\" \".join(map(str, elem)))\n" ]
49
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n\n\np = 0;\n", "A = []\n\n\nB = sorted(A, key=lambda x: x[1])\np = 0;\n", "A = []\nn = int(input())\n\nB = sorted(A, key=lambda x: x[1])\np = 0;\n", "A = []\nn = int(input())\n\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\n", "def patation:\n \n\nA = []\nn = int(input())\n\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\n", "def patation:\n \n\nA = []\nn = int(input())\n\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\n", "def patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\n\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\n", "def patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\n", "def patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort:\n \n\ndef patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n \n\ndef patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation:\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation:\n \n \n ; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n \nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation:\n \n \n ; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n \n \n ; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n \n \n for j in :\n \n ; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n \n i = p - 1\n for j in :\n \n ; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n \n i = p - 1\n for j in :\n \n tmp = A[i+1]; ; \n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n \n i = p - 1\n for j in :\n \n tmp = A[i+1]; ; A[r] = tmp\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; ; A[r] = tmp\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n \n\ndef print_list(A):\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n \n\ndef print_list(A):\n \n\n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n \n\ndef print_list(A):\n if A == B:\n \n \n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n \n \n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n \n\n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n else:\n \n\n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n if int(A[j][1]) <= x:\n i += 1\n tmp = A[i]; A[i] = A[j]; A[j] = tmp\n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n else:\n \n\n for line in A:\n \n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n if int(A[j][1]) <= x:\n i += 1\n tmp = A[i]; A[i] = A[j]; A[j] = tmp\n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n else:\n \n\n for line in A:\n print(line[0], line[1])\n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i += 1\n tmp = A[i]; A[i] = A[j]; A[j] = tmp\n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n else:\n \n\n for line in A:\n print(line[0], line[1])\n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n", "def quicksort(A, p, r):\n if p < r:\n q = patation(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\ndef patation(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i += 1\n tmp = A[i]; A[i] = A[j]; A[j] = tmp\n tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp\n return i+1\n\ndef print_list(A):\n if A == B:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for line in A:\n print(line[0], line[1])\n\nA = []\nn = int(input())\nfor i in range(n):\n A.append(input().split())\nB = sorted(A, key=lambda x: x[1])\np = 0; r = n - 1\nquicksort(A, p, r)\nprint_list(A)\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A=[]\n", "def partition(A,p,r):\n \n\nA=[]\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n\nquick=checkStable()\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n\nquick=checkStable()\n\n\nprint(stable)\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n\nquick=checkStable()\n\n\nquickSort(A,0,n-1)\n\nprint(stable)\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\n\nprint(stable)\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\n\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\n\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n \ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n \ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n", "def partition(A,p,r):\n \n i=p-1\n \n \ndef quickSort(A,p,r):\n \n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n \n \ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n \nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n \n i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n \n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n \n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n \n def isStable(self,A):\n \n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in :\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n \n def isStable(self,A):\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n \n def isStable(self,A):\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]]=[A[i][0]]\n def isStable(self,A):\n \n \nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]]=[A[i][0]]\n def isStable(self,A):\n \n return \"Stable\"\n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]]=[A[i][0]]\n def isStable(self,A):\n for i in :\n \n return \"Stable\"\n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]]=[A[i][0]]\n def isStable(self,A):\n for i in :\n if self.d[A[i][1]].pop(0)!=A[i][0]:\n return \"Not stable\"\n return \"Stable\"\n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n", "def partition(A,p,r):\n x=A[r][1]\n i=p-1\n for j in range(p,r):\n if A[j][1]<=x:\n i+=1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quickSort(A,p,q-1)\n quickSort(A,q+1,r)\n\nclass checkStable:\n def __init__(self):\n self.d={}\n def storeCards(self,A):\n for i in range(len(A)):\n if A[i][1] in self.d:\n self.d[A[i][1]].append(A[i][0])\n else:\n self.d[A[i][1]]=[A[i][0]]\n def isStable(self,A):\n for i in range(len(A)):\n if self.d[A[i][1]].pop(0)!=A[i][0]:\n return \"Not stable\"\n return \"Stable\"\n\nn=int(input())\nA=[]\nfor _ in range(n):\n mark,num=input().split()\n num=int(num)\n A.append([mark,num])\nquick=checkStable()\nquick.storeCards(A)\n\nquickSort(A,0,n-1)\nstable=quick.isStable(A)\nprint(stable)\nfor i in range(n):\n print(*A[i])\n" ]
37
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "for (a, s) in :\n", "n = int(input())\n\n\nfor (a, s) in :\n", "n = int(input())\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n", "def partition:\n \n\nn = int(input())\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n", "def partition:\n \n\nn = int(input())\n\n\nstable_list = []\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\n\nstable_list = []\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nfor (a, s) in :\n \nprint(is_stable)\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\n\nfor (a, s) in :\n \nprint(is_stable)\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\n\nfor (a, s) in :\n \nprint(is_stable)\n", "def partition:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\n\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\n\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\n\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n \n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n \n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n \n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n \nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from import defaultdict\n\ndef partition:\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n\ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \ndef quick_sort(arr, p: int, r: int):\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in :\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n \n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n \n i = p - 1\n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n x = int(arr[r][1])\n i = p - 1\n for j in :\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n x = int(arr[r][1])\n i = p - 1\n for j in range(p, r):\n \n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n", "from collections import defaultdict\n\ndef partition(arr, p: int, r: int):\n x = int(arr[r][1])\n i = p - 1\n for j in range(p, r):\n if int(arr[j][1]) <= x:\n i += 1\n arr[i], arr[j] = arr[j], arr[i]\n arr[i + 1], arr[r] = arr[r], arr[i + 1]\n return i + 1\n\ndef quick_sort(arr, p: int, r: int):\n if p < r:\n q = partition(arr, p, r)\n quick_sort(arr, p, q - 1)\n quick_sort(arr, q + 1, r)\n\nn = int(input())\narr = [input().split() for _ in range(n)]\nstable_dict = defaultdict(list)\nstable_list = []\n\nfor a in arr:\n stable_dict[int(a[1])].append(a[0])\n\nstable_dict = sorted(stable_dict.items(), key = lambda x: x[0])\n\nfor key, values in stable_dict:\n for v in values:\n stable_list.append([v, str(key)])\n\nquick_sort(arr, 0, n - 1)\n\nis_stable = 'Stable'\nfor (a, s) in zip(arr, stable_list):\n if ''.join(a) != ''.join(s):\n is_stable = 'Not stable'\n break\nprint(is_stable)\n\nfor a in arr:\n print(*a)\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# coding: utf-8\n", "# coding: utf-8\n\n\ndef partition:\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef printCards(A, n):\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef printCards(A, n):\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef printCards(A, n):\n \n\nquickSort(cards, 0, n-1)\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef printCards(A, n):\n \n\nquickSort(cards, 0, n-1)\n\n\nprintCards(cards, n)\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nquickSort(cards, 0, n-1)\n\n\nprintCards(cards, n)\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\n\n\nquickSort(cards, 0, n-1)\n\n\nprintCards(cards, n)\n", "# coding: utf-8\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\n\nquickSort(cards, 0, n-1)\n\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\n\nquickSort(cards, 0, n-1)\n\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\n\nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n \nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n \nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n \nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n \nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif :\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort:\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif :\n \nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif :\n \nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif :\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef isStable(A, n):\n \n\ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef isStable(A, n):\n \n \ndef printCards(A, n):\n \n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef isStable(A, n):\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n \n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n \n \ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n \n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n \n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n \n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n \n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n if A[i+1].number == A[i].number and A[i+1].initial < A[i].initial:\n flag = False\n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p,r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n if A[i+1].number == A[i].number and A[i+1].initial < A[i].initial:\n flag = False\n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p,r):\n if A[j].number <= x:\n i += 1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in :\n if A[i+1].number == A[i].number and A[i+1].initial < A[i].initial:\n flag = False\n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n", "# coding: utf-8\n\nclass Card:\n def __init__(self, card, initial):\n self.mark = card[0]\n self.number = int(card[1])\n self.initial = initial\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p,r):\n if A[j].number <= x:\n i += 1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef isStable(A, n):\n flag = True\n for i in range(n-1):\n if A[i+1].number == A[i].number and A[i+1].initial < A[i].initial:\n flag = False\n return flag\n\ndef printCards(A, n):\n for i in range(n):\n print(A[i].mark, end=\" \")\n print(A[i].number)\n\nn = int(input().rstrip())\ncards = []\nfor i in range(n):\n cards.append(Card(input().rstrip().split(), i))\nquickSort(cards, 0, n-1)\nif isStable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nprintCards(cards, n)\n" ]
36
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "li = []\n", "def partition:\n \n\nli = []\n", "def partition:\n \n\nli = []\n\n\nfor i in :\n", "def partition:\n \n\nli = []\n\nfor i in :\n \n\nfor i in :\n", "def partition:\n \n\nli = []\n\nfor i in :\n \n\nfor i in :\n \n\nfor i, n in :\n", "def partition:\n \n\nli = []\nbase_li = []\nfor i in :\n \n\nfor i in :\n \n\nfor i, n in :\n", "def partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \n\nfor i in :\n \n\nfor i, n in :\n", "import copy\n\n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \n\nfor i in :\n \n\nfor i, n in :\n", "import copy\n\n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \n\nquicksort(li, 0, length - 1)\n\nfor i in :\n \n\nfor i, n in :\n", "import copy\n\n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in :\n \n\nfor i, n in :\n", "import copy\n\ndef quicksort:\n # print(li, ini_i, length)\n \n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in :\n \n\nfor i, n in :\n", "import copy\n\ndef quicksort:\n # print(li, ini_i, length)\n \n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \n\nfor i, n in :\n", "import copy\n\ndef quicksort:\n # print(li, ini_i, length)\n \n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \n\nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n \n\ndef partition:\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \n\nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n \n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \n\nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n \n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \nelse:\n \nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \nelse:\n \nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in :\n \n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \nelse:\n \nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n \nelse:\n \nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n \nfor i, n in :\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n \nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n \n # print(f\"its {ini_i}\")\n \n \nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n \nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n \n # print(f\"its {ini_i}\")\n \n \nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n \nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n \n \nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n \nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n \n \nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n \n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n \n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n target = li[length][1]\n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n \n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n target = li[length][1]\n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n \n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n t = input().split(\" \")\n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n target = li[length][1]\n # print(target, li, ini_i, length)\n for i in :\n \n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n return ini_i\n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n t = input().split(\" \")\n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n target = li[length][1]\n # print(target, li, ini_i, length)\n for i in :\n if li[i][1] <= target:\n li[ini_i], li[i] = li[i], li[ini_i]\n ini_i += 1\n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n return ini_i\n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n t = input().split(\" \")\n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n", "import copy\n\ndef quicksort(li, ini_i, length):\n # print(li, ini_i, length)\n if ini_i < length:\n next_len = partition(li, ini_i, length)\n # print(next_len)\n quicksort(li, ini_i, next_len - 1)\n quicksort(li, next_len + 1, length)\n\ndef partition(li, ini_i, length):\n target = li[length][1]\n # print(target, li, ini_i, length)\n for i in range(ini_i, length):\n if li[i][1] <= target:\n li[ini_i], li[i] = li[i], li[ini_i]\n ini_i += 1\n # print(f\"its {ini_i}\")\n li[ini_i], li[length] = li[length], li[ini_i]\n return ini_i\n\nlength = int(input())\nli = []\nbase_li = []\nfor i in range(length):\n t = input().split(\" \")\n t[1] = int(t[1])\n base_li.append(t)\nli = copy.deepcopy(base_li)\n\nquicksort(li, 0, length - 1)\n\nfor i in range(length - 1):\n if li[i + 1][1] == li[i][1]:\n if base_li.index(li[i + 1]) < base_li.index(li[i]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\nfor i, n in enumerate(li):\n print(*n)\n" ]
33
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#A = [None for i in range(n)]\nA = []\n", "import copy\n\n\n#A = [None for i in range(n)]\nA = []\n", "import copy\n\n\ndef partition:\n \n\n#A = [None for i in range(n)]\nA = []\n", "import copy\n\n\ndef partition:\n \n\n#A = [None for i in range(n)]\nA = []\n\n\nB = copy.deepcopy(A)\n", "import copy\n\n\ndef partition:\n \n\n#A = [None for i in range(n)]\nA = []\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\n#A = [None for i in range(n)]\nA = []\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n\n\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n\n\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n\n\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\n\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n \n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort:\n \n return 0\n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition:\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition:\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge:\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition:\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition:\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n \n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n \n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n for k in :\n \n \ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n for k in :\n \n return count\n\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n \n for k in :\n \n return count\n\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n \n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n \n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n else:\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n else:\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n i = i + 1\n else:\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n \n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\n\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF, INF)]\n R = A[mid:right] + [(INF, INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n return count\n\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q - 1)\n quickSort(A, q + 1, r)\n\nn = int(input())\n#A = [None for i in range(n)]\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([a, int(b)])\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n" ]
63
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "cards=[]\n", "def isstable(A, n):\n \n\ncards=[]\n", "def quicksort:\n \n\ndef isstable(A, n):\n \n\ncards=[]\n", "def quicksort:\n \n\ndef isstable(A, n):\n \n\ncards=[]\n\n\nquicksort(cards, 0, n-1)\n", "def quicksort:\n \n\ndef isstable(A, n):\n \n\ncards=[]\n\n\nquicksort(cards, 0, n-1)\n\nfor i in range(n):\n", "def quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\n\nquicksort(cards, 0, n-1)\n\nfor i in range(n):\n", "def partition:\n \n\ndef quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\n\nquicksort(cards, 0, n-1)\n\nfor i in range(n):\n", "def partition:\n \n\ndef quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\n\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n \ndef partition:\n \n\ndef quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\n\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n \ndef partition:\n \n\ndef quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n \ndef partition:\n \n \ndef quicksort:\n \n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n \ndef partition:\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition:\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n \n \ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \n A[r] = temp\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n \n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \n A[r] = temp\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n \nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \n A[r] = temp\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n \n \n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n \n \n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n \n \n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in :\n \n \n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n \nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in :\n \n \n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n for i in :\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in range(p, r):\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n for i in :\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in range(p, r):\n if A[j].value <= piv:\n i += 1\n temp = A[j]\n A[j] = A[i]\n A[i] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n for i in :\n \n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in range(p, r):\n if A[j].value <= piv:\n i += 1\n temp = A[j]\n A[j] = A[i]\n A[i] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n for i in :\n if A[i].value == A[i+1].value and A[i].no > A[i+1].no:\n print(\"Not stable\")\n return\n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n", "class card:\n def __init__(self, suit, value, no):\n self.suit = suit\n self.value = value\n self.no = no\ndef partition(A, p, r):\n piv = A[r].value\n i = p - 1\n for j in range(p, r):\n if A[j].value <= piv:\n i += 1\n temp = A[j]\n A[j] = A[i]\n A[i] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q, r)\n\ndef isstable(A, n):\n for i in range(n-1):\n if A[i].value == A[i+1].value and A[i].no > A[i+1].no:\n print(\"Not stable\")\n return\n print(\"Stable\")\n\n\nn = int(input())\ncards=[]\n\nfor i in range(n):\n temp = list(input().split())\n ob = card(temp[0], int(temp[1]), i)\n cards.append(ob)\nquicksort(cards, 0, n-1)\nisstable(cards, n)\nfor i in range(n):\n print(cards[i].suit + \" \" + str(cards[i].value))\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "quicksort(Card1, 0, n-1)\n", "import copy\n\n\nquicksort(Card1, 0, n-1)\n", "import copy\n\n\nCard1 = []\n\n\nquicksort(Card1, 0, n-1)\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\nquicksort(Card1, 0, n-1)\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\nquicksort(Card1, 0, n-1)\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(Card1, 0, n-1)\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(Card1, 0, n-1)\n\n\nif :\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\n\nif :\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\n\nif :\n \n\nfor i in range(n):\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\n\nif :\n \n\nfor i in range(n):\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \n\nfor i in range(n):\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \n\nfor i in range(n):\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \n\nfor i in range(n):\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n \nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergesort(A, left, right):\n \n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n \n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort:\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n \n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n \n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n \n global i\n i = p-1\n \n \n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n \n \n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n \n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n \n \n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in :\n \n \n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in :\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in :\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in :\n \n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in :\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in :\n \n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n \n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n \n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \n l2 = float(l1[1])\n \n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n \n \n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n \n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n \ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n else:\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if :\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n i += 1\n else:\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if int(c2) <= int(x2):\n \n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n i += 1\n else:\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if int(c2) <= int(x2):\n i += 1\n y = B[i]\n z = B[j]\n B[i] = z\n B[j] = y\n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n i += 1\n else:\n \n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if int(c2) <= int(x2):\n i += 1\n y = B[i]\n z = B[j]\n B[i] = z\n B[j] = y\n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n \n i += 1\n else:\n \n j += 1\n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if int(c2) <= int(x2):\n i += 1\n y = B[i]\n z = B[j]\n B[i] = z\n B[j] = y\n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n A[k] = L[i]\n i += 1\n else:\n \n j += 1\n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n", "import copy\n\nn = int(input())\n\nCard1 = []\n\nfor i in range(n):\n Card1.append(input())\n\ndef partition(B, p, r):\n x1, x2 = B[r].split()\n global i\n i = p-1\n for j in range(p, r):\n c1, c2 = B[j].split()\n if int(c2) <= int(x2):\n i += 1\n y = B[i]\n z = B[j]\n B[i] = z\n B[j] = y\n a = B[i+1]\n b = B[r]\n B[i+1] = b\n B[r] = a\n return i+1\n\ndef quicksort(B, p, r):\n if p < r:\n q = partition(B, p, r)\n quicksort(B, p, q-1)\n quicksort(B, q+1, r)\n\ndef merge(A, left, mid, right):\n inf = float('inf')\n L = A[left:mid] + [\"D inf\"]\n R = A[mid:right] + [\"D inf\"]\n i = 0\n j = 0\n for k in range(left, right):\n l1 = L[i].split()\n r1 = R[j].split()\n l2 = float(l1[1])\n r2 = float(r1[1])\n if l2 <= r2:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef mergesort(A, left, right):\n if left+1 < right:\n mid = (left + right)//2\n mergesort(A, left, mid)\n mergesort(A, mid, right)\n merge(A, left, mid, right)\n\nCard2 = copy.deepcopy(Card1)\n\nquicksort(Card1, 0, n-1)\n\nmergesort(Card2, 0, n)\n\nif Card1 == Card2:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(Card1[i])\n" ]
55
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n", "n=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n", "import sys\n\n\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n", "import sys\n\n\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n\nprint(s(A)+'table')\n", "import sys\n\n\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\n", "import sys\n\n\ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\n", "import sys\n\n\ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint('\\n'.join(f'{a} {b}'for a,b,_ in A))\n" ]
23
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def swap:\n", "def merge:\n \n\ndef swap:\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef quicksort:\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef quicksort:\n \n\nfor _ in range(n):\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef quicksort:\n \n\nfor _ in range(n):\n \n\nfor a,b in zip(A,B):\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nfor a,b in zip(A,B):\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nquicksort(B, 0, len(B) - 1)\n\n\nfor a,b in zip(A,B):\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nquicksort(B, 0, len(B) - 1)\n\n\nfor a,b in zip(A,B):\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nquicksort(B, 0, len(B) - 1)\n\n\nfor a,b in zip(A,B):\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\nB = list()\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\nB = list()\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort:\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition:\n \n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition(S, p, r):\n \n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap:\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n \n\ndef merge:\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge:\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n \n\nif flag:\n \nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge:\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n \nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n \nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n i = 0\n j = 0\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n \nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n i = 0\n j = 0\n \n\ndef swap(A, i, j):\n \n \ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n i = 0\n j = 0\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n \nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n \n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n \n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n \n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n \n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n \n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n \n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n \n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n \n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n \n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n \n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__:\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n \n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n \n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in :\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n \n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in :\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n\n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in range(l,r):\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n \n \n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in range(l,r):\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n self.suit = suit\n \n\n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in range(l,r):\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "class Card():\n def __init__(self, suit, value):\n self.suit = suit\n self.value = int(value)\n\n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in range(l,r):\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n", "\nclass Card():\n def __init__(self, suit, value):\n self.suit = suit\n self.value = int(value)\n\n def __str__(self):\n return \" \".join([self.suit, str(self.value)])\n\n\n\nMAXINT = 1000000000 + 1\ndef mergesort(X, l, r):\n if l + 1 < r:\n m = (l + r)//2\n mergesort(X,l,m)\n mergesort(X,m ,r)\n merge(X,l, m, r)\n\ndef merge(X, l, m, r):\n nl = m - l\n nr = r - m\n L = [X[i] for i in range(l, l + nl)]\n R = [X[i] for i in range(m, m + nr)]\n L.append(Card('', MAXINT))\n R.append(Card('', MAXINT))\n i = 0\n j = 0\n for k in range(l,r):\n if L[i].value <= R[j].value:\n X[k] = L[i]\n i += 1\n else:\n X[k] = R[j]\n j += 1\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(S, p, r):\n x = S[r]\n i = p -1\n for j in range(p,r):\n if S[j].value <= x.value:\n i += 1\n swap(S, i, j)\n swap(S, i+1, r)\n return i+1\n\ndef quicksort(S, p, r):\n if p < r:\n q = partition(S, p, r)\n quicksort(S, p, q-1)\n quicksort(S, q+1, r)\n\nn = int(input())\nA = list()\nB = list()\nfor _ in range(n):\n s, v = input().split()\n A.append(Card(s, v))\n B.append(Card(s, v))\n\nmergesort(A, 0, len(A))\nquicksort(B, 0, len(B) - 1)\n\nflag = True\nfor a,b in zip(A,B):\n if a.suit != b.suit:\n flag = False\n break\n\nif flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x in B:\n print(x)\n" ]
61
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def s(A):\n", "import sys\n\n\ndef s(A):\n", "import sys\n\n\ndef s(A):\n \n\nk(A,0,n-1)\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \n\nk(A,0,n-1)\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \n\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n" ]
24
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "a = []\n", "n = int(input())\na = []\n", "import copy\n\n\nn = int(input())\na = []\n", "import copy\n\n\nn = int(input())\na = []\nfor i in range(n):\n", "import copy\n\n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n", "import copy\n\n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \n\nquick_sort(a, 0, n - 1)\n", "import copy\n\n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n", "import copy\n\n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n", "import copy\n\n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quick_sort(a, p, r):\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n \nelse:\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n \n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n \n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n \n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n \nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n \n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n \n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in range(p, r):\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x[1]:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in a:\n print(\" \".join(map(str, i)))\n", "import copy\ndef partition(a, p, r):\n x = a[r]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x[1]:\n i = i + 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return(i + 1)\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n\nn = int(input())\na = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\n\nquick_sort(a, 0, n - 1)\n\nfor i in range(n - 1):\n if a[i][1] == a[i + 1][1]:\n if b.index(a[i]) > b.index(a[i + 1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor i in a:\n print(\" \".join(map(str, i)))\n" ]
30
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "if :\n main()\n", "def partition:\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition:\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition:\n \n\ndef quick_sort:\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef main():\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition:\n \n \ndef quick_sort:\n \n\ndef main():\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition:\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "from import deque, \n\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "from import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "from import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n\nif :\n main()\n", "from import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n\nif __name__ == \"__main__\":\n main()\n", "from import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n \n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n \n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n if stable:\n \n\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n if stable:\n \n\n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n if stable:\n print(\"Stable\")\n\n \n for a in A:\n \n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n if stable:\n print(\"Stable\")\n\n \n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n\n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in :\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n \n A.append(inp)\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n \n \n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n \n\n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n \n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n if :\n \n\n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n d[int(inp[1:])].append(inp[0])\n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n if :\n \n\n if stable:\n print(\"Stable\")\n\n else:\n \n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n d[int(inp[1:])].append(inp[0])\n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n if :\n \n\n if stable:\n print(\"Stable\")\n\n else:\n print(\"Not stable\")\n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n d[int(inp[1:])].append(inp[0])\n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n if a[0] != tmp:\n \n\n if stable:\n print(\"Stable\")\n\n else:\n print(\"Not stable\")\n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n", "from collections import deque, defaultdict\n\n\ndef partition(A, p, r):\n x = int(A[r][1:])\n i = p - 1\n for j in range(p, r):\n if x >= int(A[j][1:]):\n i += 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n\n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\n\ndef main():\n n = int(input())\n A = []\n d = defaultdict(deque)\n stable = True\n for i in range(n):\n inp = input().replace(\" \", \"\")\n A.append(inp)\n d[int(inp[1:])].append(inp[0])\n quick_sort(A, 0, n-1)\n\n # stableかどうかを確認\n for a in A:\n tmp = d[int(a[1:])].popleft()\n if a[0] != tmp:\n stable = False\n\n if stable:\n print(\"Stable\")\n\n else:\n print(\"Not stable\")\n\n for a in A:\n print(a[0], a[1:])\n\n\nif __name__ == \"__main__\":\n main()\n" ]
42
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "a = []\n", "r = int(input())\na = []\n", "def check:\n \n\nr = int(input())\na = []\n", "def quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\n", "def quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n \n\nfor s,r,d in a:\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n \nquickSort(a, 0, r-1)\n\nfor s,r,d in a:\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check:\n \n\nr = int(input())\na = []\nfor i in range(r):\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition:\n \n\ndef quickSort:\n \n\ndef check(A, s, e):\n \n\nr = int(input())\na = []\nfor i in range(r):\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n\nr = int(input())\na = []\nfor i in range(r):\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n\nr = int(input())\na = []\nfor i in range(r):\n \n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n\nr = int(input())\na = []\nfor i in range(r):\n \n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n \nr = int(input())\na = []\nfor i in range(r):\n \n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n \nr = int(input())\na = []\nfor i in range(r):\n \n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n \nr = int(input())\na = []\nfor i in range(r):\n \n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n \nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n \nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n \n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in :\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef check(A, s, e):\n for i in range(s,e-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nr = int(input())\na = []\nfor i in range(r):\n c = input().split()\n a.append((c[0],int(c[1]),i))\nquickSort(a, 0, r-1)\nprint(check(a,0,r))\nfor s,r,d in a:\n print(\"{} {}\".format(s,r))\n" ]
30
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = [f(readline().split(), i) for i in range(n)]\n", "A = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\n", "A = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\n\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\n\n\ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\n\n\ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \n\ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition:\n \n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n \n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n \nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n \n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in :\n if A[i][1] == A[i + 1][1]:\n if A[i][2] > A[i + 1][2]:\n return False\n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n if A[i][1] == A[i + 1][1]:\n if A[i][2] > A[i + 1][2]:\n return False\n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n if A[i][1] == A[i + 1][1]:\n if A[i][2] > A[i + 1][2]:\n return False\n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\nreadline = sys.stdin.readline\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\ndef isStable(A):\n for i in range(0, len(A) - 1):\n if A[i][1] == A[i + 1][1]:\n if A[i][2] > A[i + 1][2]:\n return False\n return True\nn = int(input())\nf = lambda a, i: (a[0], int(a[1]), i)\nA = [f(readline().split(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nprint(\"Stable\" if isStable(A) else \"Not stable\")\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n" ]
28
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "sentinel = str(10**9+1)\n", "sentinel = str(10**9+1)\n\n\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\nquick_sort(n_lst,0,n-1)\n\n\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\n\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\n\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\n\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\n\n\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\n\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge(lst,left,middle,right):\n \n\ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort:\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort(lst,left,right):\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort(lst,left,right):\n \n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n \n \ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n \n right_lst = lst[middle:right] + [['',sentinel]]\n\n \ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n \n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n \n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n \n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n i,j = 0,0\n for k in :\n \n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n i,j = 0,0\n for k in :\n if int(left_lst[i][1]) <= int(right_lst[j][1]):\n lst[k] = left_lst[i]\n i += 1\n else:\n lst[k] = right_lst[j]\n j += 1\n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n \n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n i,j = 0,0\n for k in range(left,right):\n if int(left_lst[i][1]) <= int(right_lst[j][1]):\n lst[k] = left_lst[i]\n i += 1\n else:\n lst[k] = right_lst[j]\n j += 1\n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in :\n if int(A[j][1]) <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n i,j = 0,0\n for k in range(left,right):\n if int(left_lst[i][1]) <= int(right_lst[j][1]):\n lst[k] = left_lst[i]\n i += 1\n else:\n lst[k] = right_lst[j]\n j += 1\n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n", "sentinel = str(10**9+1)\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i = i + 1\n A[i], A[j] = A[j], A[i]\n\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(lst,left,middle,right):\n left_lst = lst[left:middle] + [['',sentinel]]\n right_lst = lst[middle:right] + [['',sentinel]]\n\n i,j = 0,0\n for k in range(left,right):\n if int(left_lst[i][1]) <= int(right_lst[j][1]):\n lst[k] = left_lst[i]\n i += 1\n else:\n lst[k] = right_lst[j]\n j += 1\n\ndef merge_sort(lst,left,right):\n if left+1 < right:\n middle = (left+right)//2\n merge_sort(lst,left,middle)\n merge_sort(lst,middle,right)\n merge(lst,left,middle,right)\n\n\nn = int(input())\nn_lst = [[i for i in input().split()] for _ in range(n)]\nm_lst = list(n_lst)\nquick_sort(n_lst,0,n-1)\nmerge_sort(m_lst,0,n)\nprint('Stable' if n_lst == m_lst else 'Not stable')\nfor ans in n_lst:\n print('{} {}'.format(ans[0],ans[1]))\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "# Quick Sort #\n\n\na = []\n\nb = a[:]\n", "# Quick Sort #\n\n\ndef is_stable:\n \n\na = []\n\nb = a[:]\n", "# Quick Sort #\n\n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\n", "# Quick Sort #\n\n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\n\n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\n\n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\nquick_sort(b, 0, n-1)\n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\nquick_sort(b, 0, n-1)\n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\nquick_sort(b, 0, n-1)\n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\n\nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \n\nfor i in b:\n", "# Quick Sort #\ndef partition:\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \n\nfor i in b:\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \n\nfor i in b:\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \nelse:\n \nfor i in b:\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n \n\ndef is_stable:\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \nelse:\n \nfor i in b:\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable:\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \nelse:\n \nfor i in b:\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable:\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n \nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable:\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort(A, p, r):\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable:\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n\ndef quick_sort(A, p, r):\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n \n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif :\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n \nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n \n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n \n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n for k in :\n \n \n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n \n i = p-1\n for k in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n \n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n if A[k][1] <= x:\n i += 1\n A[i], A[k] = A[k], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n \n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n if A[k][1] <= x:\n i += 1\n A[i], A[k] = A[k], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n for k in range(n-1, i, -1):\n if x[k][1] < x[k-1][1]:\n x[k], x[k-1] = x[k-1], x[k]\n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n \n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n if A[k][1] <= x:\n i += 1\n A[i], A[k] = A[k], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n for k in range(n-1, i, -1):\n if x[k][1] < x[k-1][1]:\n x[k], x[k-1] = x[k-1], x[k]\n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n \n else:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n if A[k][1] <= x:\n i += 1\n A[i], A[k] = A[k], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n for k in range(n-1, i, -1):\n if x[k][1] < x[k-1][1]:\n x[k], x[k-1] = x[k-1], x[k]\n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n print(\"Stable\")\n else:\n \nfor i in b:\n print(*i)\n", "# Quick Sort #\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for k in range(p, r):\n if A[k][1] <= x:\n i += 1\n A[i], A[k] = A[k], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef bubble_sort(c, n):\n x = c[:]\n for i in range(n):\n for k in range(n-1, i, -1):\n if x[k][1] < x[k-1][1]:\n x[k], x[k-1] = x[k-1], x[k]\n return x\n\ndef is_stable(_in, out):\n n = len(_in)\n for i in range(n):\n for k in range(i+1, n):\n for a in range(n):\n for b in range(a+1, n):\n if _in[i][1] == _in[k][1] and _in[i] == out[b] and _in[k] == out[a]:\n return False\n return True\n\nn = int(input())\na = []\nfor i in range(n):\n mrk, num = input().split()\n num = int(num)\n a.append((mrk, num))\nb = a[:]\nquick_sort(b, 0, n-1)\nif n > 10000:\n print(\"Not stable\")\nelse:\n c = bubble_sort(a[:], n)\n if b == c:\n print(\"Stable\")\n else:\n print(\"Not stable\")\nfor i in b:\n print(*i)\n" ]
44
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\ndef partition:\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\ndef swap:\n \n\ndef partition:\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\ndef swap:\n \n\ndef partition:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\n\nfrom math import inf\n\n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n\ndef partition(A, p, r):\n \n\ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n\ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n\ndef main():\n \n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort:\n \n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort:\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge:\n ; \n ; \n ; \n ; \n \n\ndef merge_sort(A, left, right):\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; \n ; \n ; \n ; \n \n\ndef merge_sort(A, left, right):\n \n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; \n ; \n ; \n ; \n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; \n ; \n ; \n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; \n ; \n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; \n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; \n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n \ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n \n \nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n \n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n \n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n \n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n \n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n \n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n ; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n ; l = next(i)\n ; r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n ; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n ; r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n ; r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n ; r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n ; r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n if l[1] <= r[1]:\n A[k] = l\n l = next(i)\n else:\n A[k] = r\n r = next(j)\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n if l[1] <= r[1]:\n A[k] = l\n l = next(i)\n else:\n A[k] = r\n r = next(j)\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n swap(A, i, j)\n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n \n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n if l[1] <= r[1]:\n A[k] = l\n l = next(i)\n else:\n A[k] = r\n r = next(j)\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n swap(A, i, j)\n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n \n A.append((suit, int(num)))\n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n", "#! /usr/local/bin/python3\n# coding: utf-8\n\nfrom sys import stdin\nfrom math import inf\n\ndef merge(A, left, mid, right):\n L = A[left:mid]; L.append((\"\", inf))\n R = A[mid:right]; R.append((\"\", inf))\n i = iter(L); l = next(i)\n j = iter(R); r = next(j)\n for k in range(left, right):\n if l[1] <= r[1]:\n A[k] = l\n l = next(i)\n else:\n A[k] = r\n r = next(j)\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\ndef swap(A, i, j):\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n swap(A, i, j)\n swap(A, i + 1, r)\n return i + 1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n\ndef main():\n n = int(stdin.readline())\n A = []\n for l in stdin:\n suit, num = l.split()\n A.append((suit, int(num)))\n B = A[:]\n quick_sort(A, 0, n - 1)\n merge_sort(B, 0, n)\n print(\"Stable\" if A == B else \"Not stable\")\n [print(*a) for a in A]\n\nmain()\n" ]
51
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\n", "A = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\n\n\nprint(\"Not stable\" if notstable else \"Stable\")\n", "n = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\n\n\nprint(\"Not stable\" if notstable else \"Stable\")\n", "n = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\n\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\n", "n = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\n\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n", "n = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n", "def quicksort:\n \n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n \n i = p-1\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n \n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n \n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i],A[j] = A[j],A[i]\n A[i+1],A[r] = A[r],A[i+1]\n return i+1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\nA = [(t[0], int(t[1]), i) for t, i in [(input().split(), i) for i in range(n)]]\nquicksort(A, 0, n-1)\nnotstable = any([True for i in range(1, n) if A[i][1] == A[i-1][1] and A[i][2] < A[i-1][2]])\nprint(\"Not stable\" if notstable else \"Stable\")\nfor v in A:\n print(f\"{v[0]} {v[1]}\")\n" ]
20
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "B = copy.deepcopy(A)\n", "def mergeSort:\n \n\nB = copy.deepcopy(A)\n", "def mergeSort:\n \n\nB = copy.deepcopy(A)\n\n\nans = '\\n'.join(ans)\n", "def mergeSort:\n \n\nB = copy.deepcopy(A)\n\n\nif A == B:\n \n\nans = '\\n'.join(ans)\n", "def mergeSort:\n \ndef partition(a,p,r):\n \n\nB = copy.deepcopy(A)\n\n\nif A == B:\n \n\nans = '\\n'.join(ans)\n", "def mergeSort:\n \ndef partition(a,p,r):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = '\\n'.join(ans)\n", "def mergeSort:\n \ndef partition(a,p,r):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "def mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\n", "import copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\n\n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\n\ndef merge:\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \n\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n \nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort:\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n \nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort:\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n \n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n \n \n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n \n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n \n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n \nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n \n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if :\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in :\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n \n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n \n countR = mergeSort(A, mid, right)\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n \n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n \n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n \n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if :\n \n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n \n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n \n i = i + 1\n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n \n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n \n j = j + 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n", "import copy\n\nINF = 10000000000\ndef merge(A, left, mid, right):\n count = 0\n L = A[left:mid] + [(INF,INF)]\n R = A[mid:right] + [(INF,INF)]\n\n i, j = 0, 0\n for k in range(left, right):\n count = count + 1\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n return count\n\ndef mergeSort(A, left, right):\n if left + 1 < right:\n mid = (left + right) // 2\n countL = mergeSort(A, left, mid)\n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\ndef partition(a,p,r):\n x=a[r][1]\n i=p-1\n for j in range(p,r):\n if a[j][1]<=x:\n i+=1\n a[i],a[j]=a[j],a[i]\n a[i+1],a[r]=a[r],a[i+1]\n return i+1\ndef quickSort(a,p,r):\n if p<r:\n q=partition(a,p,r)\n quickSort(a,p,q-1)\n quickSort(a,q+1,r)\nn = int(input())\nA = [None for i in range(n)]\nfor i in range(n):\n a, b = input().split()\n A[i] = (a, int(b))\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\nmergeSort(B, 0, n)\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nans = [str(x[0]) +\" \"+str(x[1]) for x in A]\nans = '\\n'.join(ans)\nprint(ans)\n" ]
60
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "deck = [None]*n\n\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "n = int(input())\ndeck = [None]*n\n\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def quicksort:\n \n\nn = int(input())\ndeck = [None]*n\n\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def quicksort:\n \n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\n\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def quicksort:\n \n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n\ndef quicksort:\n \n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n\ndef quicksort:\n \n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n\ndef quicksort:\n \n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n \n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition:\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n print(\"Stable\")\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif :\n print(\"Stable\")\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\n\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n \n \nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n \nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n \ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n for j in :\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n \n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in :\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in :\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n \n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in :\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n \n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n \n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in :\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in :\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n \n\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in range(n-1):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in :\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in range(n-1):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in range(n-1):\n \n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n", "def partition(a, p, r):\n x = a[r][1]\n i = p-1\n\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n\n a[i+1], a[r] = a[r], a[i+1]\n return i+1\n\n\ndef quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q-1)\n quicksort(a, q+1, r)\n\n\ndef isstable(a):\n for i in range(n-1):\n if a[i][1] == a[i+1][1]:\n if a[i][2] > a[i+1][2]:\n return False\n return True\n\n\nn = int(input())\ndeck = [None]*n\nfor num in range(n):\n card = input().split()\n deck[num] = [card[0], int(card[1]), num]\n\nquicksort(deck, 0, n-1)\nif isstable(deck):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n[print(deck[i][0], deck[i][1]) for i in range(n)]\n" ]
32
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "cards = [input() for i in range(n)]\n", "n = int(input())\ncards = [input() for i in range(n)]\n", "def num_from_card(card):\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n", "def num_from_card(card):\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n", "def num_from_card(card):\n \n\ndef merge:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n", "def num_from_card(card):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n", "def num_from_card(card):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n\n\nfor c in cards:\n print(c)\n", "def num_from_card(card):\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n\n\nfor c in cards:\n print(c)\n", "def num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n\n\nfor c in cards:\n print(c)\n", "def num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "def num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\n\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "def num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n i = p-1\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif :\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition:\n \n i = p-1\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n \n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge:\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort:\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\n\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\n\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n \n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n \n \n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n \n \n R.append(' ' + str(int(10e9 + 1)))\n \n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n \n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n \n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n \n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n i, j = 0, 0\n for k in range(left, right):\n \n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n i, j = 0, 0\n for k in range(left, right):\n if num_from_card(L[i]) <= num_from_card(R[j]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n i, j = 0, 0\n for k in range(left, right):\n if num_from_card(L[i]) <= num_from_card(R[j]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n", "import copy\n\ndef num_from_card(card):\n return int(card[2:])\n\ndef partition(A, p, r):\n x = num_from_card(A[r])\n i = p-1\n for j in range(p, r):\n if num_from_card(A[j]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L = A[left: mid]\n R = A[mid: right]\n L.append(' ' + str(int(10e9 + 1)))\n R.append(' ' + str(int(10e9 + 1)))\n i, j = 0, 0\n for k in range(left, right):\n if num_from_card(L[i]) <= num_from_card(R[j]):\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef merge_sort(A, left, right):\n if left + 1 < right:\n mid = int((left + right)/2)\n merge_sort(A, left, mid)\n merge_sort(A, mid, right)\n merge(A, left, mid, right)\n\nn = int(input())\ncards = [input() for i in range(n)]\nmerge_cards = copy.copy(cards)\n\nquick_sort(cards, 0, n-1)\nmerge_sort(merge_cards, 0, n)\n\nif merge_cards == cards:\n print('Stable')\nelse:\n print('Not stable')\n\nfor c in cards:\n print(c)\n" ]
41
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "data1 = copy.deepcopy(data)\n", "for _ in range(n):\n \ndata1 = copy.deepcopy(data)\n", "n = int(input())\n\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n", "n = int(input())\n\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n", "n = int(input())\n\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n", "n = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n", "n = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \n\nfor d in data:\n", "def quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \n\nfor d in data:\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n \nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort:\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in :\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n \n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition:\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n \ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n \n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n mark, num = map(str, input().split())\n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n mark, num = map(str, input().split())\n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n mark, num = map(str, input().split())\n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n", "import copy\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x[1]:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nn = int(input())\ndata = []\nfor _ in range(n):\n mark, num = map(str, input().split())\n data.append([mark, int(num)])\ndata1 = copy.deepcopy(data)\n\nquicksort(data, 0, n-1)\n\nfor i in range(n-1):\n if data[i][1] == data[i+1][1]:\n if data1.index(data[i]) > data1.index(data[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor d in data:\n print(' '.join(str(dd) for dd in d))\n" ]
28
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "l_1 = []\n", "l_1 = []\nfor _ in range(n):\n", "l_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n", "n = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n", "import copy\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n", "import copy\n\n\ndef quickSort:\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n", "import copy\n\n\ndef quickSort:\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n", "import copy\n\n\ndef quickSort:\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\n\nshow(l_1)\n", "import copy\n\n\ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in :\n \n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n i = p-1\n \n \ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n i = p-1\n \n \ndef quickSort:\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition:\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef show(l):\n \n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n \nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n \n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n \n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n print('Stable')\n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n a = input().split()\n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n print('Stable')\n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n a = input().split()\n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n print('Stable')\n\nshow(l_1)\n", "import copy\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p-1\n for j in range(p, r):\n if int(A[j][1]) <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef show(l):\n for i in range(len(l)):\n print(l[i][0], l[i][1], sep = ' ')\n\n\nn = int(input())\nl_1 = []\nfor _ in range(n):\n a = input().split()\n l_1.append(a)\nl_2 = copy.deepcopy(l_1)\n\nquickSort(l_1, 0, n-1)\n\nfor i in range(n-1):\n if int(l_1[i][1]) == int(l_1[i+1][1]):\n if l_2.index(l_1[i]) > l_2.index(l_1[i+1]):\n print('Not stable')\n break\nelse:\n print('Stable')\n\nshow(l_1)\n" ]
30
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "n=int(input())\n", "n=int(input())\n\n\nfor e in:\n", "import sys\n\n\nn=int(input())\n\n\nfor e in:\n", "import sys\n\n\ndef s(A):\n \nn=int(input())\n\n\nfor e in:\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\n\n\nfor e in:\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\n\nfor e in:\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n" ]
25
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\n\n#print(*A)\n#print(*B)\n", "def mergeSort:\n \n\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\n\n#print(*A)\n#print(*B)\n", "def mergeSort:\n \n\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def merge:\n \n\ndef mergeSort:\n \n\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\n\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\n\nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\n\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\n\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\n\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\n\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\n\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\n\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort(A, p, r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\n\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n", "def partition:\n \n\ndef quickSort(A, p, r):\n \n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\n\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\n\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition:\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition:\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge:\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n \nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n \nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n \nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n \nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n \nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n mid=0\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n \nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n \ndef mergeSort(A, left, right):\n mid=0\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n \n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n \n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n \n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if :\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n \n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in :\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in range(left,right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in range(left,right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \n mergeSort(A, left, mid)\n \n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in range(left,right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n \n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in range(left,right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n mid = int((left + right)/2)\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n \nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n", "def partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x:\n i = i+1\n A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\ndef merge(A, left, mid, right):\n L=A[left:mid]+[[\"X\",10000000000]]\n R=A[mid:right]+[[\"X\",10000000000]]\n i = 0\n j = 0\n\n for k in range(left,right):\n if L[i][1] <= R[j][1]:\n A[k] = L[i]\n i = i + 1\n else:\n A[k] = R[j]\n j = j + 1\n\ndef mergeSort(A, left, right):\n mid=0\n if left+1 < right:\n mid = int((left + right)/2)\n mergeSort(A, left, mid)\n mergeSort(A, mid, right)\n merge(A, left, mid, right)\nimport copy\nn=int(input())\nA=[]\nfor i in range(n):\n Astr=input().split( )\n A.append([Astr[0],int(Astr[1])])\n\nB=A.copy()\n#print(id(A)) # ID: 4315448960\n#print(id(B)) # ID: 4315448960\n\nquickSort(A,0,n-1)\n\nmergeSort(B,0,n)\n#print(*B)\nflag=0\nfor i in range(n):\n if A[i]!=B[i]:\n flag=1\n break\n else:\n pass\nif flag==1:\n print(\"Not stable\")\nelse:\n print(\"Stable\")\n\n#print(*A)\n#print(*B)\nfor i in range(n):\n print(*A[i])\n" ]
49
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\n\nl = []\n\n\n# print(l1)\n\n\n# print(l2_sorted)\n", "#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\n# print(l1)\n\n\n# print(l2_sorted)\n", "#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\n\n# print(l2_sorted)\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\n\n# print(l2_sorted)\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\n\n# print(l2_sorted)\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\n\n# print(l2_sorted)\n\n\nfor x, y in l1:\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\n\nfor x, y in l1:\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\n\nfor x, y in l1:\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\n\nfor x, y in l1:\n", "def quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n \n\nfor x, y in l1:\n", "def partition:\n \n\ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n \n\nfor x, y in l1:\n", "def partition:\n \n\ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition:\n \n\ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n \nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n \nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n\ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \ndef quick_sort:\n \n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n \nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n \n \nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n \n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n i = p - 1\n \n \n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n i = p - 1\n \n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n \n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n \n i = p - 1\n \n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n \n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n l.append((a, int(b)))\n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n l.append((a, int(b)))\n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n l.append((a, int(b)))\n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n", "def partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p, r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[r], a[i + 1] = a[i + 1], a[r]\n return i + 1\n\n\ndef quick_sort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\n#\n# l = [int(i) for i in input().split()]\n# quick_sort(l, 0, len(l) - 1)\n# print(l)\n\nn = int(input())\nl = []\n\nfor i in range(n):\n a, b = input().split()\n l.append((a, int(b)))\n\nl1 = l.copy()\nquick_sort(l1, 0, len(l) - 1)\n# print(l1)\n\nl2 = l.copy()\nl2_sorted = sorted(l2, key=lambda x: x[1])\n# print(l2_sorted)\n\nif l1 == l2_sorted:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor x, y in l1:\n print(x, y)\n" ]
31
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "M = []\n", "M = []\n\n\nfor m in M:\n", "M = []\nfor _ in range(n):\n \n\nfor m in M:\n", "M = []\nfor _ in range(n):\n \n\ndef group(arr):\n \n\nfor m in M:\n", "M = []\nfor _ in range(n):\n \n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nfor m in M:\n", "import copy\n\n\nM = []\nfor _ in range(n):\n \n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nquick_sort(0, n - 1)\n\n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nquick_sort(0, n - 1)\n\n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\nquick_sort(0, n - 1)\n\nif :\n \n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nquick_sort(0, n - 1)\n\nif :\n \n\nfor m in M:\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\nquick_sort(0, n - 1)\n\nif :\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n \n\nquick_sort(0, n - 1)\n\nif :\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n \n\nquick_sort(0, n - 1)\n\nif :\n \nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif :\n \nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n \n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n \nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n \nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n \n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n \n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n \n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n \n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n \n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n \n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n \n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n \n i = p - 1\n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n \n i = p - 1\n for k in :\n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n \n\n return r\n\n\ndef partition(p, r):\n x = M[r][1]\n i = p - 1\n for k in :\n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n if r.get(a[1]):\n r[a[1]] += a[0]\n else:\n r[a[1]] = a[0]\n\n return r\n\n\ndef partition(p, r):\n x = M[r][1]\n i = p - 1\n for k in :\n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n if r.get(a[1]):\n r[a[1]] += a[0]\n else:\n r[a[1]] = a[0]\n\n return r\n\n\ndef partition(p, r):\n x = M[r][1]\n i = p - 1\n for k in range(p, r):\n \n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n", "import copy\n\n\nn = int(input())\nM = []\nfor _ in range(n):\n m = input().split()\n M.append([m[0], int(m[1])])\n\n_M = copy.deepcopy(M)\n\n\ndef group(arr):\n r = {}\n for a in arr:\n if r.get(a[1]):\n r[a[1]] += a[0]\n else:\n r[a[1]] = a[0]\n\n return r\n\n\ndef partition(p, r):\n x = M[r][1]\n i = p - 1\n for k in range(p, r):\n if M[k][1] <= x:\n i += 1\n M[i], M[k] = M[k], M[i]\n M[i + 1], M[r] = M[r], M[i + 1]\n return i + 1\n\n\ndef quick_sort(p, r):\n if p < r:\n q = partition(p, r)\n quick_sort(p, q - 1)\n quick_sort(q + 1, r)\n\n\nquick_sort(0, n - 1)\n\nif group(_M) == group(M):\n print('Stable')\nelse:\n print('Not stable')\n\nfor m in M:\n print(m[0], m[1])\n" ]
33
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n #S H C D\n", "A = []\n #S H C D\n\n\nfor a in A:\n", "A = []\n #S H C D\n\n\nfor a,v in copya:\n \n\nfor a in A:\n", "def Quicksort:\n \n\nA = []\n #S H C D\n\n\nfor a,v in copya:\n \n\nfor a in A:\n", "def Quicksort:\n \n\nA = []\n #S H C D\nfor i in range(n):\n \n\nfor a,v in copya:\n \n\nfor a in A:\n", "def Quicksort:\n \n\nA = []\n #S H C D\nfor i in range(n):\n \n\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Quicksort:\n \n\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Quicksort:\n \n\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nfor a,v in A:\n \n\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nfor a,v in A:\n \n\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n\ndef Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n\ndef Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \ncopya = A[:]\n\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n\ndef Quicksort:\n \nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n\ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n \n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n print('Stable')\n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif :\n print('Stable')\n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif (Avdic == cvdic):\n print('Stable')\n\nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort:\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n \ncvdic = dict()\nfor a,v in copya:\n \nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n \nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n v = int(v)\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n v = int(v)\n \ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n \n i = p-1\n \n \n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n \n \n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n \n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n \n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n \n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n a,v = input().split()\n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n for j in :\n \n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n a,v = input().split()\n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n for j in :\n if (A[j][1] <= x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n a,v = input().split()\n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def Partition(A,p,r): ## r = n-1 (A의 p~r번째(0 base)요소를 partition!)\n x = A[r][1]\n i = p-1\n for j in range(p,r):\n if (A[j][1] <= x):\n i += 1\n A[i], A[j] = A[j], A[i]\n A[r], A[i+1] = A[i+1], A[r]\n return i+1\n\ndef Quicksort(A, p, r):\n if (p < r):\n q = Partition(A,p,r)\n Quicksort(A,p,q-1)\n Quicksort(A,q+1,r)\nn = int(input())\nA = []\ncolor = [[]for i in range(4)] #S H C D\nfor i in range(n):\n a,v = input().split()\n v = int(v)\n A.append((a,v))\ncopya = A[:]\nQuicksort(A, 0, n-1)\nAvdic = dict()\nfor a,v in A:\n if (v not in Avdic.keys()):\n Avdic[v] = [a]\n else:\n Avdic[v] += [a]\ncvdic = dict()\nfor a,v in copya:\n if (v not in cvdic.keys()):\n cvdic[v] = [a]\n else:\n cvdic[v] += [a]\nif (Avdic == cvdic):\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n" ]
35
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def partition:\n", "def partition:\n \n\nn, *D = open(0).read().split()\n", "def partition:\n \n\nn, *D = open(0).read().split()\n\n\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\nn, *D = open(0).read().split()\n\n\nstable = True\n\n\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\nn, *D = open(0).read().split()\n\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\n\nstable = True\n\n\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\nn, *D = open(0).read().split()\n\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\n\nstable = True\n\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\n\nstable = True\n\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\ndef quicksort:\n \n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\n\nstable = True\n\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\ndef quicksort:\n \n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\n\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\ndef quicksort:\n \n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n \nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\n", "def partition:\n \n\ndef quicksort:\n \n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n \nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n \nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition:\n \n\ndef quicksort:\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition:\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in :\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n \n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n", "def partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q - 1)\n quicksort(A, q + 1, r)\n\n\nn, *D = open(0).read().split()\nn = int(n)\nA = [(D[2 * i], int(D[2 * i + 1]), i) for i in range(n)]\nquicksort(A, 0, n - 1)\nstable = True\nfor i in range(n-1):\n if A[i][1] == A[i + 1][1] and A[i][2] > A[i + 1][2]:\n stable = False\nprint('Stable' if stable else 'Not stable')\nA = [(a[0], a[1]) for a in A]\nprint('\\n'.join(map(lambda x: ' '.join(map(str, x)), A)))\n" ]
25
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A=[0]*n\n", "A=[0]*n\n\n\nquicksort(A,inds,0,n-1)\n", "A=[0]*n\n\n\nquicksort(A,inds,0,n-1)\n\n\nif stable_flag:\n", "A=[0]*n\n\n\ndi=defaultdict(int)\n\n\nquicksort(A,inds,0,n-1)\n\n\nif stable_flag:\n", "A=[0]*n\n\n\ndi=defaultdict(int)\n\n\ndef partition:\n \n\nquicksort(A,inds,0,n-1)\n\n\nif stable_flag:\n", "n=int(input())\n\nA=[0]*n\n\n\ndi=defaultdict(int)\n\n\ndef partition:\n \n\nquicksort(A,inds,0,n-1)\n\n\nif stable_flag:\n", "n=int(input())\n\nA=[0]*n\n\n\ndi=defaultdict(int)\n\n\ndef partition:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\n\n\nif stable_flag:\n", "n=int(input())\n\nA=[0]*n\n\n\ndi=defaultdict(int)\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\n\n\nif stable_flag:\n", "n=int(input())\n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\n\n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\n\n\nif stable_flag:\n", "n=int(input())\n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\n\n\nif stable_flag:\n", "n=int(input())\ncards=[0]*n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\n\n\nif stable_flag:\n", "n=int(input())\ncards=[0]*n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n", "from import \n\nn=int(input())\ncards=[0]*n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n", "from import \n\nn=int(input())\ncards=[0]*n\nA=[0]*n\n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from import \n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quicksort:\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort:\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n \n\nfor i in range(n):\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n print(\"Stable\")\n\n\nfor i in range(n):\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n print(\"Stable\")\n\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n \ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n \ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n \ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n \ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n \n \ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n \n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n \n \n if :\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n \n\n if :\n \n \nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n \n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n \n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n \n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n \n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n \n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n break\n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in range(p,r):\n if A[j] <= x:\n i+=1\n A[i],A[j]=A[j],A[i]\n inds[i],inds[j]=inds[j],inds[i]\n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if :\n \n break\n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in range(p,r):\n if A[j] <= x:\n i+=1\n A[i],A[j]=A[j],A[i]\n inds[i],inds[j]=inds[j],inds[i]\n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if d[num_i][di[num_i]] != suit:\n \n break\n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n", "from collections import defaultdict\n\nn=int(input())\ncards=[0]*n\nA=[0]*n\ninds=[0]*n\nd=defaultdict(lambda :[])\ndi=defaultdict(int)\nfor i in range(n):\n tmp=input().split()\n cards[i]=tmp[0],int(tmp[1])\n A[i]=int(tmp[1])\n inds[i]=i\n d[int(tmp[1])].append(tmp[0])\n\ndef partition(A,inds,p,r):\n x=A[r]\n i=p-1\n for j in range(p,r):\n if A[j] <= x:\n i+=1\n A[i],A[j]=A[j],A[i]\n inds[i],inds[j]=inds[j],inds[i]\n A[i+1],A[r]=A[r],A[i+1]\n inds[i+1],inds[r]=inds[r],inds[i+1]\n return i+1\n\ndef quicksort(A,inds,p,r):\n if p < r:\n q=partition(A,inds,p,r)\n quicksort(A,inds,p,q-1)\n quicksort(A,inds,q+1,r)\n\nquicksort(A,inds,0,n-1)\n\nstable_flag=True\nfor i in range(n):\n num_i=cards[inds[i]][1]\n suit=cards[inds[i]][0]\n\n if d[num_i][di[num_i]] != suit:\n stable_flag=False\n break\n di[num_i]+=1\n\nif stable_flag:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(*cards[inds[i]])\n" ]
46
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def t(A,p,r):\n", "def t(A,p,r):\n \n\nn=int(input())\n", "def t(A,p,r):\n \n\nn=int(input())\n\n\nk(A,0,n-1)\n", "def t(A,p,r):\n \n\nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \n\nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \n\nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n" ]
25
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def quickSort:\n", "def partition:\n \n\ndef quickSort:\n", "import sys\n\n\ndef partition:\n \n\ndef quickSort:\n", "import sys\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nif :\n", "import sys\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef isStable(A):\n \n\nif :\n", "import sys\n\n\ndef partition:\n \n \ndef quickSort:\n \n\ndef isStable(A):\n \n\nif :\n", "import sys\n\n\ndef partition:\n \n \ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n\nif :\n", "import sys\n\n\ndef partition(A, p, r):\n \n \ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n\nif :\n", "import sys\n\n\ndef partition(A, p, r):\n \n \ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif :\n", "import sys\n\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif :\n", "import sys\n\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n", "import sys\n\n\ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n \n \ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n \n A[r] = temp\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n \n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n \n B = []\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n \n \n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n \n \n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n i = p - 1\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n \n i = p - 1\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n \nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n \n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in :\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n \n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n \n quickSort(B, 0, n-1)\n if :\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n \n quickSort(B, 0, n-1)\n if isStable(B):\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n B.append([c[0], int(c[1]), i])\n quickSort(B, 0, n-1)\n if isStable(B):\n print(\"Stable\")\n else:\n \n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n \n B.append([c[0], int(c[1]), i])\n quickSort(B, 0, n-1)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for b in B:\n print(b[0], b[1])\n", "import sys\n\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i = i + 1\n temp = A[i]\n A[i] = A[j]\n A[j] = temp\n temp = A[i+1]\n A[i+1] = A[r]\n A[r] = temp\n return i+1\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef isStable(A):\n for i in range(0, len(A)-1):\n if A[i][1] == A[i+1][1]:\n if A[i][2] > A[i+1][2]:\n return False\n return True\n\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n B = []\n for i in range(n):\n c = sys.stdin.readline().split()\n B.append([c[0], int(c[1]), i])\n quickSort(B, 0, n-1)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for b in B:\n print(b[0], b[1])\n" ]
39
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "n=int(input())\n", "def k(A,p,r):\n \n\nn=int(input())\n", "def k(A,p,r):\n \n\nn=int(input())\n\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\n", "def k(A,p,r):\n \n\nn=int(input())\n\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\n\nk(A,0,n-1)\n", "def k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\n\nk(A,0,n-1)\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\n\nk(A,0,n-1)\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]:\n if A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nf=lambda x:(x[0],int(x[1]),x[2])\nA=[(*e.split(),i)for i,e in enumerate(sys.stdin)]\nA=list(map(f,A))\nk(A,0,n-1)\nfor e in[[s(A)+'table']]+A:print(*e[:2])\n" ]
26
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def s(A):\n", "def k(A,p,r):\n \ndef s(A):\n", "def k(A,p,r):\n \ndef s(A):\n \n\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\n", "def k(A,p,r):\n \ndef s(A):\n \n\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "def k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "def k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n \n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n \nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in :\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in :\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n \n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n \n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\ndef t(A,p,r):\n x=A[r][1];i=p-1\n for j in range(p,r):\n if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]\n A[i+1],A[r]=A[r],A[i+1]\n return i+1\ndef k(A,p,r):\n if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)\ndef s(A):\n for i in range(n-1):\n if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'\n return'S'\nn=int(input())\nA=[(e[0],int(e[2:]),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n" ]
23
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "a = []\n\n\nb = a[:]\n", "a = []\nfor i in range(n):\n \n\nb = a[:]\n", "a = []\nfor i in range(n):\n \n\nb = a[:]\n\n\ndef checkStable(a):\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\n\ndef checkStable(a):\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition:\n \n\ndef checkStable(a):\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition:\n \n\ndef checkStable(a):\n \n\nquickSort(a, 0, n - 1)\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition:\n \n\ndef checkStable(a):\n \n\nquickSort(a, 0, n - 1)\n\n\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable(a):\n \n\nquickSort(a, 0, n - 1)\n\n\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable(a):\n \n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition(a, p, r):\n \n\ndef quickSort:\n \n\ndef checkStable(a):\n \n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition(a, p, r):\n \n\ndef quickSort:\n \n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition(a, p, r):\n \n \ndef quickSort:\n \n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n\nb = a[:]\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n \n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n \ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n i = p - 1\n \n \ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n \n \nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n \nb = a[:]\n\ndef partition(a, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n \n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n \n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n \n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in :\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p,r):\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n \n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p,r):\n \n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n if a[i][1] == a[i + 1][1] and a[i][2] > a[i + 1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p,r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in :\n if a[i][1] == a[i + 1][1] and a[i][2] > a[i + 1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n", "n = int(input())\na = []\nfor i in range(n):\n suit, num = input().split()\n a.append([suit, int(num), int(i)])\n\nb = a[:]\n\ndef partition(a, p, r):\n x = a[r][1]\n i = p - 1\n for j in range(p,r):\n if a[j][1] <= x:\n i += 1\n a[i], a[j] = a[j], a[i]\n a[i + 1], a[r] = a[r], a[i + 1]\n return i + 1\n\ndef quickSort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quickSort(a, p, q - 1)\n quickSort(a, q + 1, r)\n\ndef checkStable(a):\n for i in range(len(a) - 1):\n if a[i][1] == a[i + 1][1] and a[i][2] > a[i + 1][2]:\n return \"Not stable\"\n return \"Stable\"\n\nquickSort(a, 0, n - 1)\n\nprint(checkStable(a))\nfor a_i in a:\n print(a_i[0],a_i[1])\n" ]
30
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "def is_stable:\n", "def is_stable:\n \n\ndef quicksort:\n", "def is_stable:\n \n\ndef partition:\n \n\ndef quicksort:\n", "def is_stable:\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nif :\n", "def is_stable:\n \n \ndef partition:\n \n\ndef quicksort:\n \n\nif :\n", "def is_stable:\n \n \ndef partition:\n \n\ndef quicksort(A, p, r):\n \n\nif :\n", "def is_stable(before_sort, after_sort):\n \n \ndef partition:\n \n\ndef quicksort(A, p, r):\n \n\nif :\n", "def is_stable(before_sort, after_sort):\n \n \ndef partition:\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif :\n", "def is_stable(before_sort, after_sort):\n \n \ndef partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif :\n", "def is_stable(before_sort, after_sort):\n \n \ndef partition:\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n", "def is_stable(before_sort, after_sort):\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n", "def is_stable(before_sort, after_sort):\n \n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n", "def is_stable(before_sort, after_sort):\n \n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n \n for i in range(n):\n", "def is_stable(before_sort, after_sort):\n \n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n cards = list()\n for i in range(n):\n", "def is_stable(before_sort, after_sort):\n \n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n cards = list()\n for i in range(n):\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n cards = list()\n for i in range(n):\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n cards = list()\n for i in range(n):\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n \n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n \n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n \n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n \n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n \n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n \ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n \n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n \ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n \n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n \n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n \n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n \n \n cards.append(card)\n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n card = input().split()\n \n cards.append(card)\n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n", "def is_stable(before_sort, after_sort):\n current_num = 0\n same_number_card = list()\n for num in after_sort:\n if current_num == int(num[1]):\n for same_card in same_number_card:\n if before_sort.index(same_card) > before_sort.index(num):\n return False\n same_number_card.append(num)\n else:\n current_num = int(num[1])\n same_number_card = [num,]\n return True\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p - 1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i + 1\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nif __name__ == '__main__':\n n = int(input())\n cards = list()\n for i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\n before_cards = list(cards)\n quicksort(cards, 0, n-1)\n print('Stable') if is_stable(before_cards, cards) else print('Not stable')\n for card in cards:\n print(*card)\n" ]
36
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "cc=[]\n", "cards = []\n\n\ncc=[]\n", "cards = []\nfor _ in range(n):\n \n\ncc=[]\n", "cards = []\nfor _ in range(n):\n \n\norig = cards[:]\n\n\ncc=[]\n", "cards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\n\n\ncc=[]\n", "cards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\n\nnn=[c[1] for c in cards]\ncc=[]\n", "cards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\n\nnn=[c[1] for c in cards]\ncc=[]\n\n\nfor c in cards:\n", "import sys\n\n\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\n\nnn=[c[1] for c in cards]\ncc=[]\n\n\nfor c in cards:\n", "import sys\n\n\ndef Quicksort:\n \n\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\n\nnn=[c[1] for c in cards]\ncc=[]\n\n\nfor c in cards:\n", "import sys\n\n\ndef Quicksort:\n \n\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\n\n\nfor c in cards:\n", "import sys\n\n\ndef Quicksort:\n \n\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n", "import sys\n\ndef Partition:\n \n\ndef Quicksort:\n \n\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n", "import sys\n\ndef Partition:\n \n\ndef Quicksort:\n \n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n", "import sys\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n", "import sys\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n", "import sys\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n \nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n \ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n \nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n \ndef Quicksort:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n \ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n \n \n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n \n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n \n \norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n \n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n \n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n \n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n \n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n \n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n \n for p in cards:\n \n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n for o in orig:\n \n for p in cards:\n \n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n for o in orig:\n \n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n for o in orig:\n \n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n for o in orig:\n \n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if : continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n \n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n \nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in :\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n \n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n \n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n q, A = Partition(A, p, r)\n \n \n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n q, A = Partition(A, p, r)\n \n A = Quicksort(A, q+1, r)\n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n", "import sys\n\ndef Partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\n if A[j][1] <= x:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i+1], A[r] = A[r], A[i+1]\n return i+1, A\n\n\ndef Quicksort(A, p, r):\n if p < r:\n q, A = Partition(A, p, r)\n A = Quicksort(A, p, q-1)\n A = Quicksort(A, q+1, r)\n return A\n\nn = int(sys.stdin.readline())\ncards = []\nfor _ in range(n):\n s,t = sys.stdin.readline().split()\n cards.append([s, int(t)])\n\norig = cards[:]\nQuicksort(cards, 0, n-1)\nmm=[c[0] for c in cards]\nnn=[c[1] for c in cards]\ncc=[]\nfor k in nn:\n if k in cc: continue\n cc.append(k)\n if nn.count(k)<=1: continue\n a=[]\n b=[]\n for o in orig:\n if o[1]==k: a.append(o[0])\n for p in cards:\n if p[1]==k: b.append(p[0])\n if a!=b:\n print('Not stable')\n break\nelse:\n print('Stable')\n\nfor c in cards:\n print(c[0],c[1])\n" ]
47
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "A = []\n", "A = []\n\n\nfor a in A:\n", "A = []\n\n\nfor a in A:\n \n\nfor a in A:\n", "A = []\n\n\nfor a in A:\n \n\nquick_sort(A, 0, n)\n\n\nfor a in A:\n", "A = []\n\n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\n\n\nfor a in A:\n", "A = []\n\n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\n\nfor a in A:\n", "A = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\n\nfor a in A:\n", "def partition:\n \n\nA = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\n\nfor a in A:\n", "def partition:\n \n\nA = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n", "def partition:\n \n\nA = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n \nif :\n", "def partition:\n \n\ndef quick_sort:\n \n\nA = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n \nif :\n", "def partition:\n \n\ndef quick_sort:\n \n\nA = []\nfor i in range(n):\n \n\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n \nif :\n \n\nfor a in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n \nif :\n \n\nfor a in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n \nfor a in A:\n \nif :\n \n\nfor a in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif :\n \n\nfor a in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif :\n \n\nfor a in A:\n print(*a)\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n \nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif :\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif :\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif :\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif dct0 == dct1:\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition:\n \n\ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif dct0 == dct1:\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n\ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n \nif dct0 == dct1:\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n\ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n \nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n\ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n \nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n\ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n \ndef quick_sort:\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n i = l - 1\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n i = l - 1\n for j in :\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n i = l - 1\n for j in :\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n i = l - 1\n for j in :\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n \nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n \n i = l - 1\n for j in :\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n x = A[r - 1]\n i = l - 1\n for j in :\n \n \ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n x = A[r - 1]\n i = l - 1\n for j in :\n \n A[i + 1], A[r - 1] = A[r - 1], A[i + 1]\n \n\ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n x = A[r - 1]\n i = l - 1\n for j in :\n \n A[i + 1], A[r - 1] = A[r - 1], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n x = A[r - 1]\n i = l - 1\n for j in :\n if A[j][1] <= x[1]:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r - 1] = A[r - 1], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n", "def partition(A, l, r):\n x = A[r - 1]\n i = l - 1\n for j in range(l, r - 1):\n if A[j][1] <= x[1]:\n i += 1\n A[i], A[j] = A[j], A[i]\n A[i + 1], A[r - 1] = A[r - 1], A[i + 1]\n return i + 1\n\n\ndef quick_sort(A, l, r):\n if r - l > 1:\n q = partition(A, l, r)\n quick_sort(A, l, q)\n quick_sort(A, q, r)\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append((a, int(b)))\ndct0 = {}\nfor a in A:\n dct0[a[1]] = []\nfor a in A:\n dct0[a[1]].append(a[0])\nquick_sort(A, 0, n)\ndct1 = {}\nfor a in A:\n dct1[a[1]] = []\nfor a in A:\n dct1[a[1]].append(a[0])\nif dct0 == dct1:\n print('Stable')\nelse:\n print('Not stable')\nfor a in A:\n print(*a)\n" ]
38
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]
0/::0
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). Constraints * 1 ≤ n ≤ 100,000 * 1 ≤ the number of a card ≤ 109 * There are no identical card in the input 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. Examples Input 6 D 3 H 2 D 1 S 3 D 2 C 1 Output Not stable D 1 C 1 D 2 H 2 D 3 S 3 Input 2 S 1 H 1 Output Stable S 1 H 1
[ "\n", "if :\n", "def quick:\n \n\nif :\n", "def swap(A,i,j):\n \n\ndef quick:\n \n\nif :\n", "def swap(A,i,j):\n \n\ndef partition:\n \n\ndef quick:\n \n\nif :\n", "def swap(A,i,j):\n \n\ndef partition:\n \n\ndef quick:\n \n\nimport sys\nif :\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition:\n \n\ndef quick:\n \n\nimport sys\nif :\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick:\n \n\nimport sys\nif :\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick:\n \n\nimport sys\nif :\n \n A = []\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick:\n \n \nimport sys\nif :\n \n A = []\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif :\n \n A = []\n", "def swap(A,i,j):\n \n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n\ndef partition(A,p=0, r=None):\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n x = A[r]\n i = p-1\n \n \ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n \n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n \nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n \n \ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n for i in :\n \n \ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n \n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n \n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in :\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if :\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in :\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n \n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if :\n \n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if :\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if :\n \n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n \n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if :\n \n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if :\n \n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if isStable(A):\n \n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n \n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n \n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n \n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \n quick(A,q+1,r)\n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \n quick(A,q+1,r)\n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n \n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n \n quick(A,q+1,r)\n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n A.append([card[0], int(card[1]), i])\n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n \n quick(A,p,q-1)\n quick(A,q+1,r)\n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n A.append([card[0], int(card[1]), i])\n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card[0], card[1])\n", "def swap(A,i,j):\n A[i],A[j] = A[j],A[i]\n return A\n\ndef isStable(A):\n for i in range(1, len(A)):\n if A[i][1] == A[i-1][1]:\n if A[i][2] < A[i-1][2]:\n return False\n return True\n\ndef partition(A,p=0, r=None):\n if r is None:\n r = len(A)-1\n x = A[r]\n i = p-1\n for j in range(p,r):\n if A[j][1] <= x[1]:\n i += 1\n swap(A,i,j)\n swap(A,i+1,r)\n return i+1\n\ndef quick(A,p=0,r=None):\n if r is None:\n r = len(A)-1\n if p < r:\n q = partition(A,p,r)\n quick(A,p,q-1)\n quick(A,q+1,r)\n\nimport sys\nif __name__ == \"__main__\":\n n = int(sys.stdin.readline())\n A = []\n for i in range(n):\n card = sys.stdin.readline().split()\n A.append([card[0], int(card[1]), i])\n quick(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for card in A:\n print(card[0], card[1])\n" ]
49
[ { "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3" } ]
[ { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nD 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 1\nH 2", "output": "Stable\nS 1\nH 2\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nD 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 3\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nH 3\nD 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Not stable\nC 2\nC 2\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nS 4\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nD 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nH 3\nS 3\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Not stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nC 2", "output": "Not stable\nD 0\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 3\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nC 3\nD 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nD 3\nC 3\nS 4\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 2\nC 2", "output": "Stable\nH 1\nC 2\nC 2\nC 2\nD 3\nS 4\n" }, { "input": "2\nS 0\nH 1", "output": "Stable\nS 0\nH 1\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 2", "output": "Stable\nD 1\nH 2\nD 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nD 1\nH 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 2\nD 0\nS 3\nD 2\nC 0", "output": "Not stable\nD 0\nC 0\nD 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nD 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nC 2\nC 2", "output": "Not stable\nD 1\nC 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 2\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nC 0\nH 2\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nS 3\nH 3\nD 5\n" }, { "input": "6\nD 2\nH 5\nC 2\nS 3\nC 2\nC 3", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 1", "output": "Stable\nC 0\nC 1\nC 1\nH 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nD 3\nS 4\nC 8\n" }, { "input": "6\nD 2\nH 5\nC 3\nS 3\nC 2\nC 3", "output": "Not stable\nD 2\nC 2\nS 3\nC 3\nC 3\nH 5\n" }, { "input": "6\nC 3\nH 1\nC 2\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nC 3\nC 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nC 1\nD 2\nC 2\nC 2\nS 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 5\nS 4\nC 3\nC 1", "output": "Not stable\nH 1\nC 1\nC 3\nD 3\nS 4\nC 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 1\nC 2\nC 2", "output": "Not stable\nH 1\nS 1\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 4\nH 2\nD 0\nS 3\nC 2\nC 1", "output": "Not stable\nD 0\nC 1\nC 2\nH 2\nS 3\nD 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 3\nC 2\nC 0", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 2", "output": "Not stable\nD 1\nD 2\nC 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 5\nH 0\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH 0\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 1", "output": "Stable\nC 0\nC 1\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 3\nC 1\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nS 3\nD 8\n" }, { "input": "6\nD 3\nH 0\nC 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nC 4\nS 8\n" }, { "input": "6\nD 6\nH 0\nD 1\nS 4\nC 8\nC 1", "output": "Stable\nH 0\nD 1\nC 1\nS 4\nD 6\nC 8\n" }, { "input": "6\nC 3\nH 1\nC 4\nS 4\nC 3\nC 1", "output": "Stable\nH 1\nC 1\nC 3\nC 3\nC 4\nS 4\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 2\nC 2\nC 2", "output": "Not stable\nH 1\nS 2\nC 2\nC 2\nC 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nC 4\nS 4\nC 2\nD 1", "output": "Stable\nH 1\nD 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 1\nC 2\nC 0", "output": "Not stable\nC 0\nS 1\nD 2\nH 2\nC 2\nD 3\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 4", "output": "Stable\nD 1\nD 2\nD 3\nS 3\nH 4\nC 4\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 5\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 5\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC 0", "output": "Stable\nC 0\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nD 8\nH 2\nC 0\nS 1\nC 1\nC 2", "output": "Stable\nC 0\nS 1\nC 1\nH 2\nC 2\nD 8\n" }, { "input": "6\nD 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nD 3\nD 4\nS 8\n" }, { "input": "6\nD 2\nH 2\nC 1\nS 5\nC 2\nC 2", "output": "Not stable\nC 1\nH 2\nD 2\nC 2\nC 2\nS 5\n" }, { "input": "6\nD 3\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 3\n" }, { "input": "6\nD 5\nH -1\nC 0\nS 7\nC 2\nC 2", "output": "Stable\nH -1\nC 0\nC 2\nC 2\nD 5\nS 7\n" }, { "input": "6\nD 5\nH 3\nC 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nC 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 4\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 2\nC 3\nD 4\nS 8\n" }, { "input": "6\nD 5\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 5\n" }, { "input": "6\nD 5\nH 3\nD 0\nS 6\nC 2\nC -1", "output": "Stable\nC -1\nD 0\nC 2\nH 3\nD 5\nS 6\n" }, { "input": "6\nC 3\nH 0\nD 2\nS 8\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nD 2\nC 2\nC 3\nS 8\n" }, { "input": "6\nD 8\nH 2\nD 2\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nD 2\nS 2\nC 2\nD 8\n" }, { "input": "6\nD 8\nH 2\nD 4\nS 2\nC 2\nC 0", "output": "Stable\nC 0\nH 2\nS 2\nC 2\nD 4\nD 8\n" }, { "input": "6\nD 3\nH 2\nD 1\nS 2\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nS 2\nD 2\nH 2\nD 3\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nC 2\nC 1", "output": "Not stable\nC 0\nC 1\nC 2\nH 2\nD 3\nS 3\n" }, { "input": "6\nD 3\nH 2\nC 1\nS 3\nC 0\nC 2", "output": "Stable\nC 0\nC 1\nH 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 0\nH 2\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nD 0\nC 1\nH 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 7\nH 2\nC 2\nS 3\nC 2\nC 2", "output": "Stable\nH 2\nC 2\nC 2\nC 2\nS 3\nD 7\n" }, { "input": "6\nD 5\nH 0\nC 1\nS 3\nC 2\nC 1", "output": "Stable\nH 0\nC 1\nC 1\nC 2\nS 3\nD 5\n" }, { "input": "2\nS 2\nH 2", "output": "Stable\nS 2\nH 2\n" }, { "input": "6\nD 3\nH 4\nD 1\nS 3\nD 2\nC 0", "output": "Not stable\nC 0\nD 1\nD 2\nS 3\nD 3\nH 4\n" }, { "input": "6\nD 3\nH 0\nC 1\nS 3\nC 2\nC 2", "output": "Stable\nH 0\nC 1\nC 2\nC 2\nD 3\nS 3\n" }, { "input": "6\nD 5\nH 1\nC 0\nS 3\nC 2\nC 2", "output": "Stable\nC 0\nH 1\nC 2\nC 2\nS 3\nD 5\n" }, { "input": "6\nD 5\nH 3\nC 2\nS 3\nC 2\nC 4", "output": "Not stable\nC 2\nC 2\nS 3\nH 3\nC 4\nD 5\n" }, { "input": "6\nD 2\nH 2\nC 0\nS 3\nC 2\nC 2", "output": "Not stable\nC 0\nH 2\nD 2\nC 2\nC 2\nS 3\n" }, { "input": "6\nD 2\nH 3\nC 4\nS 3\nC 2\nC 2", "output": "Not stable\nD 2\nC 2\nC 2\nS 3\nH 3\nC 4\n" }, { "input": "6\nD 5\nH 2\nC -1\nS 3\nC 1\nC 1", "output": "Stable\nC -1\nC 1\nC 1\nH 2\nS 3\nD 5\n" }, { "input": "6\nD 3\nH 0\nD 1\nS 4\nD 4\nC 1", "output": "Not stable\nH 0\nD 1\nC 1\nD 3\nD 4\nS 4\n" }, { "input": "6\nD 3\nH 2\nC 0\nS 3\nD 1\nC 1", "output": "Not stable\nC 0\nD 1\nC 1\nH 2\nS 3\nD 3\n" }, { "input": "6\nD 3\nH 1\nD 2\nS 4\nC 2\nC 1", "output": "Stable\nH 1\nC 1\nD 2\nC 2\nD 3\nS 4\n" }, { "input": "6\nD 2\nH 5\nC 6\nS 3\nC 2\nC 2", "output": "Stable\nD 2\nC 2\nC 2\nS 3\nH 5\nC 6\n" }, { "input": "6\nD 3\nH 1\nC 2\nS 4\nC 4\nC 1", "output": "Not stable\nH 1\nC 1\nC 2\nD 3\nC 4\nS 4\n" }, { "input": "6\nD 1\nH 5\nC 3\nS 3\nC 2\nC 1", "output": "Not stable\nD 1\nC 1\nC 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 0\nH 5\nC 3\nS 3\nC 2\nD 2", "output": "Not stable\nD 0\nC 2\nD 2\nS 3\nC 3\nH 5\n" }, { "input": "6\nD 3\nH 1\nC 3\nS 4\nC 5\nC 2", "output": "Not stable\nH 1\nC 2\nC 3\nD 3\nS 4\nC 5\n" } ]