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
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "#i~j-1の和はS[j]-S[i]\n", "#i~j-1の和はS[j]-S[i]\n\nmemo = [[-1]*(N+1) for _ in range(N)]\n", "#i~j-1の和はS[j]-S[i]\n\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n", "mod = 10**9+7\n\n\n#i~j-1の和はS[j]-S[i]\n\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n", "mod = 10**9+7\n\na = list(map(int, input().split()))\n#i~j-1の和はS[j]-S[i]\n\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n", "mod = 10**9+7\n\na = list(map(int, input().split()))\n#i~j-1の和はS[j]-S[i]\nfor i in :\n \nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n", "mod = 10**9+7\n\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in :\n \nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n", "mod = 10**9+7\n\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in :\n \nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in :\n \nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in :\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in :\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n \n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n \n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if :\n \n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if :\n \n \n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if :\n \n if j-i == 1:\n \n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n \nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if :\n \n if j-i == 1:\n \n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n return memo[i][j]\nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if :\n \n if j-i == 1:\n \n return 0\n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n return memo[i][j]\nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if memo[i][j]>=0:\n \n if j-i == 1:\n \n return 0\n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n return memo[i][j]\nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if memo[i][j]>=0:\n return memo[i][j]\n if j-i == 1:\n \n return 0\n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n return memo[i][j]\nprint(dp(0, N))\n", "mod = 10**9+7\nN = int(input())\na = list(map(int, input().split()))\nS = [0]*(N+1)#i~j-1の和はS[j]-S[i]\nfor i in range(1, N+1):\n S[i] = S[i-1]+a[i-1]\nmemo = [[-1]*(N+1) for _ in range(N)]\ndef dp(i, j):\n if memo[i][j]>=0:\n return memo[i][j]\n if j-i == 1:\n memo[i][j] = 0\n return 0\n memo[i][j] = min(dp(i, k)+dp(k, j)+S[j]-S[i]for k in range(i+1, j))\n return memo[i][j]\nprint(dp(0, N))\n" ]
21
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "main()\n", "def main():\n \nmain()\n", "import sys\n\n\ndef main():\n \nmain()\n", "import sys\nfrom import \n\n\ndef main():\n \nmain()\n", "import sys\nfrom import \nimport math\n\ndef main():\n \nmain()\n", "import sys\nfrom import \nimport math\n\ndef main():\n \n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n \nmain()\n", "import sys\nfrom import accumulate\nimport math\n\ndef main():\n \n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n \nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n \n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n \nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n \n \n dp=[[math.inf]*n for _ in range(n)]\n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n \nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n \n \n dp=[[math.inf]*n for _ in range(n)]\n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n \nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n \n \n dp=[[math.inf]*n for _ in range(n)]\n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n \n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n \n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n \n #print(*dp,sep=\"\\n\")\n \n #print(accA)\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n \n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n \n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n \n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n \n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in :\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in :\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n \n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n dpL=dp[L]\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n dpL=dp[L]\n for R in :\n \n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n dpL=dp[L]\n for R in :\n dpL[R]=min([dpL[k-1]+dp[k][R] for k in range(L+1,R+1)])+accA[R+1]-accA[L]\n #print(dp)\n print(dp[0][-1])\nmain()\n", "import sys\nfrom itertools import accumulate\nimport math\n\ndef main():\n input=sys.stdin.readline\n n=int(input())\n A=list(map(int,input().split()))\n dp=[[math.inf]*n for _ in range(n)]\n for i in range(n):\n dp[i][i]=0\n #print(*dp,sep=\"\\n\")\n accA=list(accumulate([0]+A))\n #print(accA)\n for L in reversed(range(n)):\n dpL=dp[L]\n for R in range(L+1,n):\n dpL[R]=min([dpL[k-1]+dp[k][R] for k in range(L+1,R+1)])+accA[R+1]-accA[L]\n #print(dp)\n print(dp[0][-1])\nmain()\n" ]
24
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "A=[0]+list(accumulate(map(int,input().split())))\n", "A=[0]+list(accumulate(map(int,input().split())))\n\n\nprint(DP[0][n-1])\n", "n=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\n\n\nprint(DP[0][n-1])\n", "from import \nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\n\n\nprint(DP[0][n-1])\n", "import sys\n\nfrom import \nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\n\n\nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom import \nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\n\n\nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom import \nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\n\nfor d in :\n \nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom import \nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\nDP=[[0]*n for _ in range(n)]\nfor d in :\n \nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom import accumulate\nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\nDP=[[0]*n for _ in range(n)]\nfor d in :\n \nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom itertools import accumulate\nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\nDP=[[0]*n for _ in range(n)]\nfor d in :\n \nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom itertools import accumulate\nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\nDP=[[0]*n for _ in range(n)]\nfor d in :\n for i in range(n-d):\n j=i+d\n tmp=float('inf')\n for k in range(i,j):\n tmp=min(tmp,DP[i][k]+DP[k+1][j])\n DP[i][j]=tmp+A[j+1]-A[i]\nprint(DP[0][n-1])\n", "import sys\ninput=sys.stdin.readline\nfrom itertools import accumulate\nn=int(input())\nA=[0]+list(accumulate(map(int,input().split())))\nDP=[[0]*n for _ in range(n)]\nfor d in range(1,n):\n for i in range(n-d):\n j=i+d\n tmp=float('inf')\n for k in range(i,j):\n tmp=min(tmp,DP[i][k]+DP[k+1][j])\n DP[i][j]=tmp+A[j+1]-A[i]\nprint(DP[0][n-1])\n" ]
13
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "n = int(input())\n", "n = int(input())\n\n\nfor width in :\n", "n = int(input())\n\n\ndp = [[0]*440 for i in range(440)]\n\n\nfor width in :\n", "n = int(input())\n\n\ndp = [[0]*440 for i in range(440)]\n\n\nfor width in :\n \n\nprint(dp[0][n])\n", "n = int(input())\n\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\n\n\nfor width in :\n \n\nprint(dp[0][n])\n", "n = int(input())\n\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n\nfor width in :\n \n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n\nfor width in :\n \n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n\nfor width in range(2,n+1):\n \n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n \nfor width in range(2,n+1):\n \n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n \nfor width in range(2,n+1):\n for l in range(n-width+1):\n r = l + width\n dp[l][r] = float('inf')\n for m in range(l+1,r):\n dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + s[l][r])\n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n \n for r in :\n \n\nfor width in range(2,n+1):\n for l in range(n-width+1):\n r = l + width\n dp[l][r] = float('inf')\n for m in range(l+1,r):\n dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + s[l][r])\n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n s[l][l+1] = a[l]\n for r in :\n \n\nfor width in range(2,n+1):\n for l in range(n-width+1):\n r = l + width\n dp[l][r] = float('inf')\n for m in range(l+1,r):\n dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + s[l][r])\n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n s[l][l+1] = a[l]\n for r in :\n s[l][r] = s[l][r-1] + a[r-1]\n\nfor width in range(2,n+1):\n for l in range(n-width+1):\n r = l + width\n dp[l][r] = float('inf')\n for m in range(l+1,r):\n dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + s[l][r])\n\nprint(dp[0][n])\n", "n = int(input())\na = list(map(int,input().split()))\n\ndp = [[0]*440 for i in range(440)]\ns = [[0]*440 for i in range(440)]\nfor l in range(n):\n s[l][l+1] = a[l]\n for r in range(l+2,n+1):\n s[l][r] = s[l][r-1] + a[r-1]\n\nfor width in range(2,n+1):\n for l in range(n-width+1):\n r = l + width\n dp[l][r] = float('inf')\n for m in range(l+1,r):\n dp[l][r] = min(dp[l][r], dp[l][m] + dp[m][r] + s[l][r])\n\nprint(dp[0][n])\n" ]
15
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "for i in range(n):\n", "INF = 10**20\n\n\nfor i in range(n):\n", "INF = 10**20\n\n\nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "n = int(input())\nINF = 10**20\n\n\nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "n = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\n\n\nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "n = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\n\nfor _ in :\n \nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "n = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\nmemo_ls = [[0 for j in range(n)] for i in range(n)]\nfor _ in :\n \nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "import sys\n\nn = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\nmemo_ls = [[0 for j in range(n)] for i in range(n)]\nfor _ in :\n \nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "import sys\n\nn = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\nmemo_ls = [[0 for j in range(n)] for i in range(n)]\nfor _ in range(1,n):\n \nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "import sys\n\nn = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\nmemo_ls = [[0 for j in range(n)] for i in range(n)]\nfor _ in range(1,n):\n for i in range(n-_):\n j = i + _\n sum_ij = sum(a_ls[i:j+1])\n memo_ls[i][j] = sum_ij\n res = INF if j - i > 1 else 0\n for k in range(i,j):\n res = min(memo_ls[i][k] + memo_ls[k+1][j], res)\n memo_ls[i][j] += res\nfor i in range(n):\n \nprint(memo_ls[0][-1])\n", "import sys\n\nn = int(input())\nINF = 10**20\na_ls = [int(i) for i in sys.stdin.readline().split()]\nmemo_ls = [[0 for j in range(n)] for i in range(n)]\nfor _ in range(1,n):\n for i in range(n-_):\n j = i + _\n sum_ij = sum(a_ls[i:j+1])\n memo_ls[i][j] = sum_ij\n res = INF if j - i > 1 else 0\n for k in range(i,j):\n res = min(memo_ls[i][k] + memo_ls[k+1][j], res)\n memo_ls[i][j] += res\nfor i in range(n):\n memo_ls[i][i] = a_ls[i]\nprint(memo_ls[0][-1])\n" ]
12
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "dp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n", "dp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\n\nprint(dp[0][N])\n", "dp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\n\nfor k in :\n \n\nprint(dp[0][N])\n", "N = int(input())\n\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\n\nfor k in :\n \n\nprint(dp[0][N])\n", "N = int(input())\n\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\n\nfor k in :\n \n\nprint(dp[0][N])\n", "N = int(input())\n\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n \n\nfor k in :\n \n\nprint(dp[0][N])\n", "INF = 10**18\n\nN = int(input())\n\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n \n\nfor k in :\n \n\nprint(dp[0][N])\n", "from import \n\nINF = 10**18\n\nN = int(input())\n\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n \n\nfor k in :\n \n\nprint(dp[0][N])\n", "from import \n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n \n\nfor k in :\n \n\nprint(dp[0][N])\n", "from import \n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n \n\nfor k in :\n for i in range(0, N - k + 1):\n for j in range(i, i + k + 1):\n dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])\n\nprint(dp[0][N])\n", "from import \n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n dp[i][i + 1] = 0\n\nfor k in :\n for i in range(0, N - k + 1):\n for j in range(i, i + k + 1):\n dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])\n\nprint(dp[0][N])\n", "from import \n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n dp[i][i + 1] = 0\n\nfor k in range(1, N + 1):\n for i in range(0, N - k + 1):\n for j in range(i, i + k + 1):\n dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])\n\nprint(dp[0][N])\n", "from itertools import \n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n dp[i][i + 1] = 0\n\nfor k in range(1, N + 1):\n for i in range(0, N - k + 1):\n for j in range(i, i + k + 1):\n dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])\n\nprint(dp[0][N])\n", "from itertools import accumulate\n\nINF = 10**18\n\nN = int(input())\nA = list(map(int, input().split()))\n\nS = [0] + list(accumulate(A))\n\ndp = [[INF for j in range(N + 1)] for i in range(N + 1)]\n\nfor i in range(N):\n dp[i][i + 1] = 0\n\nfor k in range(1, N + 1):\n for i in range(0, N - k + 1):\n for j in range(i, i + k + 1):\n dp[i][i + k] = min(dp[i][i + k], dp[i][j] + dp[j][i + k] + S[i + k] - S[i])\n\nprint(dp[0][N])\n" ]
15
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "SUM=[0]\n", "A=list(map(int,input().split()))\n\n\nSUM=[0]\n", "A=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\n", "A=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n \n\nfor i in :\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n \n\nfor i in :\n \n\nprint(DPLIST[0][N-1])\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n \n\nfor i in range(1,N):\n \n\nprint(DPLIST[0][N-1])\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n \n \nfor i in range(1,N):\n \n\nprint(DPLIST[0][N-1])\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n \n \nfor i in range(1,N):\n for j in range(i,N):\n\n ANS=float(\"inf\")\n\n for k in range(j-i,j):\n\n if ANS>DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]:\n ANS=DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]\n\n DPLIST[j-i][j]=ANS\n\nprint(DPLIST[0][N-1])\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n DPLIST[i][i]=0\n \n\nfor i in range(1,N):\n for j in range(i,N):\n\n ANS=float(\"inf\")\n\n for k in range(j-i,j):\n\n if ANS>DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]:\n ANS=DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]\n\n DPLIST[j-i][j]=ANS\n\nprint(DPLIST[0][N-1])\n", "N=int(input())\nA=list(map(int,input().split()))\n\nDPLIST=[[None]*N for i in range(N)]\n\nSUM=[0]\nfor i in range(N):\n DPLIST[i][i]=0\n SUM.append(SUM[-1]+A[i])\n\nfor i in range(1,N):\n for j in range(i,N):\n\n ANS=float(\"inf\")\n\n for k in range(j-i,j):\n\n if ANS>DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]:\n ANS=DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]\n\n DPLIST[j-i][j]=ANS\n\nprint(DPLIST[0][N-1])\n" ]
13
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\n" } ]
0/::0
There are N slimes lining up in a row. Initially, the i-th slime from the left has a size of a_i. Taro is trying to combine all the slimes into a larger slime. He will perform the following operation repeatedly until there is only one slime: * Choose two adjacent slimes, and combine them into a new slime. The new slime has a size of x + y, where x and y are the sizes of the slimes before combining them. Here, a cost of x + y is incurred. The positional relationship of the slimes does not change while combining slimes. Find the minimum possible total cost incurred. Constraints * All values in input are integers. * 2 \leq N \leq 400 * 1 \leq a_i \leq 10^9 Input Input is given from Standard Input in the following format: N a_1 a_2 \ldots a_N Output Print the minimum possible total cost incurred. Examples Input 4 10 20 30 40 Output 190 Input 5 10 10 10 10 10 Output 120 Input 3 1000000000 1000000000 1000000000 Output 5000000000 Input 6 7 6 8 6 1 1 Output 68
[ "\n", "# print(s)\n\n# print(c)\n", "for i in range(n):\n \n\n# print(s)\n\n# print(c)\n", "for i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "a = [int(x) for x in input().strip().split()]\n\n\nfor i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "a = [int(x) for x in input().strip().split()]\n\n\nfor i in range(n):\n \n\nfor i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "a = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\n\n\nfor i in range(n):\n \n\nfor i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\n\n\nfor i in range(n):\n \n\nfor i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n\nfor i in range(n):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n\nfor i in range(n):\n \n\ndef solve(i,j):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n \n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n \n \n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n \nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n \n \n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n \nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n \n \n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n \n \n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n \n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n \n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n \n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n \n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n mn = 10**100\n \n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n mn = 10**100\n for k in :\n \n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n mn = 10**100\n for k in range(i,j):\n \n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n \n mn = 10**100\n for k in range(i,j):\n mn = min(mn,solve(i,k)+solve(k+1,j)+s[i][k]+s[k+1][j])\n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if :\n return c[i][j]\n mn = 10**100\n for k in range(i,j):\n mn = min(mn,solve(i,k)+solve(k+1,j)+s[i][k]+s[k+1][j])\n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n", "n = int(input())\na = [int(x) for x in input().strip().split()]\n\nc = [[None for i in range(n)] for j in range(n)]\ns = [[0 for i in range(n)] for j in range(n)]\n\nfor i in range(n):\n c[i][i] = 0\n s[i][i] = a[i]\n\nfor i in range(n):\n for j in range(i+1,n):\n s[i][j] = s[i][j-1]+a[j]\n\ndef solve(i,j):\n if c[i][j] is not None:\n return c[i][j]\n mn = 10**100\n for k in range(i,j):\n mn = min(mn,solve(i,k)+solve(k+1,j)+s[i][k]+s[k+1][j])\n c[i][j] = mn\n return c[i][j]\n\n# print(s)\nprint(solve(0,n-1))\n# print(c)\n" ]
24
[ { "input": "6\n7 6 8 6 1 1", "output": "68" }, { "input": "5\n10 10 10 10 10", "output": "120" }, { "input": "3\n1000000000 1000000000 1000000000", "output": "5000000000" }, { "input": "4\n10 20 30 40", "output": "190" } ]
[ { "input": "6\n7 9 8 6 1 1", "output": "74\n" }, { "input": "5\n10 8 10 10 10", "output": "114\n" }, { "input": "3\n1001000000 1000000000 1000000000", "output": "5001000000\n" }, { "input": "4\n10 20 30 46", "output": "196\n" }, { "input": "6\n7 9 13 6 1 1", "output": "84\n" }, { "input": "5\n19 8 10 10 10", "output": "132\n" }, { "input": "3\n1001000000 1000000001 1000000000", "output": "5001000002\n" }, { "input": "4\n10 5 30 46", "output": "151\n" }, { "input": "6\n7 9 13 6 1 2", "output": "88\n" }, { "input": "5\n19 8 10 10 1", "output": "106\n" }, { "input": "3\n1001000000 1010000001 1000000000", "output": "5021000002\n" }, { "input": "4\n10 3 30 46", "output": "145\n" }, { "input": "6\n7 9 13 2 1 2", "output": "76\n" }, { "input": "5\n19 8 10 10 2", "output": "109\n" }, { "input": "3\n1001000000 1010000011 1000000000", "output": "5021000022\n" }, { "input": "4\n19 3 30 46", "output": "172\n" }, { "input": "5\n19 8 10 12 2", "output": "115\n" }, { "input": "3\n1001000010 1010000011 1000000000", "output": "5021000032\n" }, { "input": "4\n19 3 35 46", "output": "182\n" }, { "input": "5\n19 8 10 12 1", "output": "112\n" }, { "input": "3\n1001000010 1010010011 1000000000", "output": "5021020032\n" }, { "input": "4\n19 3 35 65", "output": "201\n" }, { "input": "6\n26 9 13 2 2 2", "output": "111\n" }, { "input": "5\n19 8 10 15 1", "output": "121\n" }, { "input": "3\n1001000011 1010010011 1000000000", "output": "5021020033\n" }, { "input": "4\n19 3 21 65", "output": "173\n" }, { "input": "6\n26 9 13 2 2 4", "output": "119\n" }, { "input": "5\n12 8 10 15 1", "output": "108\n" }, { "input": "3\n1001000011 1010110011 1000000000", "output": "5021220033\n" }, { "input": "4\n15 3 21 65", "output": "161\n" }, { "input": "3\n1001000011 1010110011 1001000000", "output": "5023220033\n" }, { "input": "4\n15 3 20 65", "output": "159\n" }, { "input": "6\n26 8 13 2 2 8", "output": "129\n" }, { "input": "5\n14 8 17 15 1", "output": "126\n" }, { "input": "3\n1001010011 1010110011 1001000000", "output": "5023230033\n" }, { "input": "4\n11 3 20 65", "output": "147\n" }, { "input": "6\n26 8 13 3 2 8", "output": "133\n" }, { "input": "5\n20 8 17 15 1", "output": "138\n" }, { "input": "3\n1001000011 1000110011 1001000000", "output": "5003220033\n" }, { "input": "6\n26 8 13 3 2 16", "output": "157\n" }, { "input": "5\n20 8 17 15 2", "output": "141\n" }, { "input": "3\n1001010011 1000110011 1001000000", "output": "5003230033\n" }, { "input": "4\n11 4 27 65", "output": "164\n" }, { "input": "5\n32 8 17 15 2", "output": "158\n" }, { "input": "3\n1001010011 1000110011 1001000001", "output": "5003230035\n" }, { "input": "4\n11 4 27 129", "output": "228\n" }, { "input": "5\n64 8 17 15 2", "output": "190\n" }, { "input": "3\n1001010011 1001110011 1001000001", "output": "5005230035\n" }, { "input": "4\n11 4 26 129", "output": "226\n" }, { "input": "5\n55 8 17 15 2", "output": "181\n" }, { "input": "3\n1001010010 1001110011 1001000001", "output": "5005230034\n" }, { "input": "4\n11 4 22 129", "output": "218\n" }, { "input": "6\n5 8 26 6 4 16", "output": "153\n" }, { "input": "3\n1001000010 1001110011 1001000001", "output": "5005220034\n" }, { "input": "4\n11 7 22 129", "output": "227\n" }, { "input": "3\n1001000010 1001110001 1001000001", "output": "5005220014\n" }, { "input": "6\n10 4 26 6 4 16", "output": "156\n" }, { "input": "5\n60 8 17 2 2", "output": "143\n" }, { "input": "3\n1001000010 1011110001 1001000001", "output": "5025220014\n" }, { "input": "4\n2 7 22 129", "output": "200\n" }, { "input": "5\n60 8 17 1 2", "output": "139\n" }, { "input": "3\n1011000010 1011110001 1001000001", "output": "5035220014\n" }, { "input": "4\n2 7 22 166", "output": "237\n" }, { "input": "6\n10 4 38 6 4 29", "output": "206\n" }, { "input": "5\n37 8 17 1 2", "output": "116\n" }, { "input": "3\n1011000011 1011110001 1001000001", "output": "5035220015\n" }, { "input": "4\n2 11 22 166", "output": "249\n" }, { "input": "3\n1011000001 1011110001 1001000001", "output": "5035220005\n" }, { "input": "4\n2 6 22 166", "output": "234\n" }, { "input": "5\n32 8 17 1 0", "output": "103\n" }, { "input": "3\n1011000001 1011110001 1001001001", "output": "5035222005\n" }, { "input": "4\n2 5 22 166", "output": "231\n" }, { "input": "6\n12 4 49 6 4 39", "output": "254\n" }, { "input": "5\n56 8 17 1 0", "output": "127\n" }, { "input": "3\n1011100001 1011110001 1001001001", "output": "5035322005\n" }, { "input": "4\n2 5 22 276", "output": "341\n" }, { "input": "6\n12 4 49 6 1 39", "output": "245\n" }, { "input": "5\n56 8 17 1 -1", "output": "123\n" }, { "input": "3\n1011100001 1011010001 1001001001", "output": "5035122005\n" }, { "input": "4\n2 6 22 276", "output": "344\n" }, { "input": "6\n12 4 64 6 1 39", "output": "275\n" }, { "input": "3\n1011100001 1001010001 1001001001", "output": "5015122005\n" }, { "input": "4\n2 1 22 276", "output": "329\n" }, { "input": "6\n12 1 64 6 1 39", "output": "266\n" }, { "input": "3\n1111100001 1001010001 1001001001", "output": "5115122005\n" }, { "input": "4\n2 1 24 276", "output": "333\n" }, { "input": "6\n12 0 64 6 1 39", "output": "263\n" }, { "input": "3\n1111100001 1001010000 1001001001", "output": "5115122003\n" }, { "input": "4\n2 0 24 276", "output": "330\n" }, { "input": "6\n12 0 64 6 0 39", "output": "260\n" }, { "input": "3\n1110100001 1001010000 1001001001", "output": "5114122003\n" }, { "input": "4\n0 0 24 276", "output": "324\n" }, { "input": "3\n1110100001 1001010010 1001001001", "output": "5114122023\n" }, { "input": "6\n4 1 64 6 0 39", "output": "239\n" }, { "input": "3\n1110100001 1001010010 1001001011", "output": "5114122043\n" }, { "input": "3\n1110100001 1000010010 1001001011", "output": "5112122043\n" }, { "input": "6\n4 1 64 11 0 49", "output": "274\n" }, { "input": "3\n1110000001 1000010010 1001001011", "output": "5112022043\n" }, { "input": "6\n4 2 64 11 0 49", "output": "277\n" }, { "input": "3\n1110000001 0000010010 1001001011", "output": "3112022043\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 = []\nfor _ in range(n):\n", "A = []\nfor _ in range(n):\n \n\nfor i in A:\n", "A = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\n\n\nfor i in A:\n", "def quick_sort:\n \n\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\n\n\nfor i in A:\n", "def quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\n\n\nfor i in A:\n", "def quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\n\nfor i in A:\n", "def partition:\n \n\ndef quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\n\nfor i in A:\n", "def partition:\n \n\ndef quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in :\n \n\nfor i in A:\n", "def partition:\n \n\ndef quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n \n\nfor i in A:\n", "def partition(A, p, r):\n \n\ndef quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n \n\nfor i in A:\n", "def partition(A, p, r):\n \n\ndef quick_sort:\n \nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n\nfor i in A:\n", "def partition(A, p, r):\n \n\ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n\nfor i in A:\n", "def partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\n\nfor i in A:\n", "def partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n", "def partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n", "def partition(A, p, r):\n \n \ndef quick_sort:\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n print(*i)\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 # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\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 q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \n \nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\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 q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n \n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\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 q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n print(*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 \n\ndef quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n \nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n print('Stable')\nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n print('Stable')\nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n print('Stable')\nfor i in A:\n print(*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 quick_sort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n # 左半分\n quick_sort(A, p, q - 1)\n # 右半分\n quick_sort(A, q + 1, r)\nn = int(input())\nA = []\nfor _ in range(n):\n a, b = input().split()\n A.append((a, int(b)))\nind = dict((e, i) for i, e in enumerate(A))\nquick_sort(A, 0, n - 1)\nfor i in range(n - 1):\n if A[i][1] == A[i + 1][1]:\n if ind[A[i]] > ind[A[i + 1]]:\n print('Not stable')\n break\nelse:\n print('Stable')\nfor i in A:\n print(*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", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\nA = list()\n\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\ndef check_stable(A):\n \n\nA = list()\n\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\n\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\nfor pos in range(n):\n \n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\n\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition:\n \n i = p-1\n \n \ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition(A, p, r):\n \n i = p-1\n \n \ndef quicksort:\n \n\ndef check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n \n\ndef partition(A, p, r):\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)\n\ndef check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\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)\n\ndef check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\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)\n\ndef check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\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 check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n \n i = p-1\n for n 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 check_stable(A):\n \n \n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n \n i = p-1\n for n 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 check_stable(A):\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n \n i = p-1\n for n 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 check_stable(A):\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n 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 check_stable(A):\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n \n \nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n 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 check_stable(A):\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n 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 check_stable(A):\n \n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n 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 check_stable(A):\n prev_val = None\n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in :\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 check_stable(A):\n prev_val = None\n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n \n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in :\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 check_stable(A):\n prev_val = None\n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in :\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n if :\n \n \n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n if :\n \n prev_val = card.val\n \n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n if :\n \n prev_val = card.val\n prev_pos = card.pos\n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n if card.val == prev_val:\n \n prev_val = card.val\n prev_pos = card.pos\n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\n", "#!/usr/bin/python3\n# -*- coding: utf-8 -*-\n\n# Aizu Online Judge. Quick Sort\nimport sys\n\nclass Card():\n def __init__(self, suit, val, pos):\n self.suit = suit\n self.val = val\n self.pos = pos\n\ndef partition(A, p, r):\n x = A[r].val\n i = p-1\n for n in range (p,r):\n if A[n].val <= x:\n i += 1\n A[i], A[n] = A[n], A[i]\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 check_stable(A):\n prev_val = None\n for card in A:\n if card.val == prev_val:\n if card.pos < prev_pos:\n print('Not stable')\n return\n prev_val = card.val\n prev_pos = card.pos\n\n print('Stable')\n return\n\n\nn = int(sys.stdin.readline())\nA = list()\nfor pos in range(n):\n suit, val_s = sys.stdin.readline().split()\n A.append(Card(suit, int(val_s), pos))\n\nquicksort(A, 0, n-1)\ncheck_stable(A)\nfor card in A:\n print(card.suit, card.val)\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", "import copy\n\n\ndef is_stable():\n \n\nA = []\n", "import copy\n\n\ndef is_stable():\n \n\nA = []\n\n\nquick_sort(0, N-1)\n", "import copy\n\n\ndef is_stable():\n \n\nA = []\n\n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "import copy\n\n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "import copy\n\ndef partition(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \n\nquick_sort(0, N-1)\n\nis_stable = is_stable()\n", "import copy\n\ndef partition(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \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 is_stable():\n \n\nA = []\nfor _ in range(N):\n \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:\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \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:\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \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:\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()\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:\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:\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:\n \n\ndef is_stable():\n idx = 0\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 i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef correct_same_num_suits:\n \n\ndef is_stable():\n idx = 0\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 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:\n \n\ndef is_stable():\n idx = 0\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 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:\n \n\ndef is_stable():\n idx = 0\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 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:\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 \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:\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 \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:\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, first):\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, first):\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 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 \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, first):\n \n \ndef is_stable():\n idx = 0\n \n return True\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 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 \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, first):\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\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 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 \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, first):\n \n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\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 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 \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, first):\n suits = []\n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\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 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 \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, first):\n suits = []\n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\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 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 \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, first):\n suits = []\n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \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 \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, first):\n suits = []\n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \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, first):\n suits = []\n for i in :\n \n \ndef is_stable():\n idx = 0\n while :\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \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, first):\n suits = []\n for i in :\n \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, first):\n suits = []\n for i in :\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, first):\n suits = []\n for i in :\n \n return suits\n\ndef is_stable():\n idx = 0\n while idx < 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 \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, first):\n suits = []\n for i in :\n \n return suits\n\ndef is_stable():\n idx = 0\n while idx < 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 \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, first):\n suits = []\n for i in range(first, N):\n \n return suits\n\ndef is_stable():\n idx = 0\n while idx < 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 \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, first):\n suits = []\n for i in range(first, N):\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 \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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][0])\n return suits\n\ndef is_stable():\n idx = 0\n while idx < N-1:\n \n if :\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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 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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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 idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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] == :\n \n \n idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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] == :\n \n \n if :\n \n idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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] == :\n \n sorted_suits = correct_same_num_suits(A, num, idx)\n \n if :\n \n idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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] == :\n \n sorted_suits = correct_same_num_suits(A, num, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\n if :\n \n idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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 \n sorted_suits = correct_same_num_suits(A, num, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\n if :\n \n idx += len(sorted_suits)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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 \n sorted_suits = correct_same_num_suits(A, num, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\n if sorted_suits != orig_suits:\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, first):\n suits = []\n for i in range(first, N):\n if num == l[i][1]:\n suits.append(l[i][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, idx)\n orig_suits = correct_same_num_suits(orig_list, num, 0)\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" ]
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", "def quick_sort:\n", "def partition:\n \n\ndef quick_sort:\n", "def partition:\n \n\ndef quick_sort:\n \n\nif :\n", "def partition:\n \n \ndef quick_sort:\n \n\nif :\n", "def partition:\n \n \ndef quick_sort(A, p, r, ):\n \n\nif :\n", "def partition:\n \n \ndef quick_sort(A, p, r, ):\n \n\nif __name__ == '__main__':\n", "def partition:\n \n \ndef quick_sort(A, p, r, ):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n", "def partition:\n \n \ndef quick_sort(A, p, r, ):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n 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, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n", "def partition(A, p, r, key=lambda x: x):\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, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n for in A:\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n for in A:\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\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 q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n \n A = []\n for _ in range(n):\n \n\n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n\n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n\n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n \n \n for in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n print('Stable')\n \n\n for in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\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, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n print('Stable')\n else:\n \n\n for in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\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 quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n print('Stable')\n else:\n \n\n for in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\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 quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n print('Stable')\n else:\n \n\n for egara, number in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\n for j in range(p, r):\n if key(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\n\ndef quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if :\n print('Stable')\n else:\n \n\n for egara, number in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\n for j in range(p, r):\n if key(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\n\ndef quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if stable_sorted == A:\n print('Stable')\n else:\n \n\n for egara, number in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\n for j in range(p, r):\n if key(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\n\ndef quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n \n \n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if stable_sorted == A:\n print('Stable')\n else:\n print('Not stable')\n\n for egara, number in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\n for j in range(p, r):\n if key(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\n\ndef quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n egara, number = input().split()\n \n\n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if stable_sorted == A:\n print('Stable')\n else:\n print('Not stable')\n\n for egara, number in A:\n print(egara, number)\n", "def partition(A, p, r, key=lambda x: x):\n x = key(A[r])\n i = p - 1\n\n for j in range(p, r):\n if key(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\n\ndef quick_sort(A, p, r, key=lambda x: x):\n if p < r:\n q = partition(A, p, r, key=key)\n quick_sort(A, p, q - 1, key=key)\n quick_sort(A, q + 1, r, key=key)\n\n\nif __name__ == '__main__':\n n = int(input())\n A = []\n for _ in range(n):\n egara, number = input().split()\n A.append((egara, int(number)))\n\n stable_sorted = sorted(A, key=lambda x: x[1])\n quick_sort(A, 0, n - 1, key=lambda x: x[1])\n\n if stable_sorted == A:\n print('Stable')\n else:\n print('Not stable')\n\n for egara, number in A:\n print(egara, number)\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", "card_list2 = sorted(card_list[:], key=lambda x:x[1])\n", "card_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\nquickSort(card_list, 0, len(card_list)-1)\n", "card_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n", "sys.setrecursionlimit(2000000000)\n\n\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n", "sys.setrecursionlimit(2000000000)\n\nN = int(input())\n\n\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n", "sys.setrecursionlimit(2000000000)\n\nN = int(input())\n\n\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n", "sys.setrecursionlimit(2000000000)\n\nN = int(input())\n\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\n\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n \nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n print('Stable')\nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n print('Stable')\nelse:\n \n\nfor item in card_list:\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif :\n print('Stable')\nelse:\n \n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n \n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n \n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n \n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n \n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n \n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n \n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in card_list:\n print(*item)\n", "import sys\nsys.setrecursionlimit(2000000000)\n\nN = int(input())\norigin_list = [input().split() for _ in range(N)]\ncard_list = origin_list[:]\ncard_list2 = sorted(card_list[:], key=lambda x:x[1])\n\ndef partition(A, p, r):\n x = int(A[r][1])\n i = p - 1\n\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\nquickSort(card_list, 0, len(card_list)-1)\n\n\nif card_list == card_list2:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in card_list:\n print(*item)\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\n\nB = A[:]\n", "A = []\n\n\nB = A[:]\n\n\nfor i in A:\n", "n = int(input())\nA = []\n\n\nB = A[:]\n\n\nfor i in A:\n", "n = int(input())\nA = []\n\n\nB = A[:]\n\n\nfor i in :\n \n\nfor i in A:\n", "def quickSort:\n \n\nn = int(input())\nA = []\n\n\nB = A[:]\n\n\nfor i in :\n \n\nfor i in A:\n", "def quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = A[:]\n\n\nfor i in :\n \n\nfor i in A:\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = A[:]\n\n\nfor i in :\n \n\nfor i in A:\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\n \n\nfor i in 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\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\n \n\nfor i in 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\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\n \n\nfor i in A:\n", "def partition:\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\n \n\nfor i in A:\n", "def partition:\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\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\n\n\nfor i in A:\n", "def partition:\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\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", "def partition:\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\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(*i)\n", "def partition(A, p, r):\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(A, 0, n - 1)\n\nfor i in :\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(*i)\n", "def partition(A, p, r):\n x = A[r]\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)\n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(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(*i)\n", "def 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\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(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(*i)\n", "def partition(A, p, r):\n x = 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\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = A[:]\n\nquickSort(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(*i)\n", "def partition(A, p, r):\n x = 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\nn = int(input())\nA = []\nfor i in range(n):\n x, y = input().split()\n \n\nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n x, y = input().split()\n \n\nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n x, y = input().split()\n \n\nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n x, y = input().split()\n A.append([x, int(y)])\n\nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n x, y = input().split()\n A.append([x, int(y)])\n\nB = A[:]\n\nquickSort(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(*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())\nA = []\nfor i in range(n):\n x, y = input().split()\n A.append([x, int(y)])\n\nB = A[:]\n\nquickSort(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(*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", "for i in a:\n", "def partition:\n \n\nfor i in a:\n", "def partition:\n \n\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "def partition:\n \n\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\n\n\ndef partition:\n \n\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\n\n\ndef partition:\n \n\na = [list(input().split()) for i in range(n)]\n\n\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\n\n\ndef partition:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\n\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\n\n\ndef partition:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\ndef quicksort:\n \n\ndef partition:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\ndef quicksort:\n \n\ndef partition:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef quicksort:\n \n\ndef partition:\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\n \nelse:\n \n\nfor i in a:\n", "import copy\ndef quicksort:\n \n\ndef partition:\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\n \nelse:\n \n\nfor i in a:\n", "import copy\ndef quicksort:\n \n\ndef partition:\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\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 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 partition:\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\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 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 partition(a, p, r):\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\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 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 partition(a, p, r):\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\n\nfor i in :\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 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 partition(a, p, r):\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 partition(a, p, r):\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n \nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 partition(a, p, r):\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 partition(a, p, r):\n x = a[r][1]\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 partition(a, p, r):\n x = a[r][1]\n \n \nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 partition(a, p, r):\n x = a[r][1]\n \n \n a[i + 1], a[r] = a[r], a[i + 1]\n \n\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 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\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 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\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 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\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 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\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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 quicksort(a, p, 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 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\nn = int(input())\na = [list(input().split()) for i in range(n)]\n\nfor i in range(n):\n a[i][1] = int(a[i][1])\nb = copy.deepcopy(a)\nquicksort(a, 0, n-1)\n\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" ]
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", "for i in lstB:\n", "for i in range(n):\n \n\nfor i in lstB:\n", "def quicksort:\n \n\nfor i in range(n):\n \n\nfor i in lstB:\n", "def quicksort:\n \n\nfor i in range(n):\n \n\nmergeSort(lstA, 0, n)\n\n\nfor i in lstB:\n", "def quicksort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nmergeSort(lstA, 0, n)\n\n\nfor i in lstB:\n", "def quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nmergeSort(lstA, 0, n)\n\n\nfor i in lstB:\n", "def quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\n\n\nfor i in lstB:\n", "def quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\n\n\nfor i in lstB:\n", "def quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\n\nfor i in lstB:\n", "import copy\n\n\ndef quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\n\nfor i in lstB:\n", "import copy\ndef partition:\n \n\ndef quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\n\nfor i in lstB:\n", "import copy\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\n\nfor i in lstB:\n", "import copy\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n \n\nfor i in lstB:\n", "import copy\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n print('Stable')\n\n\nfor i in lstB:\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n print('Stable')\n\n\nfor i in lstB:\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif :\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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(A, left, right):\n \n\nn = int(input())\nlstA = []\nfor i in range(n):\n \n \nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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(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())\nlstA = []\nfor i in range(n):\n \n \nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n \n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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(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())\nlstA = []\nfor i in range(n):\n \n \nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\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 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\nn = int(input())\nlstA = []\nfor i in range(n):\n \n \nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\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 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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n \n \nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\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 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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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\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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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\n\ndef merge(A, left, mid, right):\n \n \n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\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\n\ndef merge(A, left, mid, right):\n \n \n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\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\n\ndef merge(A, left, mid, right):\n \n \n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n \n\n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\n i = p - 1\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 merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n \n\n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n \n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\n i = p - 1\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 merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n \n\n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n \n\n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n R = A[mid:right] + [[10000000000, 'S']]\n\n i = 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())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n R = A[mid:right] + [[10000000000, 'S']]\n\n i = j = 0\n\n for k in :\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n\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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\n i = p - 1\n for j in :\n if A[j][0] <= 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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n R = A[mid:right] + [[10000000000, 'S']]\n\n i = j = 0\n\n for k in :\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n\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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\n i = p - 1\n for j in :\n if A[j][0] <= 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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n R = A[mid:right] + [[10000000000, 'S']]\n\n i = j = 0\n\n for k in range(left, right):\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n\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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\n", "import copy\ndef partition(A, p, r):\n x = A[r][0]\n i = 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\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\n\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[10000000000, 'S']]\n R = A[mid:right] + [[10000000000, 'S']]\n\n i = j = 0\n\n for k in range(left, right):\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n\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\nn = int(input())\nlstA = []\nfor i in range(n):\n C, N = input().split()\n k = [int(N), C]\n lstA.append(k)\n\nlstB = copy.copy(lstA)\nmergeSort(lstA, 0, n)\nquicksort(lstB, 0, n-1)\n\nif lstA == lstB:\n print('Stable')\n\nelse:\n print('Not stable')\n\nfor i in lstB:\n print(i[1], i[0])\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", "for line in data:\n", "print(check_stable(data))\n\nfor line in data:\n", "n = int(input())\n\n\nprint(check_stable(data))\n\nfor line in data:\n", "n = int(input())\n\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "n = int(input())\ndata = []\n\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def check_stable(A):\n \n\nn = int(input())\ndata = []\n\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def partition(A,p,r):\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def partition(A,p,r):\n \n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def partition(A,p,r):\n q = p\n \n\n return q\n\ndef quicksort:\n \n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def partition(A,p,r):\n q = p\n \n\n return q\n\ndef quicksort:\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n", "def partition(A,p,r):\n q = p\n \n\n return q\n\ndef quicksort:\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n\nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n \n\n return q\n\ndef quicksort:\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n \n\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n \n \nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n \n \nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n \n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in :\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n data += [[mark,int(num),i]]\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in range(p,r):\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n data += [[mark,int(num),i]]\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in range(p,r):\n \n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n if A[i-1][1] == A[i][1]:\n if A[i-1][2] > A[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n data += [[mark,int(num),i]]\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in range(p,r):\n if A[i][1] <= A[r][1]:\n A[q],A[i] = A[i],A[q]\n q += 1\n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in :\n if A[i-1][1] == A[i][1]:\n if A[i-1][2] > A[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n data += [[mark,int(num),i]]\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\n", "def partition(A,p,r):\n q = p\n for i in range(p,r):\n if A[i][1] <= A[r][1]:\n A[q],A[i] = A[i],A[q]\n q += 1\n\n A[q],A[r] = A[r],A[q]\n return q\n\ndef quicksort(A,left,right):\n if left < right:\n q = partition(A,left,right)\n quicksort(A,left,q-1)\n quicksort(A,q+1,right)\n\ndef check_stable(A):\n for i in range(1,len(A)):\n if A[i-1][1] == A[i][1]:\n if A[i-1][2] > A[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\ndata = []\nfor i in range(n):\n mark, num = map(str,input().split())\n data += [[mark,int(num),i]]\n\nquicksort(data,0,len(data) -1)\nprint(check_stable(data))\n\nfor line in data:\n print(line[0],line[1])\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\ndef Quick(A,p,r):\n", "a=[]\n\n\ndef Quick(A,p,r):\n \n\nfor i in range(n):\n", "a=[]\n\n\ndef Quick(A,p,r):\n \n\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "a=[]\n\n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "a=[]\n\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "a=[]\nfor i in range(n):\n \n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \n\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \n\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef MergeSort:\n \nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n \n\ndef Merge:\n \n\ndef MergeSort:\n \nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge:\n \n\ndef MergeSort:\n \nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n\ndef MergeSort:\n \nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n", "n=int(input())\na=[]\nfor i in range(n):\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(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 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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n \n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n for j in :\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n \nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n \n i=p-1\n for j in :\n \n \ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n \nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n \nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n \n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n \n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n \n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=p-1\n for j in :\n if A[j][0]<=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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=p-1\n for j in :\n if A[j][0]<=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(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n \n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in :\n L[i] = A[left + i]\n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in range(n1):\n L[i] = A[left + i]\n for i in :\n \n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in range(n1):\n L[i] = A[left + i]\n for i in :\n R[i] = A[mid + i]\n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in range(n1):\n L[i] = A[left + i]\n for i in range(n2):\n R[i] = A[mid + i]\n L[n1][0] = 10**10\n R[n2][0] = 10**10\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\n", "n=int(input())\na=[]\nfor i in range(n):\n x,y=input().split()\n a.append([int(y),x])\nfrom copy import copy\nb=copy(a)\n\ndef partition(A,p,r):\n x=A[r][0]\n i=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 A[i+1],A[r]=A[r],A[i+1]\n return i+1\n\ndef Quick(A,p,r):\n if p<r:\n q=partition(A,p,r)\n Quick(A,p,q-1)\n Quick(A,q+1,r)\n\ndef Merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L=[[0,\"ST\"]for _ in range(n1+1)]\n R=[[0,\"ST\"]for _ in range(n2+1)]\n for i in range(n1):\n L[i] = A[left + i]\n for i in range(n2):\n R[i] = A[mid + i]\n L[n1][0] = 10**10\n R[n2][0] = 10**10\n i = 0\n j = 0\n for k in range(left,right):\n if L[i][0] <= R[j][0]:\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)\nMergeSort(a,0,n)\nQuick(b,0,n-1)\nprint(\"Stable\" if a==b else \"Not stable\")\nfor i in range(n):\n print(b[i][1],b[i][0])\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", "for item in a:\n", "quickSort(a, 0, n-1)\n\n\nfor item in a:\n", "quickSort(a, 0, n-1)\n\n\nif stable:\n \n\nfor item in a:\n", "def partition:\n \n\nquickSort(a, 0, n-1)\n\n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\ndef partition:\n \n\nquickSort(a, 0, n-1)\n\n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\ndef partition:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\n\n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\ndef partition:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\nclass card:\n \n\ndef partition:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\nclass card:\n \n\nfor i in range(n):\n \n\ndef partition:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "a = [0]*n\n\n\nclass card:\n \n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n \n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n \n\nif stable:\n \n\nfor item in a:\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n \n\nfor item in a:\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\n\n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\n\n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\n\n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n \n\ndef quickSort(A, p, r):\n \n\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in :\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\n i = p-1\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\n i = p-1\n for j in :\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n \n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\n i = p-1\n for j in :\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\nquickSort(a, 0, n-1)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\n i = p-1\n for j in :\n if A[j].num <= 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\n return i+1\n\ndef quickSort(A, p, 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)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in a:\n print(item.t)\n", "n = int(input())\na = [0]*n\n\n\nclass card:\n def __init__(self, s, input_idx):\n self.m = s.split()[0]\n self.num = int(s.split()[1])\n self.t = s\n self.input_idx = input_idx\n\nfor i in range(n):\n a[i] = card(input(), i)\n\ndef partition(A, p, r):\n x = A[r].num\n i = p-1\n for j in range(p,r):\n if A[j].num <= 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\n return i+1\n\ndef quickSort(A, p, 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)\n\nstable = True\nfor i in range(1, n):\n if a[i].num==a[i-1].num and a[i].input_idx<a[i-1].input_idx:\n stable = False\n\nif stable:\n print('Stable')\nelse:\n print('Not stable')\n\nfor item in a:\n print(item.t)\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\nfor card in A:\n", "A = []\n\norig_list = copy.copy(A)\n\n\nfor card in A:\n", "def is_stable():\n \n\nA = []\n\norig_list = copy.copy(A)\n\n\nfor card in A:\n", "def is_stable():\n \n\nN = int(input())\nA = []\n\norig_list = copy.copy(A)\n\n\nfor card in A:\n", "def is_stable():\n \n\nN = int(input())\nA = []\n\norig_list = copy.copy(A)\n\nquick_sort(0, N-1)\n\n\nfor card in A:\n", "import copy\n\n\ndef is_stable():\n \n\nN = int(input())\nA = []\n\norig_list = copy.copy(A)\n\nquick_sort(0, N-1)\n\n\nfor card in A:\n", "import copy\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\n\norig_list = copy.copy(A)\n\nquick_sort(0, N-1)\n\n\nfor card in A:\n", "import copy\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable():\n \n\nN = int(input())\nA = []\n\norig_list = copy.copy(A)\n\nquick_sort(0, N-1)\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 = []\n\norig_list = copy.copy(A)\n\nquick_sort(0, N-1)\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.copy(A)\n\nquick_sort(0, N-1)\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.copy(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 i = p\n \n \n return i\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.copy(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 i = p\n \n \n return i\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.copy(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 \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \norig_list = copy.copy(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 \n \norig_list = copy.copy(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 \n \norig_list = copy.copy(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 \n \norig_list = copy.copy(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 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 \norig_list = copy.copy(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 \n A.append([suit, num])\norig_list = copy.copy(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 return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \n A.append([suit, num])\norig_list = copy.copy(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 is_stable():\n \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \n A.append([suit, num])\norig_list = copy.copy(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 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 \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \n A.append([suit, num])\norig_list = copy.copy(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 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 \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \n A.append([suit, num])\norig_list = copy.copy(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 \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 = copy.copy(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 \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.copy(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.copy(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 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.copy(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 range(N-1):\n if A[i][1] == A[i+1][1]:\n small_idx, large_idx = 0, 0\n for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n elif A[i+1] == orig_list[j]:\n large_idx = j\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.copy(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 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 for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n elif A[i+1] == orig_list[j]:\n large_idx = j\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.copy(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 for j in range(N):\n if A[i] == orig_list[j]:\n small_idx = j\n elif A[i+1] == orig_list[j]:\n large_idx = j\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.copy(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", "## Quick Sort\n", "## Quick Sort\n\n\ndef merge_sort:\n", "## Quick Sort\n\n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\n", "## Quick Sort\n\n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n", "## Quick Sort\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n", "## Quick Sort\n\nimport copy\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n\n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n\n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\n\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\n\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\n\nINF = 10**9 + 1\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \n\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\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\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\ndef partition:\n \n \ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n \nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif :\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\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\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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n # 番兵\n \n # 番兵\n i, j = 0, 0\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\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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n \n \n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\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\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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\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\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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\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\ndef partition(A, p, r):\n x = int(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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\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\ndef partition(A, p, r):\n x = int(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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n \n # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n \n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n L.append((\"\", INF)) # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n L.append((\"\", INF)) # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 += 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\nquick_sort(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n L.append((\"\", INF)) # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in :\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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n L.append((\"\", INF)) # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in range(left, 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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\n", "## Quick Sort\n\nimport copy\n\nN = int(input())\nlst1 = [list(input().split()) for i in range(N)]\nlst2 = copy.copy(lst1)\nINF = 10**9 + 1\n\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:mid]\n L.append((\"\", INF)) # 番兵\n R = A[mid:right]\n R.append((\"\", INF)) # 番兵\n i, j = 0, 0\n for k in range(left, right):\n if (int(L[i][1]) <= int(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 (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\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 quick_sort(A, p, r):\n 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(lst1, 0, N-1)\nmerge_sort(lst2, 0, N)\nans = 'Stable'\nif (lst1 != lst2):\n ans = 'Not stable'\nprint(ans)\nfor i in lst1:\n print(*i)\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", "# 関数定義\n\n\n# 入力\n\nA = []\n\n\n# ソート\n\n\n# is_stable()\n\n\n# 中身\n", "# 関数定義\n\n\ndef quickSort:\n \n\n# 入力\n\nA = []\n\n\n# ソート\n\n\n# is_stable()\n\n\n# 中身\n", "# 関数定義\n\n\ndef quickSort:\n \n\n# 入力\n\nA = []\n\n\n# ソート\n\n\n# is_stable()\n\n\n# 中身\nfor a in A :\n", "# 関数定義\n\n\ndef quickSort:\n \n\n# 入力\n\nA = []\n\n\n# ソート\n\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\n\n\ndef quickSort:\n \n\n# 入力\n\nA = []\nfor i in range(N):\n \n\n# ソート\n\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\n\n\ndef quickSort:\n \n\ndef is_stable(A):\n \n\n# 入力\n\nA = []\nfor i in range(N):\n \n\n# ソート\n\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\n\n\ndef quickSort:\n \n\ndef is_stable(A):\n \n\n# 入力\n\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\n\n\ndef quickSort:\n \n\ndef is_stable(A):\n \n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\ndef partition:\n \n\ndef quickSort:\n \n\ndef is_stable(A):\n \n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\ndef partition:\n \n\ndef quickSort:\n \n\ndef is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n", "# 関数定義\ndef partition:\n \n\ndef quickSort:\n \n\ndef is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\ndef is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n \n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\ndef is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif:\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n \n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\n\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"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 is_stable(A):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n \n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n \n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n \n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n \n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n \n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n for i in :\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n for i in :\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n \n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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):\n for i in :\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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 return i + 1\n\ndef quickSort(A, p, 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):\n for i in :\n \n \n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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 return i + 1\n\ndef quickSort(A, p, 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):\n for i in :\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\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 is_stable(A):\n for i in :\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\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 is_stable(A):\n for i in :\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\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 is_stable(A):\n for i in range(0, len(A) - 1):\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\n for j in :\n if A[j][\"number\"] <= 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 is_stable(A):\n for i in range(0, len(A) - 1):\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n \n #print(A[i][\"number\"], A[j][\"number\"], \":\", A[i][\"order\"], A[j][\"order\"])\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n j = i + 1\n #print(A[i][\"number\"], A[j][\"number\"], \":\", A[i][\"order\"], A[j][\"order\"])\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n j = i + 1\n #print(A[i][\"number\"], A[j][\"number\"], \":\", A[i][\"order\"], A[j][\"order\"])\n if :\n \n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n j = i + 1\n #print(A[i][\"number\"], A[j][\"number\"], \":\", A[i][\"order\"], A[j][\"order\"])\n if :\n return False\n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\n", "# 関数定義\ndef partition(A, p, r):\n x = A[r][\"number\"]\n i = p - 1\n\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\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 is_stable(A):\n for i in range(0, len(A) - 1):\n j = i + 1\n #print(A[i][\"number\"], A[j][\"number\"], \":\", A[i][\"order\"], A[j][\"order\"])\n if (A[i][\"number\"] == A[j][\"number\"] and A[i][\"order\"] > A[j][\"order\"]):\n return False\n return True\n\n# 入力\nN = int(input())\nA = []\nfor i in range(N):\n card = input().split()\n A.append({'mark': card[0], 'number': int(card[1]), 'order': i})\n\n# ソート\nquickSort(A,0,N-1)\n\n# is_stable()\nif(is_stable(A)):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\n# 中身\nfor a in A :\n print(a[\"mark\"], a[\"number\"])\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", "def qsort(A,p,r):\n", "def partition:\n \n\ndef qsort(A,p,r):\n", "def partition:\n \n\ndef qsort(A,p,r):\n \n\ndef isStable(a):\n", "def partition:\n \n\ndef qsort(A,p,r):\n \n\ndef isStable(a):\n \n\nif :\n", "def partition(A, p, r):\n \n\ndef qsort(A,p,r):\n \n\ndef isStable(a):\n \n\nif :\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n\ndef isStable(a):\n \n\nif :\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n\ndef isStable(a):\n \n \nif :\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n \n A = []\n \n p = 0\n", "def partition(A, p, r):\n \n i = p-1\n\n \ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n \n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n \n i = p-1\n\n \n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n \n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n \n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n \n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n \n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n \n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in :\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in :\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n \n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in :\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n \n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in :\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in :\n \n A[i+1],A[r-1] = A[r-1],A[i+1]\n return i + 1\n\ndef qsort(A,p,r):\n if p < r:\n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in :\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in :\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n \n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n print(\"Stable\")\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n \n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n print(\"Stable\")\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if :\n print(\"Stable\")\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n \n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n \n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n \n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n \n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n \n qsort(A,p,q)\n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n qsort(A,p,q)\n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n \n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n qsort(A,p,q)\n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n \n N.append(i)\n A.append(N)\n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\n", "def partition(A, p, r):\n x = int(A[r-1][1])\n i = p-1\n\n for j in range(p,r-1):\n if int(A[j][1]) <= x:\n i = 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\ndef qsort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n qsort(A,p,q)\n qsort(A,q+1,r)\n return A\n\ndef isStable(a):\n length = int(len(a))\n for i in range(length):\n for j in range(i+1,length-1) :\n if a[i][1] == a[j][1] and a[i][2] > a[j][2]:\n return False\n break\n return True\n\nif __name__ == '__main__':\n cnt = int(input())\n A = []\n for i in range(cnt):\n N = input().split()\n N.append(i)\n A.append(N)\n p = 0\n r = len(A)\n B = qsort(A,p,r)\n if isStable(B):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in B:\n print (\"{0} {1}\".format(i[0],i[1]))\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", "def main():\n", "def main():\n \n\nif :\n main()\n", "def check(a):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition(a,p,r)->int:\n \n\ndef check(a):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition(a,p,r)->int:\n \n\ndef quick_sort(a,l,r):\n \n\ndef check(a):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n \n\ndef check(a):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n\ndef main():\n \n\nif :\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n\ndef main():\n \n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n a = []\n \n \nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n a = []\n \n \n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n \n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n a = []\n \n \n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n x = a[r][1]\n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n a = []\n \n \n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n x = a[r][1]\n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n \n a = []\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n x = a[r][1]\n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n \ndef main():\n n = int(input())\n a = []\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n x = a[r][1]\n i = p-1\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\n x = a[r][1]\n i = p-1\n for j in :\n \n \ndef quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in :\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in :\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in :\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in :\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in :\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while :\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n \n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while :\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n \n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while :\n \n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while :\n \n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while j<len(a) and :\n \n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while j<len(a) and :\n if :\n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while j<len(a) and a[i][1]==a[j][1]:\n if :\n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while j<len(a) and a[i][1]==a[j][1]:\n if :return 'Not stable'\n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\n", "def partition(a,p,r)->int:\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 quick_sort(a,l,r):\n if l<r:\n q = partition(a,l,r)\n quick_sort(a,l,q-1)\n quick_sort(a,q+1,r)\n\ndef check(a):\n for i in range(len(a)):\n j = i+1\n while j<len(a) and a[i][1]==a[j][1]:\n if a[j][2]<a[i][2]:return 'Not stable'\n j+=1\n return 'Stable'\n\ndef main():\n n = int(input())\n a = []\n for i in range(n):\n b,c = input().split()\n a.append([b,int(c),i])\n quick_sort(a,0,n-1)\n print (check(a))\n for b,c,_ in a:print (b,c)\n\nif __name__ == '__main__':\n main()\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=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "f=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "import sys\n\n\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "import sys\n\ndef k(A,p,r):\n \n\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \n\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n\nprint(['Not s','S'][s(A)]+'table')\n", "import sys\n\ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\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,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\n\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\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,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e 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())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e 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 return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e 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 return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e 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 return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:print(*e[:2])\n", "import sys\ndef t(A,p,r):\n x=A[r][1];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 return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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]:\n if A[i][2]>A[i+1][2]:return 0\n return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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]:\n if A[i][2]>A[i+1][2]:return 0\n return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 0\n return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 0\n return 1\nn=int(input())\nf=lambda x,i:(x[0],int(x[1]),i)\nA=[f(sys.stdin.readline().split(),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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", "B = A[:]\n", "n = int(input())\n\n\nB = A[:]\n", "def merge:\n \n\nn = int(input())\n\n\nB = A[:]\n", "readline = sys.stdin.readline\n\ndef merge:\n \n\nn = int(input())\n\n\nB = A[:]\n", "readline = sys.stdin.readline\n\ndef merge:\n \n\nn = int(input())\n\n\nB = A[:]\n\nquicksort(B, 0, n - 1)\n", "readline = sys.stdin.readline\n\ndef merge:\n \n\nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n", "readline = sys.stdin.readline\n\ndef merge:\n \n\nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "readline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "readline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\ndef quicksort:\n \nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\ndef quicksort:\n \nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\ndef partition:\n \ndef quicksort:\n \nn = int(input())\n\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \n\ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\n\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\n \ndef mergeSort(A, left, right):\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\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)\ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\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)\ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\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)\ndef partition(A, p, r):\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge:\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)\ndef partition(A, p, r):\n \ndef quicksort(A, p, r):\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\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)\ndef partition(A, p, r):\n \ndef quicksort(A, p, r):\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\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)\ndef partition(A, p, r):\n \n \ndef quicksort(A, p, r):\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n \n \n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n \n \n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\ndef partition(A, p, r):\n x = A[r][1]\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in :\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 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\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 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\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "import sys\nreadline = sys.stdin.readline\nINF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 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\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\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", "print(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "A = [f(readline().split(), i) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "def isStable(A):\n \n\nA = [f(readline().split(), i) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "def isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "readline = sys.stdin.readline\n\n\ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "readline = sys.stdin.readline\n\n\ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(isStable(A))\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "readline = sys.stdin.readline\n\ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\n\nA = [f(readline().split(), i) for i in range(n)]\n\nprint(isStable(A))\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "readline = sys.stdin.readline\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(isStable(A))\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "readline = 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)]\n\nprint(isStable(A))\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)]\n\nprint(isStable(A))\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(isStable(A))\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 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(isStable(A))\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 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(isStable(A))\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 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(isStable(A))\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 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(isStable(A))\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(isStable(A))\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 \n \ndef quicksort(A, 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(isStable(A))\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 \n \ndef quicksort(A, 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 \"Stable\"\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(isStable(A))\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 \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 isStable(A):\n \n return \"Stable\"\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(isStable(A))\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 \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 isStable(A):\n for i in :\n \n return \"Stable\"\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(isStable(A))\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 \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 \"Stable\"\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(isStable(A))\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 \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 \"Stable\"\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(isStable(A))\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 \"Stable\"\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(isStable(A))\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 \"Not stable\"\n return \"Stable\"\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(isStable(A))\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 \"Not stable\"\n return \"Stable\"\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(isStable(A))\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 \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 \"Not stable\"\n return \"Stable\"\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(isStable(A))\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 \"Not stable\"\n return \"Stable\"\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(isStable(A))\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", "A = []\n", "A = []\n\n\nif A == B:\n", "A = []\n\nfor i in range(n):\n \n\nif A == B:\n", "A = []\n\nfor i in range(n):\n \n\nB = [i for i in A]\n\n\nif A == B:\n", "A = []\n\nfor i in range(n):\n \n\nB = [i for i in A]\n\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n", "A = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\n\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n", "A = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n", "def quicksort(A,p,r):\n \nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n", "def quicksort(A,p,r):\n \nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \n\nfor i in A:\n", "from operator import \n\n\ndef quicksort(A,p,r):\n \nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \n\nfor i in A:\n", "from operator import \ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \n\nfor i in A:\n", "from operator import \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)\nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \n\nfor i in A:\n", "from operator import \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)\nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \nelse:\n \nfor i in A:\n", "from operator import \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)\nA = []\nn = int(input())\nfor i in range(n):\n \n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import \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)\nA = []\nn = int(input())\nfor i in range(n):\n \n \nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n \n \nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n \n \nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n \nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n \n \nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n \n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\ndef 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)\nA = []\nn = int(input())\nfor i in range(n):\n \n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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 \n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nA = []\nn = int(input())\nfor i in range(n):\n \n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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 \n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n \nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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\n\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(i[0],i[1])\n", "from operator import itemgetter\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)\nA = []\nn = int(input())\nfor i in range(n):\n a,b = map(str,input().split())\n A.append([a,int(b)])\n\nB = [i for i in A]\nquicksort(A,0,n-1)\n\nB.sort(key=itemgetter(1))\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in A:\n print(i[0],i[1])\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\n\nB = A[:]\n", "def quick_sort:\n \n\nA = []\n\n\nB = A[:]\n", "def quick_sort:\n \n\nA = []\n\n\nB = A[:]\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\n", "def quick_sort:\n \n\ndef is_stable(A, B):\n \n\nA = []\n\n\nB = A[:]\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\n", "def quick_sort:\n \n\ndef is_stable(A, B):\n \n\nA = []\n\n\nB = A[:]\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A:\n", "def quick_sort:\n \n\ndef is_stable(A, B):\n \n\nA = []\nfor i in range(N):\n \n\nB = A[:]\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A:\n", "def quick_sort:\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\n\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A:\n", "def quick_sort:\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A:\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A: print(\"{} {}\".format(suit, num))\n", "def partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor in A: print(\"{} {}\".format(suit, num))\n", "def partition:\n \n\ndef quick_sort(A, p, r):\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition:\n \n \ndef quick_sort(A, p, r):\n \n\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def 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\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def 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\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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\ndef is_stable(A, B):\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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\ndef is_stable(A, B):\n ma = {}\n \n\n mb = {}\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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\ndef is_stable(A, B):\n ma = {}\n \n\n mb = {}\n \n\n for num in ma:\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\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 is_stable(A, B):\n ma = {}\n \n\n mb = {}\n \n\n for num in ma:\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\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 is_stable(A, B):\n ma = {}\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\n \n \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\ndef is_stable(A, B):\n ma = {}\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\n \n \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\ndef is_stable(A, B):\n ma = {}\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\n \n \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\ndef is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n \n \nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def partition(A, p, r):\n \n \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\ndef is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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\ndef quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\n", "def 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 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 is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n \n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n\n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for in B:\n \n\n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for in B:\n \n \n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for suit, num in B:\n \n \n for num in ma:\n \n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for suit, num in B:\n \n \n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for suit, num in B:\n \n \n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for in A:\n \n \n mb = {}\n for suit, num in B:\n \n \n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n \n \n mb = {}\n for suit, num in B:\n \n \n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n \n \n mb = {}\n for suit, num in B:\n if : \n \n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n \n \n mb = {}\n for suit, num in B:\n if : \n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if : \n \n\n mb = {}\n for suit, num in B:\n if : \n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if : \n ma[num].append(suit)\n\n mb = {}\n for suit, num in B:\n if : \n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if : \n ma[num].append(suit)\n\n mb = {}\n for suit, num in B:\n if num not in mb: \n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if num not in ma: \n ma[num].append(suit)\n\n mb = {}\n for suit, num in B:\n if num not in mb: \n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if num not in ma: \n ma[num].append(suit)\n\n mb = {}\n for suit, num in B:\n if num not in mb: mb[num] = []\n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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 quick_sort(A, p, r):\n 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 is_stable(A, B):\n ma = {}\n for suit, num in A:\n if num not in ma: ma[num] = []\n ma[num].append(suit)\n\n mb = {}\n for suit, num in B:\n if num not in mb: mb[num] = []\n mb[num].append(suit)\n\n for num in ma:\n if ma[num] != mb[num]: return False\n\n return True\n\nN = int(input())\nA = []\nfor i in range(N):\n suit, num = input().split()\n A.append([suit, int(num)])\n\nB = A[:]\nquick_sort(A, 0, len(A) - 1)\nprint(\"Stable\" if is_stable(A, B) else \"Not stable\")\nfor suit, num in A: print(\"{} {}\".format(suit, num))\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", "def partition:\n", "class Num:\n \n\ndef partition:\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort:\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort:\n \n\nif :\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort:\n \ndef isStable(A):\n \n\nif :\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort:\n \ndef isStable(A):\n \n n=len(A)\n \n \nif :\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort:\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n", "class Num:\n \n\ndef partition:\n \ndef quick_sort(A , p, r):\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n", "class Num:\n \n\ndef partition:\n x=A[r].b\n i=p-1\n \n \ndef quick_sort(A , p, r):\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition:\n x=A[r].b\n i=p-1\n \n \ndef quick_sort(A , p, r):\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition:\n x=A[r].b\n i=p-1\n \n \ndef quick_sort(A , p, r):\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n \ndef quick_sort(A , p, r):\n \ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\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)\ndef isStable(A):\n \n n=len(A)\n \n \nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\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)\ndef isStable(A):\n \n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n \n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n \ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n \n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n \n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n \ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n \n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n \ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n \n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n \n \n if :\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n \n A=[]\n for i in range(n):\n \n \n if :\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n if :\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n if :\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n \n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n if :\n \n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n \n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n if :\n \n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n \n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n quick_sort(A,0,n-1)\n if :\n \n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n quick_sort(A,0,n-1)\n if :\n \n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n quick_sort(A,0,n-1)\n if :\n print(\"Stable\")\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n quick_sort(A,0,n-1)\n if :\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in :\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in :\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n \n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n a=input().split()\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n a=input().split()\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n \n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n a=input().split()\n \n num.b = int(a[1])\n \n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n \n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n a=input().split()\n \n num.b = int(a[1])\n num.origin=i\n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n \n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n \n a=input().split()\n \n num.b = int(a[1])\n num.origin=i\n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n print(i.a,end=\" \")\n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n num =Num()\n a=input().split()\n \n num.b = int(a[1])\n num.origin=i\n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n \n for i in A:\n print(i.a,end=\" \")\n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n num =Num()\n a=input().split()\n \n num.b = int(a[1])\n num.origin=i\n \n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in A:\n print(i.a,end=\" \")\n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n num =Num()\n a=input().split()\n \n num.b = int(a[1])\n num.origin=i\n A.append(num)\n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in A:\n print(i.a,end=\" \")\n print(i.b)\n", "class Num:\n a=0\n b=0\n origin=0\n\ndef partition(A, p, r):\n x=A[r].b\n i=p-1\n for j in range(p,r):\n if A[j].b <= x:\n i += 1\n A[i].b,A[j].b = A[j].b,A[i].b\n A[i].a,A[j].a = A[j].a,A[i].a\n A[i].origin,A[j].origin = A[j].origin,A[i].origin\n A[i+1].b,A[r].b = A[r].b,A[i+1].b\n A[i+1].a,A[r].a = A[r].a,A[i+1].a\n A[i+1].origin,A[r].origin = A[r].origin,A[i+1].origin\n return i+1\ndef quick_sort(A , p, r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A, p, q-1)\n quick_sort(A, q+1, r)\ndef isStable(A):\n flag=True\n n=len(A)\n for i in range(n-1):\n if A[i].b == A[i+1].b and A[i].origin > A[i+1].origin:\n flag = False\n return flag\n\nif __name__ == \"__main__\":\n\n n=int(input())\n A=[]\n for i in range(n):\n num =Num()\n a=input().split()\n num.a = a[0]\n num.b = int(a[1])\n num.origin=i\n A.append(num)\n quick_sort(A,0,n-1)\n if isStable(A):\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in A:\n print(i.a,end=\" \")\n print(i.b)\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", "B = copy.deepcopy(A)\n", "n = int(input())\n\n\nB = copy.deepcopy(A)\n", "n = int(input())\n\n\nB = copy.deepcopy(A)\n\n\nprint(ans)\n", "n = int(input())\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n \n\nprint(ans)\n", "def mergeSort:\n \n\nn = int(input())\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n \n\nprint(ans)\n", "def mergeSort:\n \n\nn = int(input())\nA = [None for i in range(n)]\n\n\nB = copy.deepcopy(A)\n\n\nif A == B:\n \n\nprint(ans)\n", "def mergeSort:\n \n\nn = int(input())\nA = [None for i in range(n)]\n\n\nB = copy.deepcopy(A)\nquickSort(A, 0, n-1)\n\nif A == B:\n \n\nprint(ans)\n", "def mergeSort:\n \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)\n\nif A == B:\n \n\nprint(ans)\n", "def merge:\n \n\ndef mergeSort:\n \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)\n\nif A == B:\n \n\nprint(ans)\n", "def merge:\n \n\ndef mergeSort:\n \n\ndef quickSort:\n \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)\n\nif A == B:\n \n\nprint(ans)\n", "def merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \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)\n\nif A == B:\n \n\nprint(ans)\n", "INF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \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)\n\nif A == B:\n \n\nprint(ans)\n", "INF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \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\nprint(ans)\n", "INF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \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]\n\nprint(ans)\n", "INF = 10000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \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 \n\ndef partition:\n \n\ndef quickSort:\n \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 \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n \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 \n\ndef partition:\n \n\ndef quickSort(A, p, r):\n \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 \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 \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\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 \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(A, left, right):\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\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 \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(A, left, right):\n \n return 0\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\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 \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(A, left, right):\n \n return 0\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\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 \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(A, left, right):\n \n return 0\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\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 \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(A, left, right):\n \n return 0\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())\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 \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(A, left, right):\n \n return 0\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())\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 \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\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())\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 \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\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())\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 \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\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\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 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\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\n\ndef partition(A, p, r):\n \n \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\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 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\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\n\ndef partition(A, p, r):\n \n \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\n\nn = int(input())\nA = [None for i 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)\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\ndef merge(A, left, mid, right):\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\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\n\nn = int(input())\nA = [None for i 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)\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\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n \ndef mergeSort(A, left, right):\n \n return 0\n\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\n\nn = int(input())\nA = [None for i 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)\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\ndef merge(A, left, mid, right):\n \n \n for k in :\n \n return count\n\ndef mergeSort(A, left, right):\n \n return 0\n\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\n\nn = int(input())\nA = [None for i 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)\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\ndef merge(A, left, mid, right):\n \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\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\n\nn = int(input())\nA = [None for i 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)\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\ndef merge(A, left, mid, right):\n \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\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\n\nn = int(input())\nA = [None for i 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)\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\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\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\n\nn = int(input())\nA = [None for i 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)\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\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\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\n\nn = int(input())\nA = [None for i 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)\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\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\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\n\nn = int(input())\nA = [None for i 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)\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\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\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\n\nn = int(input())\nA = [None for i 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)\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\n\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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 countR = mergeSort(A, mid, right)\n \n return 0\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 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\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))\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\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 \n return 0\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 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\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))\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\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\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\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))\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\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 \n countR = mergeSort(A, mid, right)\n return merge(A, left, mid, right) + countL + countR\n return 0\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 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\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))\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\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\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\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))\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\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\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\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))\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\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\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 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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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\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))\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\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\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 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\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))\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" ]
64
[ { "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(0,N-1)\n", "table = []\n\n\nquickSort(0,N-1)\n", "table = []\n\n\nquickSort(0,N-1)\n\n\nfor i in :\n", "table = []\n\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n", "table = []\nfor input_index in range(N):\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n", "table = []\nfor input_index in range(N):\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n", "table = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n", "N = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n", "N = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n \n\nif stable_FLG:\n", "N = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n \n\nif stable_FLG:\n \n\nfor i in range(N):\n", "class TRAMP:\n \n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n \n\nif stable_FLG:\n \n\nfor i in range(N):\n", "class TRAMP:\n \n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n \n\nfor i in range(N):\n", "class TRAMP:\n \n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n\ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in :\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition:\n \n\ndef quickSort:\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition:\n \n\ndef quickSort(left,right):\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition:\n \n\ndef quickSort(left,right):\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n\ndef quickSort(left,right):\n \n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\n\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n i = left-1\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n \n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n \n \ndef Partition(left,right):\n \n i = left-1\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n \n\ndef Partition(left,right):\n \n i = left-1\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n \n\ndef Partition(left,right):\n \n i = left-1\n pivot = table[right].number\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n \n i = left-1\n pivot = table[right].number\n \n \ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n \n i = left-1\n pivot = table[right].number\n \n \n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n \n i = left-1\n pivot = table[right].number\n for start in :\n \n \n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n global table\n i = left-1\n pivot = table[right].number\n for start in :\n \n \n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n global table\n i = left-1\n pivot = table[right].number\n for start in :\n \n table[i+1],table[right] = table[right],table[i+1]\n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n global table\n i = left-1\n pivot = table[right].number\n for start in range(left,right):\n \n table[i+1],table[right] = table[right],table[i+1]\n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\n", "class TRAMP:\n def __init__(self,arg_mark,arg_number,arg_input_index):\n self.mark = arg_mark\n self.number = arg_number\n self.input_index = arg_input_index\n\nN = int(input())\ntable = []\nfor input_index in range(N):\n mark,number = map(str,input().split())\n table.append(TRAMP(mark,int(number),input_index))\n\ndef Partition(left,right):\n global table\n i = left-1\n pivot = table[right].number\n for start in range(left,right):\n if table[start].number <= pivot:\n i += 1\n table[i],table[start] = table[start],table[i]\n table[i+1],table[right] = table[right],table[i+1]\n return i+1\n\ndef quickSort(left,right):\n if left < right:\n q = Partition(left,right)\n quickSort(left,q-1)\n quickSort(q+1,right)\n\nquickSort(0,N-1)\nstable_FLG = True\n\nfor i in range(1,N):\n if table[i].number == table[i-1].number and table[i].input_index < table[i-1].input_index:\n stable_FLG=False\n break\n\nif stable_FLG:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(N):\n print(\"%s %d\"%(table[i].mark,table[i].number))\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=[]\n\n\nd=dict()\ni=0\nx=\"-1\"\n", "a=[]\n\nfor i in range(n):\n \n\nd=dict()\ni=0\nx=\"-1\"\n", "a=[]\n\nfor i in range(n):\n \n\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\n", "a=[]\n\nfor i in range(n):\n \n\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n", "def quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n", "def quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nprint(message)\n", "def quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nfor i in :\n \n\nprint(message)\n", "def quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nfor i in :\n \n\nprint(message)\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nfor i in :\n \n\nprint(message)\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nmessage=\"Stable\"\n\nfor i in :\n \n\nprint(message)\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\n\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nmessage=\"Stable\"\n\nfor i in :\n \n\nprint(message)\n\nfor i in c:\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nmessage=\"Stable\"\n\nfor i in :\n \n\nprint(message)\n\nfor i in c:\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n \n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n \n\nprint(message)\n\nfor i in c:\n", "def partition(a,p,r):\n \n\ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n \n\nprint(message)\n\nfor i in c:\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n \n\nprint(message)\n\nfor i in c:\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n \n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def partition(a,p,r):\n \n i=p-1\n \n \ndef quicksort(a,p,r):\n \n\na=[]\nn=int(input())\nfor i in range(n):\n \n \nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],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\na=[]\nn=int(input())\nfor i in range(n):\n \n \nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def partition(a,p,r):\n x=int(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\na=[]\nn=int(input())\nfor i in range(n):\n \n \nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def partition(a,p,r):\n x=int(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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def partition(a,p,r):\n x=int(a[r][1:])\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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def 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 \n\ndef quicksort(a,p,r):\n if(p<r):\n q=partition(a,p,r)\n quicksort(a,p,q-1)\n quicksort(a,q+1,r)\n\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def 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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n \n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def 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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n a.append(\"\".join(s.split()))\n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def 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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n a.append(\"\".join(s.split()))\n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\n", "def 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\na=[]\nn=int(input())\nfor i in range(n):\n s=input()\n a.append(\"\".join(s.split()))\n\nc=list(a)\nquicksort(c,0,n-1)\n\nd=dict()\ni=0\nx=\"-1\"\nfor i in c:\n if(x!=i[1:]):\n d[i[1:]]=[i[:1]]\n x=i[1:]\n else:\n d[x].append(i[:1])\n\nmessage=\"Stable\"\n\nfor i in reversed(a):\n if(i[1:] in d):\n if(d[i[1:]].pop()!=i[:1]):\n message=\"Not stable\"\n break\n\nprint(message)\n\nfor i in c:\n print(\"%s %s\"%(i[:1],i[1:]))\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", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\nA = []\n\n\n# flag\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\nA = []\n\n\nquicksort(A, 0, n - 1)\n\n# flag\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\nn = int(input())\nA = []\n\n\nquicksort(A, 0, n - 1)\n\n# flag\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\n\nquicksort(A, 0, n - 1)\n\n# flag\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\n\n\nif is_stable:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\n\nfor val in valset:\n \n\nif is_stable:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n print(\"Stable\")\n\n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n \ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition:\n \n \ndef quicksort:\n \n\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n \nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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 = []\nvalset = set({})\nfor i in range(n):\n \n \nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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 = []\nvalset = set({})\nfor i in range(n):\n \n \nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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 = []\nvalset = set({})\nfor i in range(n):\n \n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n \n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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 = []\nvalset = set({})\nfor i in range(n):\n \n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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 = []\nvalset = set({})\nfor i in range(n):\n \n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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())\nA = []\nvalset = set({})\nfor i in range(n):\n \n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n \n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n \n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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\nn = int(input())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n \n # print(val, tp, flag)\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n \n # print(val, tp, flag)\n if flag:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in :\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\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())\nA = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in range(len(tp) - 1):\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\n i = 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 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 = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in range(len(tp) - 1):\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n \n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\n i = 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 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 = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in range(len(tp) - 1):\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n \n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\n", "# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_C&lang=ja\n\ndef partition(A, p, r):\n x = A[r][0]\n i = 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 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 = []\nvalset = set({})\nfor i in range(n):\n c, d = input().split()\n A.append((int(d), i, c))\n valset.add(int(d))\n\nquicksort(A, 0, n - 1)\n\n# flag\nis_stable = True\nfor val in valset:\n tp = [A[j][1] for j in range(n) if A[j][0] == val]\n flag = False\n for j in range(len(tp) - 1):\n if tp[j] > tp[j + 1]:\n flag = True\n break\n # print(val, tp, flag)\n if flag:\n is_stable = False\n break\n\nif is_stable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor tp in A:\n print(\"{} {}\".format(tp[2], tp[0]))\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", "def partition:\n", "def partition:\n \n\nif :\n", "def partition:\n \n\ndef quicksort:\n \n\nif :\n", "def partition:\n \n\ndef quicksort(A, p, r):\n \n\nif :\n", "def partition:\n \n\ndef quicksort(A, p, r):\n \n\nif __name__ == \"__main__\":\n", "def partition:\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n \n\nif __name__ == \"__main__\":\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\nif __name__ == \"__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\nif __name__ == \"__main__\":\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\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\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\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n \n \n quicksort(cards2, 0, n-1)\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 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\nif __name__ == \"__main__\":\n \n \n quicksort(cards2, 0, n-1)\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 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\nif __name__ == \"__main__\":\n \n \n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\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 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\nif __name__ == \"__main__\":\n \n \n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\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 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\nif __name__ == \"__main__\":\n \n \n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\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 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\nif __name__ == \"__main__\":\n \n \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = p-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 q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n \n \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = p-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 q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n \n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n", "def partition(A, p, r):\n x = A[r][0]\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\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n \n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n", "def partition(A, p, r):\n x = A[r][0]\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\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n \n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\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\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n import sys\n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in :\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\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\n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n import sys\n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n import sys\n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import \n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n \n \n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n \n \n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n cards1.append(card)\n \n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate:\n cards1.append(card)\n cards2.append((int(card[2:]), i))\n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate( ):\n cards1.append(card)\n cards2.append((int(card[2:]), i))\n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate( for l in ):\n cards1.append(card)\n cards2.append((int(card[2:]), i))\n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate((l.strip()) for l in ):\n cards1.append(card)\n cards2.append((int(card[2:]), i))\n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\n\")\n", "def partition(A, p, r):\n x = A[r][0]\n i = 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\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\nif __name__ == \"__main__\":\n import sys\n from operator import itemgetter\n n = int(input())\n cards1, cards2 = [], []\n for i, card in enumerate((l.strip()) for l in sys.stdin):\n cards1.append(card)\n cards2.append((int(card[2:]), i))\n\n quicksort(cards2, 0, n-1)\n print(\"Stable\" if all(i1 < i2 for (n1, i1), (n2, i2) in zip(cards2, cards2[1:]) if n1 == n2)\n else \"Not stable\")\n print(*(cards1[i] for i in map(itemgetter(1), cards2)), sep=\"\\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", "# coding=utf-8\n", "# coding=utf-8\n\n\ndef is_stable(A):\n", "# coding=utf-8\n\ndef partition:\n \n\ndef is_stable(A):\n", "# coding=utf-8\n\ndef partition:\n \n\ndef is_stable(A):\n \n\nn = int(input())\n", "# coding=utf-8\n\ndef partition:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\n", "# coding=utf-8\n\ndef partition:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n", "# coding=utf-8\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n", "# coding=utf-8\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nif :\n", "# coding=utf-8\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n", "# coding=utf-8\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n \n\nfor i in range(n):\n", "# coding=utf-8\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\n\ndef partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\n\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\n\ndef partition:\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\n\ndef partition(A, p, r):\n \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\ndef is_stable(A):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 is_stable(A):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(A):\n for i in :\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 quick_sort(A, p, r):\n 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 is_stable(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\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 A[i+1], A[j] = A[j], A[i+1]\n i += 1\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 is_stable(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\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 A[i+1], A[j] = A[j], A[i+1]\n i += 1\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 is_stable(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\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\n", "# coding=utf-8\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 A[i+1], A[j] = A[j], A[i+1]\n i += 1\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 is_stable(A):\n for i in range(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\n\nn = int(input())\ncards = []\nfor i in range(n):\n suit, num = input().split()\n cards.append([suit, int(num), i])\n\nquick_sort(cards, 0, n-1)\n\nif is_stable(cards):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i][0], cards[i][1])\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", "def merge:\n", "def merge:\n \n\nfor n, c in A:\n", "def merge:\n \n\ndef qsort:\n \n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef qsort:\n \n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef qsort:\n \n\nA, B = [], []\n\n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef qsort:\n \n\nA, B = [], []\n\n\nmsort(B, 0, N)\n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\n\n\nmsort(B, 0, N)\n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef partition:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\n\n\nmsort(B, 0, N)\n\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef partition:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\n\n\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef partition:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\n\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n\ndef msort:\n \n\ndef partition:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n \ndef msort:\n \n\ndef partition:\n \n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n \ndef msort:\n \n\ndef partition:\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n \ndef msort(A, l, r):\n \n\ndef partition:\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n \n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n \ndef msort(A, l, r):\n \n\ndef partition:\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge:\n \n \ndef msort(A, l, r):\n \n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n \n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort:\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n \nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \n R.append((1e10, None))\n \n \ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \n R.append((1e10, None))\n i, j = 0, 0\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n \n R.append((1e10, None))\n i, j = 0, 0\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n L.append((1e10, None))\n \n R.append((1e10, None))\n i, j = 0, 0\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n \n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n L.append((1e10, None))\n \n R.append((1e10, None))\n i, j = 0, 0\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n \n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n L.append((1e10, None))\n \n R.append((1e10, None))\n i, j = 0, 0\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n \n L.append((1e10, None))\n \n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n \n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n \n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n \n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in :\n \n q = i+1\n \n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n \n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in :\n \n q = i+1\n A[r-1] = A[q]\n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in :\n \n q = i+1\n A[r-1] = A[q]\n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in :\n if A[j][0] <= v[0]:\n i += 1\n t = A[i]\n A[i] = A[j]\n A[j] = t\n q = i+1\n A[r-1] = A[q]\n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in :\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in range(l, r-1):\n if A[j][0] <= v[0]:\n i += 1\n t = A[i]\n A[i] = A[j]\n A[j] = t\n q = i+1\n A[r-1] = A[q]\n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\n", "def merge(A, l, m, r):\n L = A[l:m]\n L.append((1e10, None))\n R = A[m:r]\n R.append((1e10, None))\n i, j = 0, 0\n for k in range(l, r):\n if L[i][0] <= R[j][0]:\n A[k] = L[i]\n i += 1\n else:\n A[k] = R[j]\n j += 1\n\ndef msort(A, l, r):\n if r-l > 1:\n m = (l+r)//2\n msort(A, l, m)\n msort(A, m, r)\n merge(A, l, m, r)\n\ndef partition(A, l, r):\n v = A[r-1]\n i = l - 1\n for j in range(l, r-1):\n if A[j][0] <= v[0]:\n i += 1\n t = A[i]\n A[i] = A[j]\n A[j] = t\n q = i+1\n A[r-1] = A[q]\n A[q] = v\n return q\n\ndef qsort(A, l, r):\n if r-l > 1:\n q = partition(A, l, r)\n qsort(A, l, q)\n qsort(A, q+1, r)\n\nN = int(input())\nA, B = [], []\nfor _ in range(N):\n c, n = input().split()\n n = int(n)\n A.append((n, c))\n B.append((n, c))\nqsort(A, 0, N)\nmsort(B, 0, N)\nprint('Stable' if A == B else 'Not stable')\nfor n, c in A:\n print(c, n)\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", "ans = 'Stable'\n", "def partition:\n \n\nans = 'Stable'\n", "def partition:\n \n\nans = 'Stable'\nfor i in :\n", "def partition:\n \n\nans = 'Stable'\nfor i in :\n \n\nfor v in deck:\n", "def partition:\n \n\nn = int(input())\n\n\nans = 'Stable'\nfor i in :\n \n\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\nn = int(input())\n\n\nans = 'Stable'\nfor i in :\n \n\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\nn = int(input())\nfor index in range(n):\n \n\nans = 'Stable'\nfor i in :\n \n\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\nn = int(input())\nfor index in range(n):\n \n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in :\n \n\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\nn = int(input())\nfor index in range(n):\n \n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in :\n \nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in :\n \nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in :\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition:\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition(A, p, r):\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n", "def quickSort:\n \n\ndef partition(A, p, r):\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n \n\ndef partition(A, p, r):\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n \n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n \ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n \n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n \n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n \n card = [mark, int(number), index]\n\n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n \n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n for j in :\n \n \n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n \nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n for j in :\n \n \n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n deck.append(card)\n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\n for j in :\n \n A[i+1], A[r] = A[r], A[i+1]\n return i+1\n\n\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n deck.append(card)\n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\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\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n deck.append(card)\n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[1]))\n", "def quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\ndef partition(A, p, r):\n x = A[r]\n i = p -1\n\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\ndeck = []\nn = int(input())\nfor index in range(n):\n mark, number = input().split()\n card = [mark, int(number), index]\n\n deck.append(card)\n\nquickSort(deck, 0, n-1)\n\nans = 'Stable'\nfor i in range(1, n):\n if deck[i-1][1] == deck[i][1]:\n if deck[i-1][2] > deck[i][2]:\n ans = 'Not stable'\n break\nprint (ans)\nfor v in deck:\n print ('{mark} {number}'.format(mark=v[0], number=v[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", "print(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "cards = []\n\n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def is_stable(cards):\n \n\ncards = []\n\n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def is_stable(cards):\n \n\ncards = []\nfor i in range(n):\n \n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def partition:\n \n\ndef is_stable(cards):\n \n\ncards = []\nfor i in range(n):\n \n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def partition:\n \n\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def partition:\n \n\ndef quicksort:\n \n\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\n", "def partition:\n \n\ndef quicksort:\n \n\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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\ndef is_stable(cards):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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\ndef is_stable(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\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 is_stable(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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\ndef is_stable(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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\ndef is_stable(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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 is_stable(cards):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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 is_stable(cards):\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\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\n\ndef is_stable(cards):\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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 is_stable(cards):\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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 \n\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\n\ndef is_stable(cards):\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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\ndef is_stable(cards):\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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\ndef is_stable(cards):\n for i in :\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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 += 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 is_stable(cards):\n for i in :\n \n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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 += 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 is_stable(cards):\n for i in :\n if cards[i-1][1] == cards[i][1]:\n if cards[i-1][2] > cards[i][2]:\n return False\n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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 += 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 is_stable(cards):\n for i in range(1, len(cards)):\n if cards[i-1][1] == cards[i][1]:\n if cards[i-1][2] > cards[i][2]:\n return False\n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[1])\n", "def 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\ndef is_stable(cards):\n for i in range(1, len(cards)):\n if cards[i-1][1] == cards[i][1]:\n if cards[i-1][2] > cards[i][2]:\n return False\n return True\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n cards.append(input().split() + [i])\nquicksort(cards, 0, n - 1)\nprint(\"Stable\" if is_stable(cards) else \"Not stable\")\nfor card in cards:\n print(card[0], card[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", "def partition:\n", "def partition:\n \n\nprint(msg)\n", "def partition:\n \n\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\n\n\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [input() for _ in range(n)]\n\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [input() for _ in range(n)]\n\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [input() for _ in range(n)]\n\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n", "def num(card):\n \n\ndef partition(A, p, r):\n \n\ndef quicksort:\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n", "def num(card):\n \n\ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n", "def num(card):\n \n\ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n \n\nprint(msg)\nfor card in A:\n print(card)\n", "def num(card):\n \n\ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\n print(card)\n", "def num(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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\n print(card)\n", "def num(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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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 \ndef quicksort(A, p, 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 = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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 \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 = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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 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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\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\nn = int(input())\nA = [input() for _ in range(n)]\nB = sorted(A, key=num)\nquicksort(A, 0, n - 1)\n\nmsg = \"Stable\"\nfor i in range(n):\n if A[i] != B[i]:\n msg = \"Not stable\"\n break\n\nprint(msg)\nfor card in A:\n print(card)\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 main():\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 quick_sort:\n \n\ndef main():\n \n\nif :\n main()\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef main():\n \n A = []\n\n \nif :\n main()\n", "def 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 A = []\n\n \nif :\n main()\n", "def 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 A = []\n\n \nif __name__ == \"__main__\":\n main()\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 main():\n \n A = []\n\n \nif __name__ == \"__main__\":\n main()\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 main():\n \n A = []\n\n \nif __name__ == \"__main__\":\n main()\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 main():\n \n A = []\n\n \nif __name__ == \"__main__\":\n main()\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 main():\n n = int(input())\n A = []\n\n \nif __name__ == \"__main__\":\n main()\n", "def 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\n\ndef main():\n n = int(input())\n A = []\n\n \nif __name__ == \"__main__\":\n main()\n", "def 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\n\ndef main():\n n = int(input())\n A = []\n\n \n flag = False\n \n\nif __name__ == \"__main__\":\n main()\n", "def partition(A, p, r):\n x = A[r][1]\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\n\ndef main():\n n = int(input())\n A = []\n\n \n flag = False\n \n\nif __name__ == \"__main__\":\n main()\n", "def partition(A, p, r):\n x = A[r][1]\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\n\ndef main():\n n = int(input())\n A = []\n\n \n flag = False\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 \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 = 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\n \n flag = False\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 \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 = 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\n \n quick_sort(A, 0, n - 1)\n\n flag = False\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 \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 = 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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\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\n for j in :\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\ndef main():\n n = int(input())\n A = []\n\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\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\n for j in :\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\ndef main():\n n = int(input())\n A = []\n\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n \n\n if flag:\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\n for j in :\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\ndef main():\n n = int(input())\n A = []\n\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in :\n \n\n if flag:\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in :\n \n\n if flag:\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in :\n \n\n if flag:\n print(\"Not stable\")\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in :\n \n\n if flag:\n print(\"Not stable\")\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in :\n \n\n if flag:\n print(\"Not stable\")\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n \n\n if flag:\n print(\"Not stable\")\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\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\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\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\n for i in range(n):\n \n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\n \n\n for i in range(n):\n print(A[i][0], A[i][1])\n\n\nif __name__ == \"__main__\":\n main()\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\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\n for i in range(n):\n \n \n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\n \n\n for i in range(n):\n print(A[i][0], A[i][1])\n\n\nif __name__ == \"__main__\":\n main()\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\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\n for i in range(n):\n \n A.append([mark, int(num), i])\n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\n \n\n for i in range(n):\n print(A[i][0], A[i][1])\n\n\nif __name__ == \"__main__\":\n main()\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\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\n for i in range(n):\n mark, num = input().split()\n A.append([mark, int(num), i])\n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\n \n\n for i in range(n):\n print(A[i][0], A[i][1])\n\n\nif __name__ == \"__main__\":\n main()\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\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\n for i in range(n):\n mark, num = input().split()\n A.append([mark, int(num), i])\n\n quick_sort(A, 0, n - 1)\n\n flag = False\n for i in range(1, n):\n if A[i - 1][1] == A[i][1]:\n if A[i - 1][2] > A[i][2]:\n flag = True\n break\n\n if flag:\n print(\"Not stable\")\n else:\n print(\"Stable\")\n\n for i in range(n):\n print(A[i][0], A[i][1])\n\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", "# coding: utf-8\n# クイックソート\n", "# coding: utf-8\n# クイックソート\n\n\ndef partition:\n", "# coding: utf-8\n# クイックソート\n\n\ndef partition:\n \n\nif :\n", "# coding: utf-8\n# クイックソート\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nif :\n", "# coding: utf-8\n# クイックソート\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable:\n\n \nif :\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable:\n\n \nif :\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable:\n\n \nif __name__ == \"__main__\":\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef checkStable:\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\ndef checkStable:\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n\ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\ndef quickSort:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \ndef quickSort:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \ndef quickSort(A, p, r):\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n \n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n aft_A = quickSort(A, 0, n - 1)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n \ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n \n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n \n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n \nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n \n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n\nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n\nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n \n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in :\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n \n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n \n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n quickSort(A, p, q - 1)\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\n return i + 1\n\n\ndef quickSort(A, p, r):\n if p < r:\n \n quickSort(A, p, q - 1)\n \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n for data in same_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 \n return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n for data in same_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n \n for data in same_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n \n if :\n continue\n\n for data in same_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if :\n continue\n\n for data in same_list:\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if :\n continue\n\n for data in same_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n \n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n \n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n if :\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n if or :\n \n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n if or :\n return 'Not stable'\n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n if (bef > 0 and aft < 0) or :\n return 'Not stable'\n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n", "# coding: utf-8\n# クイックソート\nimport copy\n\n\ndef partition(A, p, r):\n x = int(A[r].split()[1])\n\n i = p - 1\n tmp = 0\n\n for j in range(p, r):\n if int(A[j].split()[1]) <= x:\n i = i + 1\n tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n\n tmp = A[i + 1]\n A[i + 1] = A[r]\n A[r] = tmp\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 return (A)\n\n\ndef checkStable(before_list, sorted_list):\n\n for val in sorted_list:\n same_list = [\n i for i in sorted_list\n if (int(val.split()[1]) == int(i.split()[1])) and val != i\n ]\n if len(same_list) == 0:\n continue\n\n for data in same_list:\n bef = before_list.index(val) - before_list.index(data)\n aft = sorted_list.index(val) - sorted_list.index(data)\n\n if (bef > 0 and aft < 0) or (bef < 0 and aft > 0):\n return 'Not stable'\n\n return 'Stable'\n\n\nif __name__ == \"__main__\":\n n = int(input())\n\n A = []\n for _ in range(n):\n A.append(input())\n\n bef_A = copy.deepcopy(A)\n\n aft_A = quickSort(A, 0, n - 1)\n\n print(checkStable(bef_A, aft_A))\n\n for data in aft_A:\n print(data)\n" ]
52
[ { "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", "tag = True\n", "def partition:\n \n\ntag = True\n", "def partition:\n \n\ntag = True\n\n\nfor s in arr:\n", "def partition:\n \n\ntag = True\nfor i in :\n \n\nfor s in arr:\n", "def partition:\n \n\nn = int(input())\n\n\ntag = True\nfor i in :\n \n\nfor s in arr:\n", "def partition:\n \n\nn = int(input())\n\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \n\nfor s in arr:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \n\nfor s in arr:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \n\nfor s in arr:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n", "def partition:\n \n \ndef quick_sort:\n \n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n", "def partition:\n \n \ndef quick_sort:\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n", "def partition:\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n \nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n", "def partition:\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n", "def partition:\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in :\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition:\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n \n for j in :\n \n \ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n \n for j in :\n \n \n return i + 1\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n \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, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n i = l - 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, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n i = l - 1\n for j in range(l, r):\n \n A[i + 1], A[r] = A[r], A[i + 1]\n return i + 1\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\n", "def partition(A, l, r):\n i = l - 1\n for j in range(l, 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\n\ndef quick_sort(A, l, r):\n if l < r:\n q = partition(A, l, r)\n quick_sort(A, l, q - 1)\n quick_sort(A, q + 1, r)\n\nn = int(input())\narr = [input().split() + [i] for i in range(n)]\nquick_sort(arr, 0, n - 1)\ntag = True\nfor i in range(1, n):\n if arr[i][1] == arr[i - 1][1] and arr[i - 1][2] > arr[i][2]:\n tag = False\n break\nprint(['Not stable', 'Stable'][tag])\nfor s in arr:\n print(*s[:2])\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 num(card):\n", "def num(card):\n \n\ndef quicksort:\n", "def num(card):\n \n\ndef quicksort:\n \n\nquicksort(A, 0, n - 1)\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nquicksort(A, 0, n - 1)\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n\nquicksort(A, 0, n - 1)\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(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\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n return int(card[0][2:])\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\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n return int(card[0][2:])\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\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n return int(card[0][2:])\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\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n return int(card[0][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):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n", "def num(card):\n return int(card[0][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):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(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\ndef is_stable(A):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(A[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):\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(A[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):\n for i in :\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n \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):\n for i in :\n \n \nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n \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):\n for i in :\n \n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][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):\n for i in :\n \n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][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):\n for i in :\n \n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][2:])\n\ndef partition(A, p, r):\n x = num(A[r])\n i = p - 1\n for j in :\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):\n for i in :\n \n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][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):\n for i in :\n \n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][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):\n for i in :\n if num(A[i]) == num(A[i + 1]) and A[i][1] > A[i + 1][1]:\n return False\n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\n", "def num(card):\n return int(card[0][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):\n for i in range(n - 1):\n if num(A[i]) == num(A[i + 1]) and A[i][1] > A[i + 1][1]:\n return False\n return True\n\nn = int(input())\nA = [(input(), i) for i in range(n)]\nquicksort(A, 0, n - 1)\n\nprint(\"Stable\" if is_stable(A) else \"Not stable\")\nfor card in A:\n print(card[0])\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", "cards=[]\n", "def quicksort(p,r):\n \n\ncards=[]\n", "def quicksort(p,r):\n \n\nn=int(input())\ncards=[]\n", "def quicksort(p,r):\n \n\nn=int(input())\ncards=[]\n\n\nfor ci in cards:\n", "def quicksort(p,r):\n \n\nn=int(input())\ncards=[]\n\n\nquicksort(0,n-1)\n\n\nfor ci in cards:\n", "def quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\n\nfor ci in cards:\n", "def partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\n\nfor ci in cards:\n", "def partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\n\n\nfor ci in cards:\n", "class card:\n \n\ndef partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\n\n\nfor ci in cards:\n", "class card:\n \n\ndef partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in :\n \n\nfor ci in cards:\n", "class card:\n \n\ndef partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in :\n \nif:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in :\n \nif:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n\ndef quicksort(p,r):\n \n\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n print(\"Stable\")\n\n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n \nif:\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif:\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif:\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n \n \nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\n \n \n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\n \n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n \n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\n \n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n \n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n \n i=p-1\n for j in :\n \n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n cards.append(card(suit,int(num),i))\n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n c_pivot=cards[r]\n i=p-1\n for j in :\n \n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n cards.append(card(suit,int(num),i))\n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n c_pivot=cards[r]\n i=p-1\n for j in :\n if(cards[j].num<=c_pivot.num):\n i+=1\n cards[i],cards[j]=cards[j],cards[i]\n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n cards.append(card(suit,int(num),i))\n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor ci in cards:\n print(ci.suit,ci.num)\n", "class card:\n def __init__(self,suit,num,input_index):\n self.suit = suit\n self.num = num\n self.input_index = input_index\n\ndef partition(p,r):\n c_pivot=cards[r]\n i=p-1\n for j in range(p,r):\n if(cards[j].num<=c_pivot.num):\n i+=1\n cards[i],cards[j]=cards[j],cards[i]\n cards[i+1],cards[r]=cards[r],cards[i+1]\n return i+1\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\nn=int(input())\ncards=[]\nfor i in range(n):\n suit,num=input().split()\n cards.append(card(suit,int(num),i))\n\nquicksort(0,n-1)\n\nstableflag=True\nfor i in range(1,n):\n if(cards[i-1].num == cards[i].num and cards[i-1].input_index > cards[i].input_index):\n stableflag=False\n break\nif(stableflag):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor ci in cards:\n print(ci.suit,ci.num)\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", "#coding:utf-8\n#1_6_C\n", "#coding:utf-8\n#1_6_C\ndef partition:\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nprint(d.is_stable(cards))\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nd = CheckStable()\n\n\nprint(d.is_stable(cards))\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nd = CheckStable()\nd.store_cards(cards)\n\n\nprint(d.is_stable(cards))\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nn = int(input())\n\nd = CheckStable()\nd.store_cards(cards)\n\n\nprint(d.is_stable(cards))\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nn = int(input())\n\nd = CheckStable()\nd.store_cards(cards)\n\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\nn = int(input())\n\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort:\n \n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n", "#coding:utf-8\n#1_6_C\ndef partition:\n \n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n \n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n \n \n for j in :\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n \n \n for j in :\n \n \n return i + 1\n\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\n def store_cards:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef 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\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n \n\n def store_cards:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef 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\ndef quick_sort(A, p, r):\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n x = int(A[r][1])\n \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 \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n x = int(A[r][1])\n \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 \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\ndef partition(A, p, r):\n x = int(A[r][1])\n \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 \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\n def is_stable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\n def is_stable:\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\n def is_stable(self, cards):\n \n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n \n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 += 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 \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n \n\n def store_cards:\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n # Key is number. Value is array of suit.\n\n def store_cards:\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n return A\n\nclass CheckStable:\n def __init__(self):\n # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n \n return A\n\nclass CheckStable:\n def __init__(self):\n # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n \n quick_sort(A, q + 1, r)\n return A\n\nclass CheckStable:\n def __init__(self):\n # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n \n quick_sort(A, q + 1, r)\n return A\n\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n return A\n\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n return A\n\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n for item in :\n \n \nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n if p < r:\n \n quick_sort(A, p, q - 1)\n quick_sort(A, q + 1, r)\n return A\n\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n for item in :\n \n return \"Stable\"\n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n 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\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n for item in :\n \n return \"Stable\"\n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n 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\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n for item in reversed(cards):\n \n return \"Stable\"\n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\n", "#coding:utf-8\n#1_6_C\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 quick_sort(A, p, r):\n 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\nclass CheckStable:\n def __init__(self):\n self.d = dict() # Key is number. Value is array of suit.\n\n def store_cards(self, cards):\n for i in range(n):\n if cards[i][1] in self.d:\n self.d[cards[i][1]].append(cards[i][0])\n else:\n self.d[cards[i][1]] = [cards[i][0]]\n\n def is_stable(self, cards):\n for item in reversed(cards):\n if self.d[item[1]].pop() != item[0]:\n return \"Not stable\"\n return \"Stable\"\n\nn = int(input())\ncards = [tuple(input().split()) for i in range(n)]\nd = CheckStable()\nd.store_cards(cards)\n\nquick_sort(cards, 0, n - 1)\n\nprint(d.is_stable(cards))\nfor i in range(n):\n print(' '.join(cards[i]))\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\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\n\n\ndef quickSort:\n \n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\n\n\ndef quickSort:\n \n\nmergeSort(S, n, 0, n)\n\n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\n\n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nmergeSort(S, n, 0, n)\n\n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\n\n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\n\n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\n", "A = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n", "A = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\ndef merge:\n \n\ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\ndef merge:\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n\ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\ndef merge:\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef partition:\n \n i = p -1\n \n \ndef quickSort:\n \n\nSENTINEL = 9999999999999\n\ndef merge:\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef 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)\n\nSENTINEL = 9999999999999\n\ndef merge:\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef 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)\n\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef 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)\n\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef 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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort:\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\n\ndef 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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort(S, n, left, right):\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort(S, n, left, right):\n \n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n \n \ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n \n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n \nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n \n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n \n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n \n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n \n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.copy()\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 += 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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n \n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in :\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n if A[_] != S[_]:\n return \"Not stable\"\n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in range(left, right):\n \n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n if A[_] != S[_]:\n return \"Not stable\"\n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\n", "n = int(input())\nA = [input().split(\" \") for _ in range(n)]\nS = A.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\nSENTINEL = 9999999999999\n\ndef merge(S, n, left, mid, right):\n global SENTINEL\n n1 = mid - left\n n2 = right - mid\n L = S[left:mid] + [[\" \", SENTINEL]]\n R = S[mid:right] + [[\" \", SENTINEL]]\n i = j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(R[j][1]):\n S[k] = L[i]\n i += 1\n else:\n S[k] = R[j]\n j += 1\n\ndef mergeSort(S, n, left, right):\n if left + 1 < right:\n mid = int((left + right) / 2)\n mergeSort(S, n, left, mid)\n mergeSort(S, n, mid, right)\n merge(S, n, left, mid, right)\n\nquickSort(A, 0, n-1)\nmergeSort(S, n, 0, n)\n\ndef Judge():\n for _ in range(n):\n if A[_] != S[_]:\n return \"Not stable\"\n return \"Stable\"\n\nprint(Judge())\nfor _ in range(n):\n print(*A[_])\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", "l = []\n", "l = []\nfor i in range(n):\n", "def partition(A,p,r):\n \n\nl = []\nfor i in range(n):\n", "def partition(A,p,r):\n \n\nl = []\nfor i in range(n):\n \n\nfor s,n,c in l:\n", "def partition(A,p,r):\n \n\ndef checker:\n \n\nl = []\nfor i in range(n):\n \n\nfor s,n,c in l:\n", "def partition(A,p,r):\n \n\ndef quickSort:\n \n\ndef checker:\n \n\nl = []\nfor i in range(n):\n \n\nfor s,n,c in l:\n", "def partition(A,p,r):\n \n\ndef quickSort:\n \n\ndef checker:\n \n\nl = []\nfor i in range(n):\n \n\nprint(checker(l,0,n))\nfor s,n,c in l:\n", "def partition(A,p,r):\n \n\ndef quickSort:\n \n\ndef checker:\n \n\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n", "def partition(A,p,r):\n \n\ndef quickSort:\n \n\ndef checker:\n \n\nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\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 checker:\n \n\nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\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 checker(A,start,end):\n \n\nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\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 checker(A,start,end):\n \n\nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\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 checker(A,start,end):\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\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 checker(A,start,end):\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,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\ndef checker(A,start,end):\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,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\ndef checker(A,start,end):\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n \nn = int(input())\nl = []\nfor i in range(n):\n \n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n \nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n \nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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\ndef checker(A,start,end):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 checker(A,start,end):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 (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 checker(A,start,end):\n for i in :\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 (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 checker(A,start,end):\n for i in range(start,end-1):\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 checker(A,start,end):\n for i in range(start,end-1):\n \n return \"Stable\"\n\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 checker(A,start,end):\n for i in range(start,end-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\nn = int(input())\nl = []\nfor i in range(n):\n card = input().split()\n l.append((card[0],int(card[1]),i))\nquickSort(l,0,n-1)\nprint(checker(l,0,n))\nfor s,n,c in l:\n print(\"{} {}\".format(s,n))\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 quick_sort -> None:\n", "def quick_sort -> None:\n \n\nif :\n", "from typing import List, Tuple\n\n\ndef quick_sort -> None:\n \n\nif :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef quick_sort -> None:\n \n\nif :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition -> int:\n \n\ndef quick_sort -> None:\n \n\nif :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition -> int:\n \n\ndef quick_sort -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition -> int:\n \n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition -> int:\n \n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , ) -> int:\n \n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , ) -> int:\n \n \ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , ) -> int:\n \n \n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , ) -> int:\n \n \n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n \n \n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , ) -> int:\n \n \n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n \n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , pivot_idx: int) -> int:\n \n \n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n \n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, , pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n \n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n \n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n \n\n for i in :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(, p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n \n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n \n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n \n\n for j in :\n \n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n \n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(, start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in :\n \n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n \n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in :\n \n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n \n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in :\n \n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n else:\n \n\n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n \n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n else:\n \n\n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n else:\n \n\n for elem in elements:\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in :\n \n else:\n \n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n \n else:\n \n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n if elements[i][1] == elements[i + 1][1]:\n if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n \n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n if elements[i][1] == elements[i + 1][1]:\n if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n elements[i] = (element[0], int(element[1]))\n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n if elements[i][1] == elements[i + 1][1]:\n if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):\n print(\"Not stable\")\n break\n else:\n \n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n \n elements[i] = (element[0], int(element[1]))\n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n if elements[i][1] == elements[i + 1][1]:\n if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\n", "import copy\nfrom typing import List, Tuple\n\n\ndef partition(elements: List[Tuple[str, int]], start_idx: int, pivot_idx: int) -> int:\n pivot = elements[pivot_idx][1]\n i = start_idx - 1\n\n for j in range(start_idx, pivot_idx):\n if elements[j][1] <= pivot:\n i += 1\n elements[i], elements[j] = elements[j], elements[i]\n elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]\n\n return i + 1\n\n\ndef quick_sort(elements: List[Tuple[str, int]], p: int, r: int) -> None:\n if p < r:\n q = partition(elements, p, r)\n quick_sort(elements, p, q - 1)\n quick_sort(elements, q + 1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n elements = [(\"\", 0)] * n\n for i in range(n):\n element = input().split()\n elements[i] = (element[0], int(element[1]))\n\n elements_copy = copy.deepcopy(elements)\n quick_sort(elements, 0, n - 1)\n\n for i in range(n - 1):\n if elements[i][1] == elements[i + 1][1]:\n if elements_copy.index(elements[i]) > elements_copy.index(elements[i + 1]):\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for elem in elements:\n print(f\"{elem[0]} {elem[1]}\")\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", "A = []\nfor i in range(n):\n", "import sys\n\n\nA = []\nfor i in range(n):\n", "import sys\n\n\nn = int(input())\nA = []\nfor i in range(n):\n", "import sys\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n", "import sys\n\n\nBIG_NUM = 2000000000\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n", "import sys\n\n\nBIG_NUM = 2000000000\n\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n", "from queue import Queue\n\n\nimport sys\n\n\nBIG_NUM = 2000000000\n\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n", "from queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\n\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n", "from queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\n\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\n\ndef isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\n\ndef QuickSort(A,p,r):\n \n\ndef isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\n\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\ndef isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\ndef isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\n\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\ndef isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\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 isStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\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 isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\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 isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n \nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n \nn = int(input())\nA = []\nfor i in range(n):\n \n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n \n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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\ndef isStable(A):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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 isStable(A):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\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\n\ndef QuickSort(A,p,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 return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\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\n\ndef QuickSort(A,p,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 for i in :\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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 isStable(A):\n for i in :\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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 isStable(A):\n for i in range(1,len(A)):\n \n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,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 isStable(A):\n for i in range(1,len(A)):\n if A[i-1][1] == A[i][1]:\n if A[i-1][2] > A[i][2]:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\n", "from enum import Enum\nfrom queue import Queue\nimport collections\n\nimport sys\nimport math\n\nBIG_NUM = 2000000000\nMOD = 1000000007\nEPS = 0.000000001\n\ndef partition(A,p,r):\n i = p-1\n for j in range(p,r):\n if A[j][1]<=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\n\ndef QuickSort(A,p,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 for i in range(1,len(A)):\n if A[i-1][1] == A[i][1]:\n if A[i-1][2] > A[i][2]:\n return 'Not stable'\n return 'Stable'\n\nn = int(input())\nA = []\nfor i in range(n):\n suit,num = sys.stdin.readline().split()\n A += [[suit,int(num),i]]\nQuickSort(A,0,n-1)\nprint(isStable(A))\nfor i in A:\n print(i[0],i[1])\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", "def partition:\n", "def partition:\n \n\nfor i in range(n):\n", "def partition:\n \n\nfor i in range(n):\n \n\nfor card in li:\n", "def partition:\n \n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\n\nfor card in li:\n", "def partition:\n \n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "def partition:\n \n\ndef quick_sort:\n \n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n \n\ndef partition:\n \n \ndef quick_sort:\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n \n\ndef partition:\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition:\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n \nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n \nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n \nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n \n \ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n \n \ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n \n for j in :\n \n \ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n \n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n \n for j in :\n \n \n return i + 1\n\n\ndef quick_sort(A, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\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-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n \n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\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-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n \nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\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-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\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 index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in :\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if :\n \n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in :\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and :\n \n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in :\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and :\n \n break\n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and :\n \n break\n if :\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and :\n \n break\n if i == n - 1:\n \n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and :\n \n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and and :\n \n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and and > :\n \n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and and > :\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if and and li[i].input_index > :\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and and li[i].input_index > :\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and and li[i].input_index > .input_index:\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and == and li[i].input_index > .input_index:\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and == li[i + 1].num and li[i].input_index > .input_index:\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and li[i].num == li[i + 1].num and li[i].input_index > .input_index:\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\n", "class Card:\n def __init__(self, num, suit, input_index):\n self.num = num\n self.suit = suit\n self.input_index = input_index\n\n\ndef partition(A, p, r):\n x = A[r - 1].num\n i = p - 1\n for j in range(p, r - 1):\n if A[j].num <= x:\n i = 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, p, r):\n if p < r-1:\n index = partition(A, p, r)\n quick_sort(A, p, index)\n quick_sort(A, index, r)\n\n\nn = int(input())\nli = [None] * n\nfor i in range(n):\n temp_list = list(map(str, input().split()))\n li[i] = Card(int(temp_list[1]), temp_list[0], i)\n\nquick_sort(li, 0, n)\n\nfor i in range(n):\n if i < n - 1 and li[i].num == li[i + 1].num and li[i].input_index > li[i + 1].input_index:\n print('Not stable')\n break\n if i == n - 1:\n print('Stable')\n\nfor card in li:\n print(card.suit + ' {}'.format(card.num))\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", "def isStable(A):\n", "def isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\n", "def partition:\n \n\ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\n", "def partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\n", "def partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) + (i,) for i in range(n)]\n", "def partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) + (i,) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\n\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\nA = [f(readline().split()) + (i,) for i in range(n)]\n\n\nprint(\"\\n\".join(f\"{a} {b}\" for a, b, c in A))\n", "import sys\n\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \n\nf = lambda a: (a[0], int(a[1]))\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\ndef partition:\n \ndef quicksort:\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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())\nf = lambda a: (a[0], int(a[1]))\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())\nf = lambda a: (a[0], int(a[1]))\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:\n \ndef isStable(A):\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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:\n \ndef isStable(A):\n \n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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:\n \ndef isStable(A):\n \n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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 \n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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 for i in :\n \n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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 for i in :\n \n return True\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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 \ndef quicksort(A, 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: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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 \n return True\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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 \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: (a[0], int(a[1]))\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 \n return True\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\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: (a[0], int(a[1]))\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", "for i in :\n", "for i in :\n \n\nfor i in range(n):\n", "card = []\n\n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\ncard = []\n\n\nfor i in :\n \n\nfor i in range(n):\n", "n = int(input())\ncard = []\n\n\nfor i in :\n \n\nfor i in range(n):\n \n\nfor in card:\n", "def quick_sort:\n \n\nn = int(input())\ncard = []\n\n\nfor i in :\n \n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\n\n\nfor i in :\n \n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\n\nfor i in range(n):\n \n\nfor i in :\n \n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\nfor i in :\n \n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\nfor i in :\n \n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in :\n \n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n \n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n\nfor in card:\n", "def partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n \n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n", "def partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n \n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n", "def partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n", "def partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n print(f\"{suit} {num}\")\n", "def partition:\n \n i = p-1\n \n \ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quick_sort(A, p, r):\n \n\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n print(f\"{suit} {num}\")\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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor in card:\n print(f\"{suit} {num}\")\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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor suit, num in card:\n print(f\"{suit} {num}\")\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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor suit, num in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n \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\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor suit, num in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n x = A[r][1]\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\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n \nfor suit, num in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n x = A[r][1]\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\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\n", "def partition(A, p, r):\n x = A[r][1]\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\nn = int(input())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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\ndef quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n \n \n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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\ndef quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n \n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n \n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n \n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n \n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n \n \norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n tmpdic[num] += suit\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n tmpdic[num] += suit\n else:\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n tmpdic[num] += suit\n else:\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if :\n tmpdic[num] += suit\n else:\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if order[i] != :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if num in tmpdic:\n tmpdic[num] += suit\n else:\n \n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if order[i] != :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if num in tmpdic:\n tmpdic[num] += suit\n else:\n tmpdic[num] = suit\n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if order[i] != :\n \n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if num in tmpdic:\n tmpdic[num] += suit\n else:\n tmpdic[num] = suit\n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if order[i] != :\n print(\"Not stable\")\n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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 quick_sort(A, p, r):\n 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())\ncard = []\ntmpdic = {}\nfor i in range(n):\n suit, num = input().split()\n num = int(num)\n card.append((suit, num))\n if num in tmpdic:\n tmpdic[num] += suit\n else:\n tmpdic[num] = suit\n\norder = \"\"\nfor i in sorted(tmpdic.keys()):\n order += tmpdic[i]\n\nquick_sort(card, 0, n-1)\n\nfor i in range(n):\n if order[i] != card[i][0]:\n print(\"Not stable\")\n break\n if i == n-1:\n print(\"Stable\")\n\nfor suit, num in card:\n print(f\"{suit} {num}\")\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", "def merge:\n \n\nA = []\n", "def merge:\n \n\nA = []\n\n\nmerge_sort(0, N)\n", "def merge:\n \n\nA = []\nfor _ in range(N):\n \n\nmerge_sort(0, N)\n", "def merge:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \n\nmerge_sort(0, N)\n", "def merge:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\n\nmerge_sort(0, N)\n", "def merge:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\n\nmerge_sort(0, N)\n\nis_stable = True\n", "def quick_sort(p, r):\n \n\ndef merge:\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\n\nmerge_sort(0, N)\n\nis_stable = True\n", "def quick_sort(p, r):\n \n\ndef merge:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\n\nmerge_sort(0, N)\n\nis_stable = True\n", "def quick_sort(p, r):\n \n\ndef merge:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\n\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n", "def quick_sort(p, r):\n \n\ndef merge:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge:\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge:\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge:\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge:\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n \nif is_stable:\n print(\"Stable\")\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 \n\ndef merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n \n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n \n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\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 merge(left, mid, right):\n \n R = merge_list[mid:right]\n \n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 \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 merge(left, mid, right):\n \n R = merge_list[mid:right]\n \n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 \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 merge(left, mid, right):\n \n R = merge_list[mid:right]\n \n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 \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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n \n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 \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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in range(left, right):\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in range(left, right):\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nis_stable = True\nfor i in range(N):\n if A[i][0] != merge_list[i][0]:\n print(\"Not stable\")\n is_stable = False\n break\nif is_stable:\n print(\"Stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\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", "a = []\n", "a = []\n\n\nfor i in a:\n", "import copy\n\n\na = []\n\n\nfor i in a:\n", "import copy\n\n\ndef quickSort:\n \n\na = []\n\n\nfor i in a:\n", "import copy\n\n\ndef quickSort:\n \n\na = []\n\nb = copy.deepcopy(a)\n\n\nfor i in a:\n", "import copy\n\n\ndef quickSort:\n \n\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\n\nfor i in a:\n", "import copy\n\n\ndef quickSort:\n \n\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\n\n\ndef quickSort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quickSort(a, p, r):\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quickSort(a, p, r):\n \n\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\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\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\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\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\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\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\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\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\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\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\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\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 \n return(i+1)\n\ndef quickSort(a, p, r):\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 = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 \n return(i+1)\n\ndef quickSort(a, p, r):\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 = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\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 = []\nfor i in range(n):\n a.append(list(input().split()))\n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 += 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\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\nquickSort(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 += 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\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\nquickSort(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", "A = []\n", "A = []\n\nfor i in range(n):\n", "n = int(input())\n\nA = []\n\nfor i in range(n):\n", "n = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n", "Card = namedtuple('Card', ['suit', 'value', 'init'])\n\n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n", "Card = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n", "Card = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\n\nfor a in A:\n", "from import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\n\nfor a in A:\n", "from import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n\nQuickSort(A, 0, n)\n\nfor i in :\n \n\nfor a in A:\n", "from import \n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\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 import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\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 import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\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 import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort:\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n \nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n \nelse:\n \n\nfor a in A:\n", "from import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n \nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n \nelse:\n \n\nfor a in A:\n", "from collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n \nQuickSort(A, 0, n)\n\nfor i in range(n - 1):\n \nelse:\n \n\nfor a in A:\n", "from collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(input())\n\nA = []\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", "from collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(input())\n\nA = []\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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n left, right = begin, begin\n\n \nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n left, right = begin, begin\n\n \nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\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 print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n left, right = begin, begin\n\n for i in :\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\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 print('Stable')\n\nfor a in A:\n print(a.suit, a.value)\n", "from collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n left, right = begin, begin\n\n for i in :\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\n A.append(Card(suit, 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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n \n\n left, right = begin, begin\n\n for i in :\n \n\n QuickSort(A, begin, left)\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\n A.append(Card(suit, 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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n \n left, right = begin, begin\n\n for i in :\n \n\n QuickSort(A, begin, left)\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n \n value = int(value)\n A.append(Card(suit, 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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n \n left, right = begin, begin\n\n for i in :\n \n\n QuickSort(A, begin, left)\n \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 collections import namedtuple\n\nCard = namedtuple('Card', ['suit', 'value', 'init'])\n\ndef QuickSort(A, begin, end):\n if :\n return\n\n \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 \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 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 \n\nn = int(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 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(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 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 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(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 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 :\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(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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 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(input())\n\nA = []\n\nfor i in range(n):\n suit, value = input().split()\n value = int(value)\n A.append(Card(suit, 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", "#coding:utf-8\n\n\nA = []\n", "#coding:utf-8\n\n\nA = []\n\n\ndef quickSort:\n", "#coding:utf-8\n\n\nA = []\n\n\ndef quickSort:\n \n\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\n\nA = []\n\n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\nn = int(input())\nA = []\n\n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\nn = int(input())\nA = []\n\n\ndef Merge:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\nn = int(input())\nA = []\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\nn = int(input())\nA = []\n\n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n", "#coding:utf-8\n\nn = int(input())\nA = []\n\n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\n\n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\n\n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\n\n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n\nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge:\n \n\ndef MergeSort:\n \n\ndef partition:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge:\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:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\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:\n \n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\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:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\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-1\n \n return i\n\n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\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-1\n \n return i\n\n\ndef quickSort:\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\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-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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\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\n\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\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\n\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \nelse:\n \n\nfor a in A:\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\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\n\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n \nelse:\n \n\nfor a in A:\n \n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\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\n\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n \n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\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\n\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n \n i,j = 0,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-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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n \n \nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n \n L.append([\"S\",2000000000])\n \n i,j = 0,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-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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n \n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n \n L.append([\"S\",2000000000])\n \n i,j = 0,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-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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n \n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n \n L.append([\"S\",2000000000])\n \n i,j = 0,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\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n \n L.append([\"S\",2000000000])\n \n i,j = 0,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\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append([\"S\",2000000000])\n \n i,j = 0,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\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\n i,j = 0,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\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\n i,j = 0,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\ndef 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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\n i,j = 0,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\ndef partition(A, p, r):\n x = A[r-1][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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n \n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n \n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\n i,j = 0,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\ndef partition(A, p, r):\n x = A[r-1][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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\n i,j = 0,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\ndef partition(A, p, r):\n x = A[r-1][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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\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 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][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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\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 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][1]\n i = p-1\n for j in range(p, r):\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)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\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 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][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 return i\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\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 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][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 return i\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\n", "#coding:utf-8\nfrom copy import deepcopy\nn = int(input())\nA = []\nfor i in range(n):\n ch, num = input().split()\n A.append([ch, int(num)])\n\nB = deepcopy(A)\n\n\n\ndef Merge(A, left, mid, right):\n L = A[left:mid]\n R = A[mid:right]\n L.append([\"S\",2000000000])\n R.append([\"S\",2000000000])\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 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\n\ndef partition(A, p, r):\n x = A[r-1][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 return i\n\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q)\n quickSort(A, q+1, r)\n\n\n\n\n\nquickSort(A, 0, n)\nMergeSort(B, 0, n)\n\nif A == B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor a in A:\n a = \" \".join([a[0],str(a[1])])\n print(a)\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", "mergesort(A_M, 0, n)\n", "mergesort(A_M, 0, n)\n\n\nif :\n", "def mergesort:\n \n\nmergesort(A_M, 0, n)\n\n\nif :\n", "def merge:\n \n\ndef mergesort:\n \n\nmergesort(A_M, 0, n)\n\n\nif :\n", "def merge:\n \n\ndef mergesort:\n \n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nif :\n", "import copy\n\n\ndef merge:\n \n\ndef mergesort:\n \n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nif :\n", "import copy\n\n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nif :\n", "import copy\n\ndef partition:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nif :\n", "import copy\n\ndef partition:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n", "import copy\n\ndef partition:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\n\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\n\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\n\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif :\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort:\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n \n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\n\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n i = p-1\n \n\ndef quicksort:\n \n\ndef merge:\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition:\n \n i = p-1\n \n\ndef quicksort:\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort:\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition(A, p, r):\n \n i = p-1\n \n\ndef quicksort(A, p, r):\n \n\ndef merge(A, left, mid, right):\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\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\n\ndef merge(A, left, mid, right):\n \n \ndef mergesort(A, left, right):\n \n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\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\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef 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\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n \nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef 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\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef 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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [(\"J\", 1000000000) ]\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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef 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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef 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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\n\ndef quicksort(A, p, r):\n 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] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\n\ndef quicksort(A, p, r):\n 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] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\n i, j = 0, 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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\n\ndef quicksort(A, p, r):\n 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] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\n i, j = 0, 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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\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 merge(A, left, mid, right):\n L = A[left:mid] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\n i, j = 0, 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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\n\ndef partition(A, p, r):\n x = A[r][1]\n i = p-1\n for j in range(p, r):\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 merge(A, left, mid, right):\n L = A[left:mid] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\n i, j = 0, 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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\n\ndef quicksort(A, p, r):\n 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] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\n i, j = 0, 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\n\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\n", "import copy\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\n\ndef quicksort(A, p, r):\n 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] + [(\"J\", 1000000000) ]\n R = A[mid:right] + [(\"J\", 1000000000)]\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 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\nn = int(input())\nA_Q = [input() for _ in range(n)]\nA_Q = [(i.split()[0], int(i.split()[1])) for i in A_Q]\nA_M = copy.deepcopy(A_Q)\n\nquicksort(A_Q, 0, n-1)\nmergesort(A_M, 0, n)\n\nA_Q = [f\"{str(i[0])} {str(i[1])}\"for i in A_Q]\nA_M = [f\"{str(i[0])} {str(i[1])}\"for i in A_M]\nif A_Q == A_M:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nprint(*A_Q, sep=\"\\n\")\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", "a = []\n", "a = []\n\n\nfor i in :\n", "n = int(input())\na = []\n\n\nfor i in :\n", "import copy\n\n\nn = int(input())\na = []\n\n\nfor i in :\n", "import copy\n\n\nn = int(input())\na = []\n\nb = copy.deepcopy(a)\n\n\nfor i in :\n", "import copy\n\n\ndef quickSort:\n \nn = int(input())\na = []\n\nb = copy.deepcopy(a)\n\n\nfor i in :\n", "import copy\n\n\ndef quickSort:\n \nn = int(input())\na = []\n\nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \nn = int(input())\na = []\n\nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in :\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(a, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\n \n\ndef quickSort:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition:\n \n\ndef quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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\n\n\nfor i in a:\n print(\" \".join(map(str,i)))\n", "import copy\ndef partition(a, p, r):\n \n\ndef quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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\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 quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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\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 quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n \nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 \n \n return(i+1)\n\ndef quickSort(a, p, r):\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 \n \n return(i+1)\n\ndef quickSort(a, p, r):\n if p<r:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 \n \n return(i+1)\n\ndef quickSort(a, p, r):\n if p<r:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 \n return(i+1)\n\ndef quickSort(a, p, r):\n if p<r:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\n if p<r:\n \n\n #รับ input\nn = int(input())\na = []\nfor i in range(n):\n \n a[i][1]=int(a[i][1])\nb = copy.deepcopy(a)\n\nquickSort(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 quickSort(a, p, r):\n if p<r:\n \n\n #รับ input\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\nquickSort(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 quickSort(a, p, r):\n if p<r:\n \n \n #รับ input\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\nquickSort(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 quickSort(a, p, r):\n if p<r:\n \n \n #รับ input\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\nquickSort(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 += 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 \n \n #รับ input\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\nquickSort(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 += 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 \n \n #รับ input\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\nquickSort(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 += 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 \n\n #รับ input\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\nquickSort(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 += 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\n #รับ input\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\nquickSort(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" ]
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", "B = A[:]\n\n\njuge = 1\n", "B = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "A = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "def mergeSort:\n \n\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "def mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "def quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "def partition:\n \n\ndef quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\n", "def partition:\n \n\ndef quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n", "def partition:\n \n\ndef quicksort:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n \nif :\n", "def partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n \nif :\n", "def partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\n\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n \nif :\n \n\nfor i in range(n):\n", "def partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n \nif :\n \n\nfor i in range(n):\n", "def partition:\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif :\n \n\nfor i in range(n):\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif :\n \n\nfor i in range(n):\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif :\n print(\"Stable\")\n\n\nfor i in range(n):\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif :\n print(\"Stable\")\n\n\nfor i in range(n):\n", "def partition(A, p, r):\n \n\ndef quicksort:\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\n\n\nfor i in range(n):\n", "def partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\n\n\nfor i in range(n):\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 merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\n\n\nfor i in range(n):\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 merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\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\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\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\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\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\ndef merge(A, left, mid, right):\n \n\ndef mergeSort(A, left, right):\n \n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\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\n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\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\n\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\n i = 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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\n i = 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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\n i = 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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n \n R = A[mid:right] + [[0,1000000001]]\n i = 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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[0,1000000001]]\n R = A[mid:right] + [[0,1000000001]]\n i = 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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[0,1000000001]]\n R = A[mid:right] + [[0,1000000001]]\n i = j = 0\n for k in :\n if int(L[i][1]) <= int(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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[0,1000000001]]\n R = A[mid:right] + [[0,1000000001]]\n i = j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[i]))\n", "def partition(A, p, r):\n x = A[r]\n i = p-1\n for j in :\n if int(A[j][1]) <= int(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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[0,1000000001]]\n R = A[mid:right] + [[0,1000000001]]\n i = j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(A[i]))\n", "def partition(A, p, r):\n x = A[r]\n i = p-1\n for j in range(p,r):\n if int(A[j][1]) <= int(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\ndef merge(A, left, mid, right):\n L = A[left:mid] + [[0,1000000001]]\n R = A[mid:right] + [[0,1000000001]]\n i = j = 0\n for k in range(left, right):\n if int(L[i][1]) <= int(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\nn = int(input())\nA = [input().split() for i in range(n)]\nB = A[:]\nquicksort(A, 0, n-1)\nmergeSort(B, 0, n)\n\njuge = 1\nfor i in range(n):\n if A[i] != B[i]:\n juge = 0\n break\nif juge == 1:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(\" \".join(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", "n = int(input())\nA = []\n", "n = int(input())\nA = []\n\n\nquickSort(A, 0, len(A) - 1)\n", "n = int(input())\nA = []\n\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n", "def quickSort:\n \n\nn = int(input())\nA = []\n\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n", "def quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition:\n \n\ndef quickSort:\n \n\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n \n \nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n \n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n for index, a in :\n \n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(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\ndef IsStable(A):\n for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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 for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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 for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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 index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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 index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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\n\ndef IsStable(A):\n for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n \n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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\n\ndef IsStable(A):\n for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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\n\ndef IsStable(A):\n for index, a in :\n \n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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\n\ndef IsStable(A):\n for index, a in :\n for i in range(index, len(A)):\n if (a[2] == A[i][2]) and (a[0] > A[i][0]):\n return \"Not stable\"\n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\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\n\ndef IsStable(A):\n for index, a in enumerate(A):\n for i in range(index, len(A)):\n if (a[2] == A[i][2]) and (a[0] > A[i][0]):\n return \"Not stable\"\n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\n i = p - 1\n\n for j in range(p, r):\n if A[j][2] <= 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\n\ndef IsStable(A):\n for index, a in enumerate(A):\n for i in range(index, len(A)):\n if (a[2] == A[i][2]) and (a[0] > A[i][0]):\n return \"Not stable\"\n\n return \"Stable\"\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\n", "def partition(A, p, r):\n x = A[r][2]\n i = p - 1\n\n for j in range(p, r):\n if A[j][2] <= 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\n\ndef IsStable(A):\n for index, a in enumerate(A):\n for i in range(index, len(A)):\n if (a[2] == A[i][2]) and (a[0] > A[i][0]):\n return \"Not stable\"\n\n return \"Stable\"\n\n\n\nn = int(input())\nA = []\nfor i in range(n):\n a, b = input().split()\n A.append([i, a, int(b)])\n\nquickSort(A, 0, len(A) - 1)\n\nprint(IsStable(A))\n[print(\"{} {}\".format(A[i][1], A[i][2])) for i in range(len(A))]\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", "A = []\n", "N = int(input())\nA = []\n", "def merge_sort:\n \n\nN = int(input())\nA = []\n", "def partition(p, r):\n \n\ndef merge_sort:\n \n\nN = int(input())\nA = []\n", "def partition(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n\n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n\n\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\n\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n\ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge:\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n \n\nfor card in A:\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n print(\"Stable\")\n\n\nfor card in A:\n", "def partition(p, r):\n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n \n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n print(\"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 \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n print(\"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 \n\ndef merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n print(\"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 merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif :\n print(\"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 merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\n print(\"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 merge(left, mid, right):\n \n \ndef merge_sort:\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n \n \ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n \nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n \n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n \n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n \n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 \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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n \n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in :\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\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 merge(left, mid, right):\n L = merge_list[left:mid]\n R = merge_list[mid:right]\n L.append([\"\", INFTY])\n R.append([\"\", INFTY])\n i, j = 0, 0\n for k in range(left, right):\n if L[i][1] <= R[j][1]:\n merge_list[k] = L[i]\n i += 1\n else:\n merge_list[k] = R[j]\n j += 1\n\ndef merge_sort(left, right):\n if left+1 < right:\n mid = int( (left+right)/2 )\n merge_sort(left, mid)\n merge_sort(mid, right)\n merge(left, mid, right)\n\nINFTY = 1000000001\n\nN = int(input())\nA = []\nfor _ in range(N):\n suit, num = input().split()\n num = int(num)\n A.append([suit, num])\nmerge_list = A[:]\n\nquick_sort(0, N-1)\nmerge_sort(0, N)\n\nif A == merge_list:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in A:\n print(\"%s %d\" % (card[0], card[1]))\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", "a = []\n", "def checkstable(a):\n \n\na = []\n", "def checkstable(a):\n \n\na = []\nfor i in range(n):\n", "def partition:\n \n\ndef checkstable(a):\n \n\na = []\nfor i in range(n):\n", "def partition:\n \n\ndef checkstable(a):\n \n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\n", "def partition:\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\n", "def partition:\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n", "def partition:\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n", "def partition:\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n", "def partition:\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n \n\ndef quicksort:\n \n\ndef checkstable(a):\n \n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\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\ndef checkstable(a):\n \n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\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\ndef checkstable(a):\n \n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\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\ndef checkstable(a):\n \n \nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in 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\ndef checkstable(a):\n \n \nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in 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\ndef checkstable(a):\n \n \nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in 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\ndef checkstable(a):\n \n \nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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\ndef checkstable(a):\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[1])\n", "def partition(a, p, r):\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 checkstable(a):\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[1])\n", "def partition(a, p, r):\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 checkstable(a):\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[1])\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 quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q - 1)\n quicksort(a, q + 1, r)\n\n\ndef checkstable(a):\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[1])\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 quicksort(a, p, r):\n if p < r:\n q = partition(a, p, r)\n quicksort(a, p, q - 1)\n quicksort(a, q + 1, r)\n\n\ndef checkstable(a):\n for i in :\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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 checkstable(a):\n for i in :\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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 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 checkstable(a):\n for i in :\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n \n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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 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 checkstable(a):\n for i in :\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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\ndef checkstable(a):\n for i in :\n \n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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\ndef checkstable(a):\n for i in :\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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\ndef checkstable(a):\n for i in :\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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\ndef checkstable(a):\n for i in range(1, len(a)):\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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 = 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 checkstable(a):\n for i in range(1, len(a)):\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return \"Not stable\"\n return \"Stable\"\n\n\nimport sys\nn = int(input())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(checkstable(a))\n\nfor line in a:\n print(line[0], line[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", "# -*- coding: utf-8 -*-\n", "# -*- coding: utf-8 -*-\n\n\nif :\n", "# -*- coding: utf-8 -*-\n\n\ndef quickSort:\n \n\nif :\n", "# -*- coding: utf-8 -*-\n\n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nif :\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef mergeSort:\n \n\nif :\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif :\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n \n\ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[r]\n \n \ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort:\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[r]\n \n \ndef quickSort:\n \n\ndef merge:\n \n\ndef mergeSort(A, left, right):\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[r]\n \n \ndef quickSort:\n \n\ndef merge:\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[r]\n \n \ndef quickSort:\n \n\ndef merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[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 merge(A, left, mid, right):\n \n \n i = 0\n j = 0\n \n\ndef mergeSort(A, left, right):\n \n\nif __name__ == '__main__':\n", "# -*- coding: utf-8 -*-\n\ndef partition:\n x = A[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 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", "# -*- coding: utf-8 -*-\n\ndef partition:\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\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", "# -*- coding: utf-8 -*-\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\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", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n \n \n L = A[left:left+n1]\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", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n \n \n L = A[left:left+n1]\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 \n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n \n \n L = A[left:left+n1]\n R = A[mid:mid+n2]\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 \n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n \n \n L = A[left:left+n1]\n R = A[mid:mid+n2]\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\n\nif __name__ == '__main__':\n\n \n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n n1 = mid - left\n \n L = A[left:left+n1]\n R = A[mid:mid+n2]\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\n\nif __name__ == '__main__':\n\n \n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\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\n\nif __name__ == '__main__':\n\n \n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n mergeSort(A_m, 0, n)\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n A_m = [(a[0], int(a[1])) for a in A]\n \n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\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\n\nif __name__ == '__main__':\n\n n = int(input())\n \n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n \n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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 merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n \n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if :\n \n \n for a in A_q:\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[r]\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\ndef merge(A, left, mid, right):\n n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if :\n \n \n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if :\n \n \n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n \n \n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n \n else:\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\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\n\nif __name__ == '__main__':\n\n n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n \n else:\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\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\n\nif __name__ == '__main__':\n\n n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n \n\n for a in A_q:\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\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\n\nif __name__ == '__main__':\n\n n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n \n\n for a in A_q:\n print(a[0], a[1])\n", "# -*- coding: utf-8 -*-\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] = 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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\n i = 0\n j = 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 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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n \n\n for a in A_q:\n print(a[0], a[1])\n", "# -*- coding: utf-8 -*-\n\ndef partition(A, p, r):\n x = A[r]\n i = p - 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\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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\n i = 0\n j = 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 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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n \n\n for a in A_q:\n print(a[0], a[1])\n", "# -*- coding: utf-8 -*-\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\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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\n i = 0\n j = 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 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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n \n\n for a in A_q:\n print(a[0], a[1])\n", "# -*- coding: utf-8 -*-\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\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 n1 = mid - left\n n2 = right - mid\n L = A[left:left+n1]\n R = A[mid:mid+n2]\n L.append([None, float('inf')])\n R.append([None, float('inf')])\n\n i = 0\n j = 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 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 n = int(input())\n A = [input().split(\" \") for _ in range(n)]\n\n A_m = [(a[0], int(a[1])) for a in A]\n A_q = [(a[0], int(a[1])) for a in A]\n\n mergeSort(A_m, 0, n)\n quickSort(A_q, 0, n-1)\n\n if A_m == A_q:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n\n for a in A_q:\n print(a[0], a[1])\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", "for i in range(n):\n", "def quickSort:\n \n\nfor i in range(n):\n", "def quickSort:\n \n\nfor i in range(n):\n \n\nif :\n", "def quickSort:\n \n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\n\ndef quickSort:\n \n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef quickSort:\n \n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef quickSort:\n \n\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef quickSort:\n \n\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif :\n \n\nfor i in range(n):\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n", "import sys\n\nclass Card:\n \n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n\nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n \nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n \n\ndef partition(A, p, r):\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(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n \n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n \nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n \n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n \n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\n\ndef partition(A, 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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\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 return i + 1\n\ndef quickSort(A, p, 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(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\n\ndef 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 return i + 1\n\ndef quickSort(A, p, 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(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in :\n \n\n return True\n\ndef partition(A, p, r):\n x = A[r].num\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in range(n - 1):\n \n\n return True\n\ndef partition(A, p, r):\n x = A[r].num\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in range(n - 1):\n \n\n return True\n\ndef partition(A, p, r):\n x = A[r].num\n i = p - 1\n\n for j in :\n if A[j].num <= x:\n i += 1\n A[j], A[i] = A[i], A[j]\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in range(n - 1):\n \n\n return True\n\ndef partition(A, p, r):\n x = A[r].num\n i = p - 1\n\n for j in range(p, r):\n if A[j].num <= x:\n i += 1\n A[j], A[i] = A[i], A[j]\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\n", "import sys\n\nclass Card:\n def __init__(self, s, n, i):\n self.suit = s\n self.num = n\n self.ini_ord = i\n\ndef is_stable(A, n):\n for i in range(n - 1):\n if A[i].num == A[i + 1].num:\n if A[i].ini_ord > A[i + 1].ini_ord:\n return False\n\n return True\n\ndef partition(A, p, r):\n x = A[r].num\n i = p - 1\n\n for j in range(p, r):\n if A[j].num <= x:\n i += 1\n A[j], A[i] = A[i], A[j]\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\nn = int(sys.stdin.readline().rstrip())\ncards = []\n\nfor i in range(n):\n line = sys.stdin.readline().split()\n cards.append(Card(line[0], int(line[1]), i))\n\nquickSort(cards, 0, n - 1)\n\nif is_stable(cards, n):\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(cards[i].suit,str(cards[i].num))\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", "import sys\n\na = []\n", "import sys\n\na = []\n\n\nquicksort(a, 0, len(a) - 1)\n", "import sys\n\na = []\n\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n", "import sys\n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n", "def partition:\n \n\nimport sys\n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n", "def partition:\n \n\ndef check_stable(a):\n \n\nimport sys\n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n", "def partition:\n \n\ndef check_stable(a):\n \n\nimport sys\n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef check_stable(a):\n \n\nimport sys\n\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition:\n \n\ndef quicksort:\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n \n\ndef quicksort:\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n \n\ndef quicksort(a, p, r):\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n \n\ndef quicksort(a, p, r):\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, r):\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, r):\n \n\ndef check_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n \n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n \n \nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n \nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n \nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n \nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n \n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n \n \n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n \n a[q], a[r] = a[r], a[q]\n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n if a[i][1] <= a[r][1]:\n a[q], a[i] = a[i], a[q]\n q += 1\n a[q], a[r] = a[r], a[q]\n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in :\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n if a[i][1] <= a[r][1]:\n a[q], a[i] = a[i], a[q]\n q += 1\n a[q], a[r] = a[r], a[q]\n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in range(1, len(a)):\n \n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in :\n if a[i][1] <= a[r][1]:\n a[q], a[i] = a[i], a[q]\n q += 1\n a[q], a[r] = a[r], a[q]\n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in range(1, len(a)):\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return 'Not stable'\n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\n", "def partition(a, p, r):\n q = p\n for i in range(p, r):\n if a[i][1] <= a[r][1]:\n a[q], a[i] = a[i], a[q]\n q += 1\n a[q], a[r] = a[r], a[q]\n return q\n\ndef quicksort(a, p, 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_stable(a):\n for i in range(1, len(a)):\n if a[i - 1][1] == a[i][1]:\n if a[i - 1][2] > a[i][2]:\n return 'Not stable'\n return 'Stable'\n\nimport sys\nn = int(sys.stdin.readline())\na = []\nfor i in range(n):\n suit, num = sys.stdin.readline().split()\n a += [[suit, int(num), i]]\n\nquicksort(a, 0, len(a) - 1)\nprint(check_stable(a))\n\nfor line in a:\n print(line[0],line[1])\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", "def mergeSort:\n", "def mergeSort:\n \n\nfor i in range(n):\n", "def mergeSort:\n \n\nA=[input().split() for _ in range(n)]\n\n\nfor i in range(n):\n", "def mergeSort:\n \n\ndef partition(A,p,r):\n \n\nA=[input().split() for _ in range(n)]\n\n\nfor i in range(n):\n", "def mergeSort:\n \n\ndef partition(A,p,r):\n \n\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\n\nfor i in range(n):\n", "def mergeSort:\n \n\ndef partition(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\n\nfor i in range(n):\n", "INFTY=1000000000\n\n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\n\n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\n\n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\n\n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\n\n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\n\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\n\n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\n\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\n\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n\ndef mergeSort:\n \n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\ndef merge:\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n \n i=0\n j=0\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=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \n\nfor i in range(n):\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n \n i=0\n j=0\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=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n \n i=0\n j=0\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=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge:\n \n \n i=0\n j=0\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 \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n i=0\n j=0\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 \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n \nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n i=0\n j=0\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 \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n i=0\n j=0\n \n \ndef mergeSort(A,left,right):\n \n return 0\n\ndef partition(A,p,r):\n \n i=p-1\n \n \ndef quickSort(A,p,r):\n \n\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n i=0\n j=0\n \n \ndef mergeSort(A,left,right):\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n \n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n i=0\n j=0\n \n \ndef mergeSort(A,left,right):\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\n \n \ndef mergeSort(A,left,right):\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\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 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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n \n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\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 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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\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 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())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n \n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n \n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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 \n\ndef quickSort(A,p,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=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in :\n \n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in :\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in :\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if :\n \n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n \n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n \n \n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n \n \n return merge(A,left,mid,right)+t2+t1\n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n \n t1=mergeSort(A,left,mid)\n \n return merge(A,left,mid,right)+t2+t1\n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n mid=(left+right)//2\n t1=mergeSort(A,left,mid)\n \n return merge(A,left,mid,right)+t2+t1\n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\n", "import copy\n\nINFTY=1000000000\ndef merge(A,left,mid,right):\n n1=mid-left\n n2=right-mid\n L=[ A[left+i] for i in range(n1)]\n R=[ A[mid+i] for i in range(n2)]\n L.append((INFTY,INFTY))\n R.append((INFTY,INFTY))\n i=0\n j=0\n for k in range(left,right):\n if int(L[i][1])<=int(R[j][1]):\n A[k]=L[i]\n i+=1\n else:\n A[k]=R[j]\n j+=1\n return right-left\n\ndef mergeSort(A,left,right):\n if left+1<right:\n mid=(left+right)//2\n t1=mergeSort(A,left,mid)\n t2=mergeSort(A,mid,right)\n return merge(A,left,mid,right)+t2+t1\n return 0\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\nn=int(input())\nA=[input().split() for _ in range(n)]\nB=copy.deepcopy(A)\n\nquickSort(A,0,n-1)\nmergeSort(B,0,n)\nif A==B:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(' '.join(A[i]))\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", "def isStable:\n", "def isStable:\n \n\nif :\n main()\n", "def main() :\n \n\ndef isStable:\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n \n\ndef isStable:\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n \n\ndef isStable:\n \n\nclass Card():\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n \n\ndef partion :\n \n\ndef isStable:\n \n\nclass Card():\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n \n\ndef partion :\n \n i = p\n \n \ndef isStable:\n \n\nclass Card():\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion :\n \n i = p\n \n \ndef isStable:\n \n\nclass Card():\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable:\n \n\nclass Card():\n \n\nif :\n main()\n", "def main() :\n \n\ndef quickSort :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable:\n \n\nclass Card():\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n\ndef quickSort :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \ndef quickSort :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n \n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n \ndef isStable(a, b, n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n cards = [Card(*input().split()) for i in range(n)]\n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n \n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n cards = [Card(*input().split()) for i in range(n)]\n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n cards = [Card(*input().split()) for i in range(n)]\n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n \n cards = [Card(*input().split()) for i in range(n)]\n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n \n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n \n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n \n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n\n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n \n def print_card(self):\n \n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__:\n \n \n def print_card(self):\n print(self.prefix, self.number)\n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__(self, prefix, number):\n \n \n def print_card(self):\n print(self.prefix, self.number)\n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in range(p, r + 1) :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__(self, prefix, number):\n \n \n def print_card(self):\n print(self.prefix, self.number)\n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in range(p, r + 1) :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__(self, prefix, number):\n self.prefix = prefix\n \n\n def print_card(self):\n print(self.prefix, self.number)\n\nif __name__ == '__main__':\n main()\n", "def main() :\n n = int(input())\n cards = [Card(*input().split()) for i in range(n)]\n stableCards = sorted(cards[:], key=lambda c: c.number)\n quickSort(cards, 0, n - 1)\n print(isStable(cards, stableCards, n))\n list(map(lambda i : i.print_card(), cards))\n\ndef quickSort(cards, p, r) :\n if p < r:\n q = partion(cards, p, r)\n quickSort(cards, p, q - 1)\n quickSort(cards, q + 1, r)\n\ndef partion(cards, p, r) :\n x = cards[r]\n i = p\n for j in range(p, r + 1) :\n if int(cards[j].number) <= int(x.number) :\n cards[i], cards[j] = cards[j], cards[i]\n i += 1\n return i - 1\n\ndef isStable(a, b, n):\n for i in range(n):\n if a[i].prefix != b[i].prefix:\n return 'Not stable'\n\n return 'Stable'\n\nclass Card():\n def __init__(self, prefix, number):\n self.prefix = prefix\n self.number = number\n\n def print_card(self):\n print(self.prefix, self.number)\n\nif __name__ == '__main__':\n main()\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", "a=[]\n", "import copy\n\n\na=[]\n", "import copy\n\n\na=[]\n\n\nfor i in b:\n", "import copy\n\n\na=[]\n\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\n\na=[]\n\n\nquicksort(b,1,n)\n\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\n\ndef quicksort(A,p,r):\n \n\na=[]\n\n\nquicksort(b,1,n)\n\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\n\ndef quicksort(A,p,r):\n \n\na=[]\n\n\nquicksort(b,1,n)\nflag=True\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\n\ndef quicksort(A,p,r):\n \n\na=[]\nfor i in range(n):\n \n\nquicksort(b,1,n)\nflag=True\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\na=[]\nfor i in range(n):\n \n\nquicksort(b,1,n)\nflag=True\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n \n\nquicksort(b,1,n)\nflag=True\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n \n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\n\nif flag:\n\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n \n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:\n\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n \n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:\nelse:print('Not stable')\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n \n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n", "import copy\n\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n \n \n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n \n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n \n \n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n \nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n \n \n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in :\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n \n \n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in range(n-1):\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n for j in :\n \n \n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in range(n-1):\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n for j in :\n \n A[r-1]=A[i]\n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in range(n-1):\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n for j in range(p-1,r-1):\n \n A[r-1]=A[i]\n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in range(n-1):\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\n", "import copy\n\ndef partition(A,p,r):\n x=A[r-1]\n i=p-1\n for j in range(p-1,r-1):\n if int(A[j][1])<=int(x[1]):\n A_j=A[j]\n A[j]=A[i]\n A[i]=A_j\n i+=1\n A[r-1]=A[i]\n A[i]=x\n return i\n\ndef quicksort(A,p,r):\n if p<r:\n q=partition(A,p,r)\n quicksort(A,p,q)\n quicksort(A,q+1,r)\n\n\nn=int(input())\na=[]\nfor i in range(n):\n a.append(input().split())\n\nb=copy.deepcopy(a)\nquicksort(b,1,n)\nflag=True\nfor j in range(n-1):\n if int(b[j][1]) == int(b[j+1][1]):\n if a.index(b[j]) > a.index(b[j+1]):flag=False ;break\nif flag:print('Stable')\nelse:print('Not stable')\n\nfor i in b:\n print(*i)\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", "n=int(input())\n", "n=int(input())\n\nk(A,0,n-1)\n", "n=int(input())\n\nk(A,0,n-1)\n\nprint(\"\\n\".join(f\"{a} {b}\"for a,b,_ in A))\n", "n=int(input())\n\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\"for a,b,_ in A))\n", "def t(A,p,r):\n \n\nn=int(input())\n\nk(A,0,n-1)\nprint(s(A)+'table')\nprint(\"\\n\".join(f\"{a} {b}\"for a,b,_ in A))\n", "def t(A,p,r):\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", "def t(A,p,r):\n \ndef k(A,p,r):\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", "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)\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 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,_ 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,_ 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 \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 ;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 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 ;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'\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 \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)\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 \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 \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 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)\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 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 \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 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", "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 quick_sort(p, r):\n", "input = sys.stdin.readline\n\n\ndef quick_sort(p, r):\n", "from copy import deepcopy\ninput = sys.stdin.readline\n\n\ndef quick_sort(p, r):\n", "from copy import deepcopy\ninput = sys.stdin.readline\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n \n\nif :\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n \n \n return\n\nif :\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n \n \n return\n\nif :\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef is_stable:\n \n \n return\n\nif __name__ == \"__main__\":\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n i = p\n \n \n return i\n\ndef quick_sort(p, r):\n \n\ndef is_stable(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n \n i = p\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(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 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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(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 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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n \n A = [input().split() for _ in range(n)]\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n \n A = [input().split() for _ in range(n)]\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n \n \n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n \n \n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n \n \n is_stable(A_original, A)\n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n \n is_stable(A_original, A)\n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n \n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n print(\"Stable\")\n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n \n print(\"Stable\")\n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n print(\"{} {}\".format(key, val))\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\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(original_list, sorted_list):\n for key, val in sorted_list:\n for original_key, original_val in original_list[:]:\n if val == original_val:\n if key != original_key:\n print(\"Not stable\")\n return\n original_list.remove([original_key, original_val])\n break\n print(\"Stable\")\n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n print(\"{} {}\".format(key, val))\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\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 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(original_list, sorted_list):\n for key, val in sorted_list:\n for original_key, original_val in original_list[:]:\n if val == original_val:\n if key != original_key:\n print(\"Not stable\")\n return\n original_list.remove([original_key, original_val])\n break\n print(\"Stable\")\n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n print(\"{} {}\".format(key, val))\n", "import sys\nfrom copy import deepcopy\ninput = sys.stdin.readline\n\ndef partition(p, r):\n x = int(A[r][1])\n i = p\n for j in range(p, r):\n if int(A[j][1]) <= 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 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(original_list, sorted_list):\n for key, val in sorted_list:\n for original_key, original_val in original_list[:]:\n if val == original_val:\n if key != original_key:\n print(\"Not stable\")\n return\n original_list.remove([original_key, original_val])\n break\n print(\"Stable\")\n return\n\nif __name__ == \"__main__\":\n n = int(input())\n A = [input().split() for _ in range(n)]\n A_original = deepcopy(A)\n quick_sort(0, n-1)\n is_stable(A_original, A)\n for key, val in A:\n print(\"{} {}\".format(key, val))\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", "main()\n", "def main():\n\n \nmain()\n", "def quicksort:\n \n\ndef main():\n\n \nmain()\n", "import sys\n\n\ndef quicksort:\n \n\ndef main():\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef quicksort:\n \n\ndef main():\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition:\n\n \ndef quicksort:\n \n\ndef main():\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\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\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\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 main():\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\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 \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\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 \n A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\n\ndef main():\n\n \n A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 main():\n\n \n A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\n\ndef quicksort(A, p, r):\n 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 A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 \n A = []\n\n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 \n A = []\n\n \n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 \n A = []\n\n for i in range(N):\n \n\n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 \n A = []\n\n for i in range(N):\n \n\n for i in :\n \n \n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 \n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n \n \n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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 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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n \n \n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n \n \n for m, n, _ in A:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n \n \n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n \n \n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n\n quicksort(A, 0, N - 1)\n\n for i in :\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n \n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in :\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n \n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in range(1, N):\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n \n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in range(1, N):\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n else:\n \n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n \n # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in range(1, N):\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n m, n = sys.stdin.readline().rstrip().split()\n # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in range(1, N):\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10**6)\n\n\ndef partition(A, p, r):\n\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\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 N = int(sys.stdin.readline().rstrip())\n\n A = []\n\n for i in range(N):\n m, n = sys.stdin.readline().rstrip().split()\n A.append((m, int(n), i)) # stable 確認用に index をつけておく\n\n quicksort(A, 0, N - 1)\n\n for i in range(1, N):\n if A[i][1] == A[i - 1][1]:\n if A[i][2] < A[i - 1][2]:\n print(\"Not stable\")\n break\n else:\n print(\"Stable\")\n\n for m, n, _ in A:\n print(m, n)\n\n\nmain()\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", "A = []\n\n\nquicksort(0, n-1)\n", "A = []\n\n\nquicksort(0, n-1)\n\n\nprint(checkstable())\n", "A = []\n\n\nB = copy.deepcopy(A)\n\n\nquicksort(0, n-1)\n\n\nprint(checkstable())\n", "A = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\n\nquicksort(0, n-1)\n\n\nprint(checkstable())\n", "A = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\n\nprint(checkstable())\n", "A = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\n\nprint(checkstable())\nfor i in A:\n", "n = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\nquicksort(0, n-1)\n\n\nprint(checkstable())\nfor i in A:\n", "n = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\ndef quicksort(p, r):\n \n\nquicksort(0, n-1)\n\n\nprint(checkstable())\nfor i in A:\n", "n = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\ndef quicksort(p, r):\n \n\nquicksort(0, n-1)\n\ndef checkstable():\n \n\nprint(checkstable())\nfor i in A:\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n \n\ndef quicksort(p, r):\n \n\nquicksort(0, n-1)\n\ndef checkstable():\n \n\nprint(checkstable())\nfor i in A:\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\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\nquicksort(0, n-1)\n\ndef checkstable():\n \n\nprint(checkstable())\nfor i in A:\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n \n\nprint(checkstable())\nfor i in A:\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n \n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n \n \nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n \nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n \n \nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n \n \nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n \n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n \nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n \nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n \n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n \n A[i], A[r] = A[r], A[i]\n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n \n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n x, y = input().split()\n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n \n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n x, y = input().split()\n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in :\n if A[i]['num'] == A[i+1]['num']:\n if B.index(A[i]) > B.index(A[i+1]):\n return 'Not stable'\n break\n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n x, y = input().split()\n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n for j in :\n \n A[i], A[r] = A[r], A[i]\n return 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\nquicksort(0, n-1)\n\ndef checkstable():\n for i in range(n-1):\n if A[i]['num'] == A[i+1]['num']:\n if B.index(A[i]) > B.index(A[i+1]):\n return 'Not stable'\n break\n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n x, y = input().split()\n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, 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(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\nquicksort(0, n-1)\n\ndef checkstable():\n for i in range(n-1):\n if A[i]['num'] == A[i+1]['num']:\n if B.index(A[i]) > B.index(A[i+1]):\n return 'Not stable'\n break\n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\n", "import copy\n\nn = int(input())\nA = []\n\nfor i in range(n):\n x, y = input().split()\n z = {'mark': x, 'num': int(y)}\n A.append(z)\n\nB = copy.deepcopy(A)\n\ndef partition(p, r):\n i = p\n for j in range(p, r):\n if A[j]['num'] <= A[r]['num']:\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(p, r):\n if p < r:\n q = partition(p, r)\n quicksort(p, q-1)\n quicksort(q+1, r)\n\nquicksort(0, n-1)\n\ndef checkstable():\n for i in range(n-1):\n if A[i]['num'] == A[i+1]['num']:\n if B.index(A[i]) > B.index(A[i+1]):\n return 'Not stable'\n break\n return 'Stable'\n\nprint(checkstable())\nfor i in A:\n print(i['mark'], i['num'])\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", "B=A[:]\n", "B=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "def t(A,p,r):\n \n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "import sys\ndef t(A,p,r):\n \n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "import sys\ndef t(A,p,r):\n \n\ndef d(A):\n\n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "import sys\ndef t(A,p,r):\n \n\ndef d(A):\n\n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \n\ndef d(A):\n\nf=lambda x,y:(x,int(y))\n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \n\ndef d(A):\n\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \n\ndef d(A):\n\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \n\ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\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 m(L,R):\n T=[]\n \n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e 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 m(L,R):\n T=[]\n \n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "import sys\ndef t(A,p,r):\n x=A[r][1];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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while :\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while R and R[-1][1]>=l[1]:\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while R and R[-1][1]>=l[1]:T+=[R.pop()]\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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", "B=A[:]\n", "B=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "f=lambda x,y:(x,int(y))\n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\n", "f=lambda x,y:(x,int(y))\n\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "f=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def k(A,p,r):\n \n\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def k(A,p,r):\n \ndef m(L,R):\n \n\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\n\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def k(A,p,r):\n \ndef m(L,R):\n \n\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def k(A,p,r):\n \ndef m(L,R):\n \n\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def t(A,p,r):\n x=A[r][1];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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def t(A,p,r):\n x=A[r][1];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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n while :\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n while R and R[-1][1]>=l[1]:\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "def 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 m(L,R):\n T=[]\n for l in L[::-1]:\n while R and R[-1][1]>=l[1]:T+=[R.pop()]\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[f(*input().split())for _ in[0]*n]\nB=A[:]\nk(A,0,n-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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", "S = []\n", "n = int(input())\nS = []\n", "n = int(input())\nS = []\nfor _ in range(n):\n", "n = int(input())\nS = []\nfor _ in range(n):\n \n\nfor j in S:\n", "n = int(input())\nS = []\nfor _ in range(n):\n \n\nfor i in :\n \n\nfor j in S:\n", "def quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\n\ndef quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\n\ndef quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\n\ndef quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\ndef partition:\n \n\ndef quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\ndef partition:\n x = A[r]\n i = p-1\n \n\ndef quicksort:\n \n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\ndef partition:\n x = A[r]\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)\n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in :\n \n\nfor j in S:\n", "import copy\n\ndef partition:\n x = A[r]\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)\n\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor j in S:\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor j in S:\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n \n\nfor j in S:\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n \nelse:\n \n\nfor j in S:\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor j in S:\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\nn = int(input())\nS = []\nfor _ in range(n):\n \n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\ndef quicksort(A, p, 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())\nS = []\nfor _ in range(n):\n \n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n \n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\ndef quicksort(A, p, 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())\nS = []\nfor _ in range(n):\n \n \ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\ndef quicksort(A, p, 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())\nS = []\nfor _ in range(n):\n \n S.append([a, int(b)])\ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\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\ndef quicksort(A, p, 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())\nS = []\nfor _ in range(n):\n a, b = map(str, input().split())\n S.append([a, int(b)])\ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\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] = 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())\nS = []\nfor _ in range(n):\n a, b = map(str, input().split())\n S.append([a, int(b)])\ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\n", "import copy\n\ndef partition(A, p, r):\n x = A[r]\n i = p-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\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())\nS = []\nfor _ in range(n):\n a, b = map(str, input().split())\n S.append([a, int(b)])\ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\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 A[j][1] <= x[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 return i + 1\n\ndef quicksort(A, p, 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())\nS = []\nfor _ in range(n):\n a, b = map(str, input().split())\n S.append([a, int(b)])\ncopyS = copy.deepcopy(S)\n\nquicksort(S, 0, n-1)\n\nfor i in range(n-1):\n if S[i][1] == S[i+1][1]:\n if copyS.index(S[i]) > copyS.index(S[i+1]):\n print(\"Not stable\")\n break\nelse:\n print(\"Stable\")\n\nfor j in S:\n print(\" \".join(str(a) for a in j))\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", "if :\n", "def isStable(A,n):\n \n\nif :\n", "def quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n\nif :\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\n\n\ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n\nif :\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n\nif :\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n \nif :\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n \n\ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n \n A = []\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n x = A[r]\n i = p-1\n \n \ndef quicksort(A,p,r):\n \n\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n \n A = []\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n \n A = []\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n \n A = []\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n \nif __name__ == '__main__':\n \n A = []\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n return True\n\nif __name__ == '__main__':\n \n A = []\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n return True\n\nif __name__ == '__main__':\n \n A = []\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef isStable(A,n):\n \n return True\n\nif __name__ == '__main__':\n \n A = []\n for i in :\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef quicksort(A,p,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 return True\n\nif __name__ == '__main__':\n \n A = []\n for i in :\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef quicksort(A,p,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 for i in :\n \n return True\n\nif __name__ == '__main__':\n \n A = []\n for i in :\n \n \n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef quicksort(A,p,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 for i in :\n \n return True\n\nif __name__ == '__main__':\n \n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef quicksort(A,p,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 for i in :\n \n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\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\ndef quicksort(A,p,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 for i in :\n \n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????1?????§????????¢??????????????°???????????¨?????????\n'''\ndef partition(A,p,r):\n x = A[r]\n i = p-1\n for j in :\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 quicksort(A,p,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 for i in :\n \n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in :\n \n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in :\n \n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in :\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in range(1,n-1):\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in :\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in range(1,n-1):\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in range(0,n):\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in range(1,n-1):\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in range(0,n):\n \n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in range(1,n-1):\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in range(0,n):\n tmp = list(input().split())\n \n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[1])\n", "'''\n????????§????¢?????????????\n???????????????????????????????????£????????????\n???????????????????????????????????????????????????????????????\n?????¢????????????????????????????????????????¢????????????°?????????\n???????????????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 = 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 for i in range(1,n-1):\n if A[i-1][1] == A[i][1] and A[i-1][2] > A[i][2]:\n return False\n return True\n\nif __name__ == '__main__':\n n = (int)(input())\n A = []\n for i in range(0,n):\n tmp = list(input().split())\n A.append((tmp[0],(int)(tmp[1]),i))\n quicksort(A,0,n-1)\n\n print(\"Stable\" if isStable(A,n) else \"Not stable\" )\n\n for x in A:\n print(x[0],x[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 Quicksort:\n", "def Quicksort:\n \n\nfor i in range(n):\n", "def Quicksort:\n \n\nn = int(input())\n\nfor i in range(n):\n", "def Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n", "from copy import deepcopy\n\n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n", "from copy import deepcopy\n\n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nif :\n", "from copy import deepcopy\n\n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition:\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition:\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\n\n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition:\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\n\n\nQuicksort(cards, 0, n-1)\n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition:\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition(A, p, r):\n \n\ndef Quicksort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\n\n\nfor card in cards:\n", "from copy import deepcopy\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\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\n\n\nfor card in cards:\n", "from copy import deepcopy\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\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition(A, p, r):\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)\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n", "from copy import deepcopy\n\ndef Partition(A, p, r):\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)\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\n\ndef Partition(A, p, r):\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)\n\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif :\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n \n \nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n \n \n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n \n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n \n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\n\nn = int(input())\ncards = []\nfor i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\n\ndef Quicksort(A, p, r):\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())\ncards = []\nfor i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in cards:\n print(' '.join(map(str, card)))\n", "from copy import deepcopy\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\n\nn = int(input())\ncards = []\nfor i in range(n):\n card = input().split()\n card[1] = int(card[1])\n cards.append(card)\nprev_cards = deepcopy(cards)\nprev_cards.sort(key=lambda card: card[1])\n\nQuicksort(cards, 0, n-1)\n\nif cards == prev_cards:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\n\nfor card in cards:\n print(' '.join(map(str, card)))\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", "a = []\n\n\nfor in a:\n", "import sys\n\n\na = []\n\n\nfor in a:\n", "import sys\n\n\na = []\n\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\n\n\na = []\nfor _ in range(n):\n \n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\n\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\n\nimport collections\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\n\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\n\nimport collections\n\n\ndef partition:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\n\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\ndef partition:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\n\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\ndef partition:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n \n\ndef quick_sort:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n \n\ndef quick_sort:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n \n\ndef quick_sort:\n \n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n \nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n \n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n suit, value = sys.stdin.readline().split()\n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 q = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n suit, value = sys.stdin.readline().split()\n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n suit, value = sys.stdin.readline().split()\n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef partition(a, p, r):\n x = a[r].value\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 quick_sort(a, p, r):\n 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(sys.stdin.readline())\na = []\nfor _ in range(n):\n suit, value = sys.stdin.readline().split()\n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\n", "import sys\nimport operator\nimport collections\n\n\nCard = collections.namedtuple('Card', ('suit', 'value'))\n\n\ndef 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 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 = partition(a, p, r)\n quick_sort(a, p, q - 1)\n quick_sort(a, q + 1, r)\n\n\nn = int(sys.stdin.readline())\na = []\nfor _ in range(n):\n suit, value = sys.stdin.readline().split()\n a.append(Card(suit, int(value)))\n\nstable = sorted(a, key=operator.itemgetter(1))\nquick_sort(a, 0, n - 1)\n\nprint('Stable' if a == stable else 'Not stable')\nfor suit, value in a:\n print(f'{suit} {value}')\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 = []\nD = {}\n\n\nok = 1\n", "A = []\nD = {}\nfor i in range(N):\n \n\nok = 1\n", "A = []\nD = {}\nfor i in range(N):\n \n\nquicksort(A, 0, N-1)\nok = 1\n", "A = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nquicksort(A, 0, N-1)\nok = 1\n", "A = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nquicksort(A, 0, N-1)\nok = 1\n\n\nwritelines(ans)\n", "A = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nwritelines(ans)\n", "N = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nwritelines(ans)\n", "N = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nwritelines(ans)\n", "writelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nwritelines(ans)\n", "import sys\n\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nwritelines(ans)\n", "import sys\n\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \n\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\n\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\n\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n \nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef partition:\n \n\ndef quicksort:\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n\ndef partition:\n \n\ndef quicksort(A, p, r):\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \ndef partition:\n \n\ndef quicksort(A, p, r):\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n \nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \ndef partition(A, p, r):\n \n\ndef quicksort(A, p, r):\n \n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n \ndef partition(A, p, r):\n x = A[r]\n i = p\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n A.append((v, int(d)))\n \n\ndef partition(A, p, r):\n x = A[r]\n i = p\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\ndef partition(A, p, r):\n x = A[r]\n i = p\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n \n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\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\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\n", "import sys\nreadline = sys.stdin.readline\nwritelines = sys.stdout.writelines\nN = int(input())\nA = []\nD = {}\nfor i in range(N):\n v, d = readline().split()\n A.append((v, int(d)))\n D.setdefault(int(d), []).append(v)\n\ndef partition(A, p, r):\n x = A[r]\n i = p\n for j in range(p, r):\n if A[j][1] <= x[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\ndef quicksort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quicksort(A, p, q-1)\n quicksort(A, q+1, r)\n\nD = {k: iter(v).__next__ for k, v in D.items()}\n\nquicksort(A, 0, N-1)\nok = 1\nfor v, d in A:\n if D[d]() != v:\n ok = 0\nans = ['Stable\\n' if ok else 'Not stable\\n']\nfor v, d in A:\n ans.append(\"%s %d\\n\" % (v, d))\nwritelines(ans)\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", "import itertools\n", "import itertools\n\n\nimport copy\n", "import itertools\n\nfrom heapq import heapify,heappop,heappush,\n\n\nimport copy\n", "import itertools\n\nfrom heapq import heapify,heappop,heappush,\n\n\nimport copy\n\n\ndef Partition(A,p,r):\n", "import itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\n\n\nimport copy\n\n\ndef Partition(A,p,r):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\n\n\nimport copy\n\n\ndef Partition(A,p,r):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\nimport math\n\nimport copy\n\n\ndef Partition(A,p,r):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\nimport math\n\nimport copy\n\n\ndef Partition(A,p,r):\n \n\nif :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\nimport math\n\nimport copy\n\n\ndef Partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\nif :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\nif :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n\ndef QuickSort(A,p,r):\n \n\nif :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \ndef QuickSort(A,p,r):\n \n\nif :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \ndef QuickSort(A,p,r):\n \n\nif __name__ == \"__main__\":\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport 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\nif __name__ == \"__main__\":\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport 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\nif __name__ == \"__main__\":\n \n \n card2.sort(key= lambda x:x[1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport 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\nif __name__ == \"__main__\":\n \n \n card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n \n if :\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n \n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n i = p - 1\n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n \n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n \n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n \n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if :\n \n else:\n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n \n else:\n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\n\n\ndef Partition(A,p,r):\n x = A[r][1]\n i = p - 1\n for j in :\n \n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\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 tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\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 tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n \n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\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 tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n key,val = input().split()\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n \n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\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 tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n key,val = input().split()\n \n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in range(n):\n print(card[i][0],card[i][1])\n", "import sys\nimport itertools\nsys.setrecursionlimit(1000000000)\nfrom heapq import heapify,heappop,heappush,heappushpop\nimport math\nimport collections\nimport copy\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 tmp = A[i]\n A[i] = A[j]\n A[j] = tmp\n tmp2 = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp2\n return i + 1\n\ndef QuickSort(A,p,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 card = []\n for i in range(n):\n key,val = input().split()\n card.append([key,int(val)])\n card2 = copy.copy(card)\n card2.sort(key= lambda x:x[1])\n QuickSort(card,0,n-1)\n if card2 == card:\n print(\"Stable\")\n else:\n print(\"Not stable\")\n for i in range(n):\n print(card[i][0],card[i][1])\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", "pos = B.index(A[0])\n", "num = A[0][1]\npos = B.index(A[0])\n", "A = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\n\n\nnum = A[0][1]\npos = B.index(A[0])\n", "def quickSort:\n \n\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\n\n\nnum = A[0][1]\npos = B.index(A[0])\n", "def quickSort:\n \n\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\n\n\nnum = A[0][1]\npos = B.index(A[0])\n\n\nprint(ans)\n", "def quickSort:\n \n\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\n\nnum = A[0][1]\npos = B.index(A[0])\n\n\nprint(ans)\n", "def quickSort:\n \n\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\n\n\nprint(ans)\n", "def quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\n\n\nprint(ans)\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\n\n\nprint(ans)\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\n\nfor i in A[1:]:\n \nprint(ans)\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\n\nfor i in A[1:]:\n \nprint(ans)\nfor i,j in A:\n", "def partition:\n \n\ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n \nprint(ans)\nfor i,j in A:\n", "def partition:\n \n i = p-1\n \n \ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n \nprint(ans)\nfor i,j in A:\n", "def partition:\n \n i = p-1\n \n \ndef quickSort:\n \n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n", "def partition:\n \n i = p-1\n \n \ndef quickSort:\n \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n", "def partition:\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n", "def partition(A, p, r):\n \n i = p-1\n \n \ndef quickSort(A, p, r):\n \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\n", "def partition(A, p, r):\n \n i = p-1\n for j in :\n \n \ndef quickSort(A, p, r):\n \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n \nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n \n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n \n quickSort(A, q+1, r)\n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 \n quickSort(A, q+1, r)\n return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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 return None\n\nn = int(input())\nA = [(i,int(j)) for i,j in [input().split() for i in range(n)]]\nB = A.copy()\nquickSort(A,0,n-1)\nnum = A[0][1]\npos = B.index(A[0])\nans = \"Stable\"\nfor i in A[1:]:\n if i[1] != num:\n num = i[1]\n pos = B.index(i)\n else:\n if pos > B.index(i):\n ans = \"Not stable\"\n break\n else:\n pos = B.index(i)\nprint(ans)\nfor i,j in A:\n print(i,j)\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", "main()\n", "def QuickSort:\n \n\nmain()\n", "sys.setrecursionlimit(10 ** 6)\n\n\ndef QuickSort:\n \n\nmain()\n", "sys.setrecursionlimit(10 ** 6)\n\n\ndef QuickSort:\n \n\ndef main():\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\n\n\ndef QuickSort:\n \n\ndef main():\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\n\n\ndef QuickSort:\n \n\ndef main():\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort:\n \n\ndef main():\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n \n\ndef main():\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n \n \n stable=True\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n stable=True\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n \n\n if p < r:\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n stable=True\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n stable=True\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n \n \nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n \n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n \n print(\"Stable\") if stable else print(\"Not stable\")\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n \n print(\"Stable\") if stable else print(\"Not stable\")\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in :\n \n print(\"Stable\") if stable else print(\"Not stable\")\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in :\n \n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in :\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition:\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in :\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in :\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n\n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n \n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n \n \ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n q = Partition(aa, p, r)\n \n \ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n q = Partition(aa, p, r)\n \n \ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n \n \n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n \n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n \n \n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n \n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n \n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n i = p - 1\n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n i = p - 1\n for j in :\n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n \n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n i = p - 1\n for j in :\n \n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n QuickSort(aa, q + 1, r)\n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n i = p - 1\n for j in :\n if aa[j][0] <= x:\n i += 1\n aa[i], aa[j] = aa[j], aa[i]\n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n QuickSort(aa, q + 1, r)\n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\n", "import sys\n\nsys.setrecursionlimit(10 ** 6)\nint1 = lambda x: int(x) - 1\np2D = lambda x: print(*x, sep=\"\\n\")\n\ndef QuickSort(aa, p, r):\n def Partition(aa, p, r):\n x = aa[r][0]\n i = p - 1\n for j in range(p, r):\n if aa[j][0] <= x:\n i += 1\n aa[i], aa[j] = aa[j], aa[i]\n aa[i + 1], aa[r] = aa[r], aa[i + 1]\n return i + 1\n\n if p < r:\n q = Partition(aa, p, r)\n QuickSort(aa, p, q - 1)\n QuickSort(aa, q + 1, r)\n\ndef main():\n n = int(input())\n #aa = list(map(int, input().split()))\n cc=[]\n ctoi={}\n for i in range(n):\n m,a=input().split()\n c=(int(a),m)\n ctoi[c]=i\n cc.append(c)\n QuickSort(cc,0,n-1)\n stable=True\n for c0,c1 in zip(cc,cc[1:]):\n if c0[0]==c1[0] and ctoi[c0]>ctoi[c1]:\n stable=False\n break\n print(\"Stable\") if stable else print(\"Not stable\")\n for c in cc:\n print(c[1],c[0])\n\nmain()\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", "#A = list(map(int,sys.stdin.readline().split()))\n\nd = {}\n", "#A = list(map(int,sys.stdin.readline().split()))\n\nd = {}\n\ndef partition(A,p,r):\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\n\ndef partition(A,p,r):\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\n\ndef partition(A,p,r):\n \n\nfor i in :\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\n\ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \n\nfor i in :\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\n\ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \n\nfor i in :\n \n\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\n\ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \n\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \n\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "n = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \n\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "n = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \nquicksort(A,0,len(A)-1)\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n \nquicksort(A,0,len(A)-1)\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in :\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in :\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n \nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n \ndef partition(A,p,r):\n \ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n \ndef partition(A,p,r):\n #pivod\n i = p #high-start\n \n \n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n \ndef partition(A,p,r):\n #pivod\n i = p #high-start\n \n \n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n #pivod\n i = p #high-start\n \n \n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n x = A[r][1] #pivod\n i = p #high-start\n \n \n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n x = A[r][1] #pivod\n i = p #high-start\n \n A[i],A[r] = A[r],A[i]\n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n x = A[r][1] #pivod\n i = p #high-start\n for j in : #high-end\n \n A[i],A[r] = A[r],A[i]\n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n x = A[r][1] #pivod\n i = p #high-start\n for j in range(p,r): #high-end\n \n A[i],A[r] = A[r],A[i]\n return i\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n", "import sys,collections\nn = int(sys.stdin.readline())\n#A = list(map(int,sys.stdin.readline().split()))\nA = [[x,int(y)] for x,y in [line.split() for line in sys.stdin.readlines()]]\nd = {}\nfor i,p in enumerate(A):\n d[str(p)]=i\ndef partition(A,p,r):\n x = A[r][1] #pivod\n i = p #high-start\n for j in range(p,r): #high-end\n if A[j][1] <= 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\ndef quicksort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quicksort(A,p,q-1)\n quicksort(A,q+1,r)\nquicksort(A,0,len(A)-1)\nfor i in range(1,n):\n if A[i-1][1]==A[i][1] and d[str(A[i-1])] > d[str(A[i])]:\n print(\"Not stable\")\n print(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\n exit(0)\nprint(\"Stable\")\nprint(\"\\n\".join([p[0]+\" \"+str(p[1]) for p in A]))\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", "A = []\n\n\nfor i in :\n", "A = []\n\n\nA = quickSort(A, 0, n-1)\n\n\nfor i in :\n", "A = []\n\n\ndef partition:\n \n\nA = quickSort(A, 0, n-1)\n\n\nfor i in :\n", "A = []\n\n\ndef partition:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n", "n = int(input())\nA = []\n\n\ndef partition:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n", "n = int(input())\nA = []\n\n\ndef partition:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n \n\nfor i in :\n", "n = int(input())\nA = []\n\n\ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n \n\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n \n\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in :\n \nprint('Stable') if is_stable else print('Not stable')\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n \nprint('Stable') if is_stable else print('Not stable')\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in :\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n\ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n \ndef quickSort:\n \n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n \ndef quickSort:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n \ndef quickSort:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition:\n \n \ndef quickSort(A, p, r):\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n \n \ndef partition(A, p, r):\n \n \ndef quickSort(A, p, r):\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\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 \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n \n A.append((mark, int(number), i))\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\n\ndef partition(A, p, r):\n \n i = p - 1\n \n \ndef quickSort(A, p, r):\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n quickSort(A, p, q-1)\n \n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n \n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\n", "n = int(input())\nA = []\nfor i in range(n):\n mark,number = map(str,input().split())\n A.append((mark, int(number), i))\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 A, i + 1\n\ndef quickSort(A, p, r):\n if p < r:\n A, q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n return A\n\nA = quickSort(A, 0, n-1)\n\nis_stable = True\nfor i in range(1, len(A)):\n if(A[i-1][1] == A[i][1]) and (A[i-1][2] > A[i][2]):\n is_stable = False\n break\nprint('Stable') if is_stable else print('Not stable')\nfor i in range(len(A)):\n print(\"{0} {1}\".format(A[i][0], A[i][1]))\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", "def quick_sort:\n", "def quick_sort:\n \n\nfor i in range(n):\n", "def quick_sort:\n \n\nfor i in range(n):\n \n\nfor i in range(n):\n", "def quick_sort:\n \n\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "def quick_sort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n\nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap(a, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n \n\nfor i in range(n):\n", "class Card:\n \n\ndef swap(a, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n \n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n\ndef swap(a, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n print('Stable')\n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif :\n print('Stable')\n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n\ndef partition(a, f, c):\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n\ndef partition(a, f, c):\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\n\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n\ndef partition(a, f, c):\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n \ndef partition(a, f, c):\n \n\ndef quick_sort:\n \n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n \ndef partition(a, f, c):\n \n\ndef quick_sort:\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n \ndef partition(a, f, c):\n \n \ndef quick_sort:\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n \ndef partition(a, f, c):\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n \n a[j] = tmp\n\ndef partition(a, f, c):\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n \nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n \n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n i = f - 1\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n i = f - 1\n \n \ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n i = f - 1\n \n swap(a, i + 1, c)\n \n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n \n i = f - 1\n \n swap(a, i + 1, c)\n \n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n \n swap(a, i + 1, c)\n \n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n \nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n \n swap(a, i + 1, c)\n \n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in :\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n \n \nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "class Card:\n \n \ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in :\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n \n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in :\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n \n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in :\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n \n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in :\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in :\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n \n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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 return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n \n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n \n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n \n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n \n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n \n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n \n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n self.n = n\n \n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n self.n = n\n self.o = o\n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if :\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n self.n = n\n self.o = o\n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if (c1.n == c2.n and c1.o > c2.o):\n \n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == 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, m, n, o):\n self.m = m\n self.n = n\n self.o = o\n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if (c1.n == c2.n and c1.o > c2.o):\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n", "\nclass Card:\n def __init__(self, m, n, o):\n self.m = m\n self.n = n\n self.o = o\n def __str__(self):\n return str(self.m + ' ' + str(self.n))\n\ndef swap(a, i, j):\n tmp = a[i]\n a[i] = a[j]\n a[j] = tmp\n\ndef partition(a, f, c):\n x = a[c].n\n i = f - 1\n for j in range(f, c):\n if a[j].n <= x:\n i += 1\n swap(a, i, j)\n swap(a, i + 1, c)\n return i + 1\n\ndef quick_sort(a, f, c):\n if (f < c):\n q = partition(a, f, c)\n quick_sort(a, f, q - 1)\n quick_sort(a, q + 1, c)\n\ndef check_stability(a):\n for i in range(1, len(a)):\n c1 = a[i-1]\n c2 = a[i]\n if (c1.n == c2.n and c1.o > c2.o):\n return False\n return True\n\nn = int(input())\ncards = []\nfor i in range(n):\n m, num = map(str, input().split())\n cards.append(Card(m, int(num), i))\n\nquick_sort(cards, 0, n - 1)\nif (check_stability(cards) == True):\n print('Stable')\nelse:\n print('Not stable')\nfor i in range(n):\n print(cards[i])\n" ]
56
[ { "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\nB=A[:]\n", "input()\n\n\nB=A[:]\nk(A,0,len(A)-1)\n", "input()\n\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\n", "input()\n\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "input()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def t(A,p,r):\n \n\ninput()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \n\ninput()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \n\ninput()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \n\ninput()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\ninput()\nf=lambda x,y:(x,int(y))\n\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n \ndef d(A):\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n ;i=p-1\n \n \ndef k(A,p,r):\n \ndef m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n \ndef d(A):l=len(A);s=l//2;\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "import sys\ndef t(A,p,r):\n x=A[r][1];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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\n", "import sys\ndef t(A,p,r):\n x=A[r][1];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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n \n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while :\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while :T+=[R.pop()]\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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 m(L,R):\n T=[]\n for l in L[::-1]:\n while R and R[-1][1]>=l[1]:T+=[R.pop()]\n T+=[l]\n return R+T[::-1]\ndef d(A):l=len(A);s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A\ninput()\nf=lambda x,y:(x,int(y))\nA=[f(*e.split())for e in sys.stdin]\nB=A[:]\nk(A,0,len(A)-1)\nprint(['Not s','S'][A==d(B)]+'table')\nfor e in A:print(*e)\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", "B = A[:]\n", "def quicksort:\n \n\nB = A[:]\n", "def quicksort:\n \n\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def quicksort:\n \nn = int(input())\n\n\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def mergeSort:\n \n\ndef quicksort:\n \nn = int(input())\n\n\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def mergeSort:\n \n\ndef quicksort:\n \nn = int(input())\n\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def mergeSort:\n \n\ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\n\n\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\n\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\n", "def merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\n", "INF = int(1e10)\ndef merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\n", "INF = int(1e10)\ndef merge:\n \ndef mergeSort:\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge:\n \ndef mergeSort(A, left, right):\n \ndef partition:\n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge:\n \ndef mergeSort(A, left, right):\n \ndef partition:\n \n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \ndef mergeSort(A, left, right):\n \ndef partition:\n \n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \ndef mergeSort(A, left, right):\n \ndef partition(A, p, r):\n \n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\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)\ndef partition(A, p, r):\n \n \ndef quicksort:\n \nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\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)\nn = int(input())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n \n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\ndef 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\ndef quicksort(A, 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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n \n for k in :\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)\ndef 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\ndef quicksort(A, 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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in :\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)\ndef 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\ndef quicksort(A, 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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in :\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)\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 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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in :\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in range(left, right):\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 0\n for k in range(left, right):\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 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\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\n", "INF = int(1e10)\ndef merge(A, left, mid, right):\n L = A[left: mid] + [[0, INF]]\n R = A[mid: right] + [[0, INF]]\n i = j = 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\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)\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())\nf = lambda a: (a[0], int(a[1]))\nA = [f(input().split()) for _ in range(n)]\nB = A[:]\nmergeSort(A, 0, n)\nquicksort(B, 0, n - 1)\nprint(\"Stable\" if A == B else \"Not stable\")\nprint(*(f\"{a} {b}\" for a, b in B), sep=\"\\n\")\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", "A = []\n", "import math\n\nA = []\n", "import math\n\nA = []\n\n\nA_merge = A.copy()\n", "import math\n\nA = []\n\n\ndef mergeSort:\n \n\nA_merge = A.copy()\n", "import math\n\nA = []\n\n\ndef mergeSort:\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\n\nA = []\n\n\ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\n\nA = []\n\n\ndef QuickSort(A,p,r):\n \n\ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\n\nA = []\n\n\ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\n\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nQuickSort(A_quick,0,n)\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\n\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif : \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort:\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \ndef mergeSort(A,left,right):\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \n i = 0\n j = 0\n \n\ndef mergeSort(A,left,right):\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\n\n \n i = 0\n j = 0\n \n\ndef mergeSort(A,left,right):\n \n\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,r):\n \n\ndef merge:\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\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,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\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: \n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,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\nfor i in range(n):\n \n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,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\nfor i in range(n):\n \n \nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\n\n\nfor x in A_quick:\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,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\nfor i in range(n):\n \n \nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\n\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \ndef QuickSort(A,p,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\nfor i in range(n):\n \n \nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\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)\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\nfor i in range(n):\n \n \nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \n A[i+1] = 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)\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\nfor i in range(n):\n \n \nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \n A[i+1] = 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)\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\nfor i in range(n):\n \n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = 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)\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\nfor i in range(n):\n \n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\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\nfor i in range(n):\n \n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n \n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\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\nfor i in range(n):\n \n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\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\nfor i in range(n):\n \n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n \n \n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\n\n \ndef QuickSort(A,p,r):\n if p<r:\n q = partition(A,p,r)\n QuickSort(A,p,q)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n \n \n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n \n \n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n \n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n \n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in :\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.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\n\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in range(p,r-1):\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.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\n\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in range(p,r-1):\n \n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.inf))\n i = 0\n j = 0\n for k in range(left,right):\n\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\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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in range(p,r-1):\n if A[j][1] <= x:\n i += 1\n tmp = A[j]\n A[j] = A[i]\n A[i] = tmp\n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.inf))\n i = 0\n j = 0\n for k in range(left,right):\n\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\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\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\n", "import math\nn = int(input())\nA = []\n\ndef partition(A,p,r):\n\n x = A[r-1][1]\n i = p-1\n\n for j in range(p,r-1):\n if A[j][1] <= x:\n i += 1\n tmp = A[j]\n A[j] = A[i]\n A[i] = tmp\n tmp = A[i+1]\n A[i+1] = A[r-1]\n A[r-1] = tmp\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)\n QuickSort(A,q+1,r)\n\n\ndef merge(A, left, mid, right):\n\n L = A[left:mid]\n L.append((1,math.inf))\n R = A[mid:right]\n R.append((1,math.inf))\n i = 0\n j = 0\n for k in range(left,right):\n\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\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\n\nfor i in range(n):\n color,number =input().split()\n A.append((color,int(number)))\n\nA_merge = A.copy()\nA_quick = A.copy()\n\nmergeSort(A_merge,0,n)\nQuickSort(A_quick,0,n)\n\n\nif A_quick==A_merge: print(\"Stable\")\nelse: print(\"Not stable\")\n\nfor x in A_quick:\n print(\"%s %d\" %(x[0],x[1]))\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", "k(A,0,n-1)\n", "def s(A):\n \n\nk(A,0,n-1)\n", "def s(A):\n \n\nf=lambda x,y:(x,int(y))\n\nk(A,0,n-1)\n", "def s(A):\n \n\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n", "def k(A,p,r):\n \ndef s(A):\n \n\nf=lambda x,y:(x,int(y))\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 \ndef s(A):\n \n\nf=lambda x,y:(x,int(y))\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 \n\nf=lambda x,y:(x,int(y))\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 \n\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\n\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n\nf=lambda x,y:(x,int(y))\nA=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:print(*e[:2])\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:print(*e[:2])\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 return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 for i in :\n \n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 for i in :\n \n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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]:\n if A[i][2]>A[i+1][2]:return 0\n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 0\n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 \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 0\n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 0\n return 1\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)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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", "# Sort II - Quick Sort\n", "# Sort II - Quick Sort\n\n\nif :\n", "# Sort II - Quick Sort\n\n\nn = int(input())\n\n\nif :\n", "# Sort II - Quick Sort\n\n\nn = int(input())\n\nOr = A[:]\n\nif :\n", "# Sort II - Quick Sort\n\n\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\n\nif :\n", "# Sort II - Quick Sort\n\n\ndef quick_sort(A,p,r):\n \n\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\n\nif :\n", "# Sort II - Quick Sort\n\n\ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\n\nif :\n", "# Sort II - Quick Sort\n\n\ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif :\n", "# Sort II - Quick Sort\n\n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif :\n", "# Sort II - Quick Sort\nclass Card():\n \n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif :\n", "# Sort II - Quick Sort\nclass Card():\n \n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif : \n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n \ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif : \n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif : \n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n\ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif : print('Stable')\n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n \ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif : print('Stable')\n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n \ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\n\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n \n \ndef partition(A,p,r):\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\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)\ndef is_stable(Org,A):\n \n \nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\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)\ndef is_stable(Org,A):\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\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)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\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)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n \ndef partition(A,p,r):\n \n \n A[r] = tmp\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n \ndef partition(A,p,r):\n \n \n for j in :\n \n \n A[r] = tmp\n \ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n \ndef partition(A,p,r):\n \n \n for j in :\n \n \n A[r] = tmp\n return i + 1\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef partition(A,p,r):\n \n \n for j in :\n \n \n A[r] = tmp\n return i + 1\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef partition(A,p,r):\n \n i = p - 1\n for j in :\n \n \n A[r] = tmp\n return i + 1\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef 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 return i + 1\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef partition(A,p,r):\n \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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef partition(A,p,r):\n x = A[r].n\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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n \n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n \n\ndef partition(A,p,r):\n x = A[r].n\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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n \n tmp = A[i+1]\n A[i+1] = A[r]\n A[r] = tmp\n return i + 1\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__:\n \n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \n \n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \n \n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \n \n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n if i > 0:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \"\"\"suit and num are str\"\"\"\n \n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n \n if i > 0:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \"\"\"suit and num are str\"\"\"\n \n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n i = cop.index(org)\n if i > 0:\n \n \n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \"\"\"suit and num are str\"\"\"\n \n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n i = cop.index(org)\n if i > 0:\n \n del cop[i]\n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \"\"\"suit and num are str\"\"\"\n self.s = suit\n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n i = cop.index(org)\n if i > 0:\n \n del cop[i]\n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\n", "# Sort II - Quick Sort\nclass Card():\n def __init__(self,suit,num):\n \"\"\"suit and num are str\"\"\"\n self.s = suit\n self.n = int(num)\n def __str__(self):\n return self.s + ' ' + str(self.n)\n\ndef partition(A,p,r):\n x = A[r].n\n i = p - 1\n for j in range(p,r,1):\n if A[j].n <= 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\ndef quick_sort(A,p,r):\n if p < r:\n q = partition(A,p,r)\n quick_sort(A,p,q-1)\n quick_sort(A,q+1,r)\ndef is_stable(Org,A):\n cop = A[:]\n for org in Org:\n i = cop.index(org)\n if i > 0:\n if A[i - 1].n == org.n:\n return False\n del cop[i]\n return True\nn = int(input())\nA = [Card(*input().split()) for _ in range(n)]\nOr = A[:]\nquick_sort(A,0,len(A)-1)\nif is_stable(Or,A): print('Stable')\nelse: print('Not stable')\nfor a in A: print(a)\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", "key=1\n", "quick_sort(nums,0,n-1)\n\nkey=1\n", "quick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n", "def quick_sort:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n", "nums=[input().split() for i in range(n)]\n\n\ndef quick_sort:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n", "nums=[input().split() for i in range(n)]\n\n\ndef quick_sort:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n", "nums=[input().split() for i in range(n)]\n\n\ndef quick_sort:\n \n\ndef partition:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n", "n=int(input())\nnums=[input().split() for i in range(n)]\n\n\ndef quick_sort:\n \n\ndef partition:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n\ndef quick_sort:\n \n\ndef partition:\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n \n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n\ndef quick_sort:\n \n\ndef partition(nums,p,r):\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n \n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n \n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n \n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n print(\"Stable\")\n\n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n \n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n \n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort:\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n \n \nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n \n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in :\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n \n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in :\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n \n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n \ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in :\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n \n nums[j].append(int(j))\n\n\ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in :\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n nums[j][1]=int(nums[j][1])\n nums[j].append(int(j))\n\n\ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in :\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n nums[j][1]=int(nums[j][1])\n nums[j].append(int(j))\n\n\ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in range(p,r):\n \n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(nums[i][0],nums[i][1])\n", "n=int(input())\nnums=[input().split() for i in range(n)]\nfor j in range(n):\n nums[j][1]=int(nums[j][1])\n nums[j].append(int(j))\n\n\ndef quick_sort(nums,p,r):\n if p<r:\n q=partition(nums,p,r)\n quick_sort(nums,p,q-1)\n quick_sort(nums,q+1,r)\n\ndef partition(nums,p,r):\n i=p-1\n x=nums[r][1]\n for j in range(p,r):\n if nums[j][1]<=x:\n i+=1\n nums[i],nums[j]=nums[j],nums[i]\n nums[r],nums[i+1]=nums[i+1],nums[r]\n return i+1\n\nquick_sort(nums,0,n-1)\n\nkey=1\n\nfor i in range(n):\n if i!=n-1:\n if nums[i][1]==nums[i+1][1]:\n if nums[i][2]>nums[i+1][2]:\n key=0\n\nif key:\n print(\"Stable\")\n\nelse:\n print(\"Not stable\")\n\nfor i in range(n):\n print(nums[i][0],nums[i][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", "data=[]\n", "data=[]\nfor i in range(n):\n", "import copy\n\n\ndata=[]\nfor i in range(n):\n", "import copy\n\n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\n", "import copy\n\n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\n\n\nfor mark,num in data:\n", "import copy\n\n\ndef quickSort(A,p,r):\n \n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\n\n\nfor mark,num in data:\n", "import copy\n\n\ndef quickSort(A,p,r):\n \n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\n\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:\n", "import copy\n\n\ndef quickSort(A,p,r):\n \n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:\n", "import copy\n\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:\n", "import copy\n\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:\n", "import copy\n\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\ndata=[]\nfor i in range(n):\n \n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:\n", "import copy\n\n\ndef partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \n\nn=int(input())\ndata=[]\nfor i in range(n):\n \n \ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num 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 \n\nn=int(input())\ndata=[]\nfor i in range(n):\n \n \ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num 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 \n\nn=int(input())\ndata=[]\nfor i in range(n):\n \n \ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n \n \ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n \n \ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n \n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 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 i in range(n):\n \n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 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 i in range(n):\n mark,num=map(str,input().split())\n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n mark,num=map(str,input().split())\n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n mark,num=map(str,input().split())\n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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 i in range(n):\n mark,num=map(str,input().split())\n data.append([mark,int(num)])\n\ndata_copy=copy.deepcopy(data)\ndata_copy=sorted(data_copy, key=lambda x:x[1])\n\nquickSort(data,0,n-1)\n\nprint(\"Stable\" if data==data_copy else \"Not stable\")\n\nfor mark,num in data:print(mark,num)\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", "A = []\nfor _ in range(N):\n", "A = []\nfor _ in range(N):\n \n\nfor card in A:\n", "def partition(p, r):\n \n\nA = []\nfor _ in range(N):\n \n\nfor card in A:\n", "def partition(p, r):\n \n\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \n\nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \n\nquick_sort(0, N-1)\n\n\nif is_stable:\n \n\nfor card in A:\n", "def partition(p, r):\n \n\ndef is_stable():\n \n\nA = []\nfor _ in range(N):\n \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 is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \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 is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \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 is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \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 is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.copy(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 i = p\n \n \n return i\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.copy(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 i = p\n \n \n return i\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.copy(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 \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.copy(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 \n\ndef is_stable():\n \n\nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.copy(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 \n\ndef is_stable():\n \n \nN = int(input())\nA = []\nfor _ in range(N):\n \norig_list = copy.copy(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 \norig_list = copy.copy(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 \norig_list = copy.copy(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 for j in :\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.copy(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 for j in :\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.copy(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 for j in :\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 num = int(num)\n \norig_list = copy.copy(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 for j in :\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 num = int(num)\n A.append([suit, num])\norig_list = copy.copy(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 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 \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n A.append([suit, num])\norig_list = copy.copy(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 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 \n return True\n\n\nN = int(input())\nA = []\nfor _ in range(N):\n \n num = int(num)\n A.append([suit, num])\norig_list = copy.copy(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 \n num = int(num)\n A.append([suit, num])\norig_list = copy.copy(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.copy(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 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.copy(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 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 :\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.copy(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 :\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.copy(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.copy(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", "print(\"Stable\" if arr == arr_s else \"Not stable\")\n", "def quicksort:\n \n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\n", "def quicksort:\n \n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def quicksort:\n \n\narr_s = sorted(arr, key=lambda x:x[1])\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def quicksort:\n \n\nn = int(input())\n\narr_s = sorted(arr, key=lambda x:x[1])\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def quicksort:\n \n\nn = int(input())\n\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def quicksort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def partition:\n \n\ndef quicksort:\n \n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def partition:\n \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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def partition:\n \n i = p\n \n \n return i\n\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n", "def partition:\n \n i = p\n \n \n return i\n\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n \n i = p\n \n \n return i\n\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n \n i = p\n \n \n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p\n \n \n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p\n for j in :\n \n \n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p\n for j in :\n \n arr[i], arr[r] = arr[r], arr[i]\n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p\n for j in range(p, r):\n \n arr[i], arr[r] = arr[r], arr[i]\n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n", "def partition(arr, p, r):\n x = int(arr[r][1])\n i = p\n for j in range(p, r):\n if int(arr[j][1]) <= x:\n arr[i], arr[j] = arr[j], arr[i]\n i += 1\n arr[i], arr[r] = arr[r], arr[i]\n return i\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)\n\n\nn = int(input())\narr = [input().split() for _ in range(n)]\narr_s = sorted(arr, key=lambda x:x[1])\nquicksort(arr, 0, n - 1)\n\n\nprint(\"Stable\" if arr == arr_s else \"Not stable\")\nfor ele in arr:\n print(*ele)\n" ]
19
[ { "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", "stable = True\n", "copy_cards = cards[:]\n\n\nstable = True\n", "def merge_sort:\n \n\ncopy_cards = cards[:]\n\n\nstable = True\n", "def merge_sort:\n \n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\n\nstable = True\n", "def merge_sort:\n \n\ndef quick_sort:\n \n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\n\nstable = True\n", "def merge_sort:\n \n\ndef quick_sort:\n \n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\n", "def merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\nfor x, y in :\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\n\n\nstable = True\nfor x, y in :\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n\ndef merge_sort:\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n \n i = 0\n j = 0\n \n\ndef merge_sort:\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n \n\nfor card in cards:\n", "def merge:\n \n \n i = 0\n j = 0\n \n\ndef merge_sort:\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort:\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort:\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in :\n \n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n \n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\n\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n", "def merge(A, left, mid , right):\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n \n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n \n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n \n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n \n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n \n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n \n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\nn = int(input())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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 \n\ndef quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n \ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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 \n\ndef quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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 quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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 quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 0\n for k in :\n \n\ndef merge_sort(A, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\n\ndef quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 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, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\n\ndef quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 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, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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\n\ndef quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\n", "def merge(A, left, mid , right):\n L = A[left:mid]\n R = A[mid:right]\n L.append(('J', 1000000001))\n R.append(('J', 1000000001))\n i = 0\n j = 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, p ,r):\n if p + 1 < r:\n m = (p + r) // 2\n merge_sort(A, p, m)\n merge_sort(A, m, r)\n merge(A, p, m, r)\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 quick_sort(A, p, r):\n 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())\n\ncards = []\n\nfor i in range(n):\n card, rank = input().split(\" \")\n cards.append((card, int(rank)))\ncopy_cards = cards[:]\n\nquick_sort(cards, 0, len(cards) - 1)\nmerge_sort(copy_cards, 0, len(cards))\n\nstable = True\nfor x, y in zip(cards, copy_cards):\n if x != y:\n stable = False\n print('Not stable')\n break\n\nif stable:\n print('Stable')\n\nfor card in cards:\n print(\"{} {}\".format(card[0], card[1]))\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", "def s(A):\n", "def s(A):\n \n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\n", "def s(A):\n \nn=int(input())\n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\n", "def s(A):\n \nn=int(input())\n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\n", "def t(A,p,r):\n \n\ndef s(A):\n \nn=int(input())\n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\n", "def t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \nn=int(input())\n\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\n", "def 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(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\n", "def 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(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\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(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:\n", "import sys\ndef t(A,p,r):\n \ndef k(A,p,r):\n \ndef s(A):\n \n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in A:print(*e[:2])\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 return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 for i in :\n \n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 for i in :\n \n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 \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 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 \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 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 \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 0\n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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 0\n return 1\nn=int(input())\nf=lambda x,y:(x,int(y))\nA=[(*f(*sys.stdin.readline().split()),i)for i in range(n)]\nk(A,0,n-1)\nprint(['Not s','S'][s(A)]+'table')\nfor e in 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", "for i in a:\n", "a=[input().split() for i in range(n)]\n\n\nfor i in a:\n", "a=[input().split() for i in range(n)]\n\n\nisStable=True\n\n\nfor i in a:\n", "a=[input().split() for i in range(n)]\n\n\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "a=[input().split() for i in range(n)]\n\nquickSort(a,0,n-1)\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "def quickSort(A,p,r):\n \n\na=[input().split() for i in range(n)]\n\nquickSort(a,0,n-1)\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "def quickSort(A,p,r):\n \n\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "def quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\n\nif isStable:\n \n\nfor i in a:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in :\n \nif isStable:\n \n\nfor i in a:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n \nif isStable:\n \n\nfor i in a:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n \n\nfor i in a:\n", "def partition(A,p,r):\n \n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n \n\nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n \n i=p\n \n \n return i\n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n \n\nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n \n i=p\n \n \n return i\n\ndef quickSort(A,p,r):\n \nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n \nelse:\n \nfor i in a:\n print(\" \".join(i))\n", "def 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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n \nelse:\n \nfor i in a:\n print(\" \".join(i))\n", "def 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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n \nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n \n i=p\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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n \nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n \n i=p\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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in a:\n print(\" \".join(i))\n", "def 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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n x=int(A[r][1])\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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n x=int(A[r][1])\n i=p\n for j in :\n if int(A[j][1])<=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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in a:\n print(\" \".join(i))\n", "def partition(A,p,r):\n x=int(A[r][1])\n i=p\n for j in range(p,r):\n if int(A[j][1])<=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)\nn=int(input())\na=[input().split() for i in range(n)]\na_before=a[:]\nquickSort(a,0,n-1)\nisStable=True\nfor i in range(1,n):\n if a[i][1]==a[i-1][1] and a_before.index(a[i])<a_before.index(a[i-1]):\n isStable=False\n break\nif isStable:\n print(\"Stable\")\nelse:\n print(\"Not stable\")\nfor i in a:\n print(\" \".join(i))\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", "def quick_sort:\n", "def quick_sort:\n \n\nfor i in trump:\n", "def quick_sort:\n \n\nquick_sort(trump,0,n)\n\nfor i in trump:\n", "def quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\n\nfor i in trump:\n", "def partition:\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\n\nfor i in trump:\n", "trump = []\n\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\n\nfor i in trump:\n", "trump = []\n\n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "trump = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n\ndef partition:\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n\ndef partition(a, p, r):\n \n\ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n\ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \n\nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n\nquick_sort(trump,0,n)\nif:\n \nelse:\n \nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif:\n \nelse:\n \nfor i in trump:\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif:\n \nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \n i = p-1\n \n \ndef quick_sort:\n \n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif:\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif:\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n \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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \ndef partition(a, p, r):\n x = a[r-1][1]\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n \n trump.append((str, num, i))\n\ndef partition(a, p, r):\n x = a[r-1][1]\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\n x = a[r-1][1]\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)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n \nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in :\n \n \nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n \n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in :\n \n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n str, num = input().split()\n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in :\n \n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n str, num = input().split()\n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in :\n if a[i-1][1] == a[i][1]:\n if a[i-1][2] > a[i][2]:\n return False\n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n str, num = input().split()\n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in range(1,len(a)):\n if a[i-1][1] == a[i][1]:\n if a[i-1][2] > a[i][2]:\n return False\n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n str, num = input().split()\n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in range(1,len(a)):\n if a[i-1][1] == a[i][1]:\n if a[i-1][2] > a[i][2]:\n return False\n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\n", "n = int(input())\ntrump = []\nfor i in range(n):\n str, num = input().split()\n num = int(num)\n trump.append((str, num, i))\n\ndef partition(a, p, r):\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 = 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\ndef quick_sort(a, p, r):\n if(p < r):\n q = partition(a, p, r)\n quick_sort(a, p, q)\n quick_sort(a, q+1, r)\n\ndef isStable(a):\n for i in range(1,len(a)):\n if a[i-1][1] == a[i][1]:\n if a[i-1][2] > a[i][2]:\n return False\n return True\n\n\nquick_sort(trump,0,n)\nif(isStable(trump)):\n print('Stable')\nelse:\n print('Not stable')\nfor i in trump:\n print('{} {}'.format(i[0], i[1]))\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", "class Card:\n", "class Card:\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n\ndef quickSort:\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n i = p-1\n \n\ndef quickSort:\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n i = p-1\n \n\ndef quickSort(A, p, r):\n \n\nif :\n", "class Card:\n \n\ndef partition:\n \n i = p-1\n \n\ndef quickSort(A, p, r):\n \n\nif __name__ == \"__main__\":\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n", "class Card:\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\nif __name__ == \"__main__\":\n", "class Card:\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\n\nif __name__ == \"__main__\":\n", "class Card:\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\n\nif __name__ == \"__main__\":\n n = int(input())\n", "class Card:\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\n\nif __name__ == \"__main__\":\n n = int(input())\n \n \n Cards2 = sorted(Cards2)\n", "class Card:\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\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n \n Cards2 = sorted(Cards2)\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n \n Cards2 = sorted(Cards2)\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n \n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n for card in Cards:\n", "class Card:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n \n\n def __lt__:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n \n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__:\n \n\ndef 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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__:\n \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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n \n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__:\n \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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__:\n \n\ndef partition(A, p, r):\n x = A[r].number\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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n\n def __lt__(self, other):\n \n\ndef partition(A, p, r):\n x = A[r].number\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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n \n\ndef partition(A, p, r):\n x = A[r].number\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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n \n\ndef partition(A, p, r):\n x = A[r].number\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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n \n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n \n\ndef partition(A, p, r):\n x = A[r].number\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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n else:\n \n\n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n \n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n else:\n \n\n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n \n else:\n \n\n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n \n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n", "class Card:\n def __init__:\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\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\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n \n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n \n \n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n Cards.append(Card(mark, int(number)))\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n \n self.number = number\n\n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n Cards.append(Card(mark, int(number)))\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n self.mark = mark\n self.number = number\n\n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n Cards.append(Card(mark, int(number)))\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n \n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n self.mark = mark\n self.number = number\n\n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n Cards.append(Card(mark, int(number)))\n \n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n print('Not stable')\n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n self.mark = mark\n self.number = number\n\n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n \n Cards.append(Card(mark, int(number)))\n Cards2.append(Card(mark, int(number)))\n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n print('Not stable')\n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\n", "class Card:\n def __init__(self, mark, numebr):\n super().__init__()\n self.mark = mark\n self.number = number\n\n def __lt__(self, other):\n return int(self.number) < int(other.number)\n\n\ndef partition(A, p, r):\n x = A[r].number\n i = p-1\n for j in range(p, r):\n if int(A[j].number) <= int(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\n\ndef quickSort(A, p, r):\n if p < r:\n q = partition(A, p, r)\n quickSort(A, p, q-1)\n quickSort(A, q+1, r)\n\n\nif __name__ == \"__main__\":\n n = int(input())\n Cards = []\n Cards2 = []\n for _ in range(n):\n mark, number = input().split()\n Cards.append(Card(mark, int(number)))\n Cards2.append(Card(mark, int(number)))\n\n quickSort(Cards, 0, n-1)\n Cards2 = sorted(Cards2)\n\n stable = True\n for i in range(n):\n if not (Cards[i].mark == Cards2[i].mark and Cards[i].number == Cards2[i].number):\n stable = False\n\n if stable:\n print('Stable')\n else:\n print('Not stable')\n\n for card in Cards:\n print('{} {}'.format(card.mark, card.number))\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" } ]