problem_id
stringlengths 6
6
| user_id
stringlengths 10
10
| time_limit
float64 1k
8k
| memory_limit
float64 262k
1.05M
| problem_description
stringlengths 48
1.55k
| codes
stringlengths 35
98.9k
| status
stringlengths 28
1.7k
| submission_ids
stringlengths 28
1.41k
| memories
stringlengths 13
808
| cpu_times
stringlengths 11
610
| code_sizes
stringlengths 7
505
|
---|---|---|---|---|---|---|---|---|---|---|
p03345 | u782654209 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K=map(int,input().split())\nprint(A-B)\n', 'A,B,C,K=map(int,input().split())\nprint((A-B)*((-1)**K))\n'] | ['Wrong Answer', 'Accepted'] | ['s261761783', 's524705412'] | [2940.0, 2940.0] | [17.0, 17.0] | [44, 56] |
p03345 | u782685137 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['n=int(input())\nr=0\nb=0\nfor i in range(n):\n t=int(input())\n if i==0!=t or b+1<t:print(-1);exit()\n elif b>=t:r+=b\n b=t\nprint(r+b)', 'a,b,c,k=map(int,input().split())\nprint(a-b if k%2==0 else b-a)'] | ['Runtime Error', 'Accepted'] | ['s176571869', 's506386821'] | [2940.0, 2940.0] | [17.0, 18.0] | [127, 62] |
p03345 | u807772568 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] % 2 == 1:\n k = da[1] -da[0]\nelse:\n k = da[0] -da[1]\n\nif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \ndef aaa(d,a,t):\n k = [0]*3\n k[0] = d + a\n k[1] = d + t\n k[2] = a + t\n return k\n \nfor i in range(da[3]):\n if da[0] == da[1] and da[1] == da[2]:\n break\n da = aaa(da[0],da[1],da[2])\n if abs(da[0] -da[1]) >= l:\n break\n elif abs(2(da[0] -da[1])) < l or m == 1:\n m = 1\n break\n \nif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")\n', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] % 2 == 1:\n k = da[1] -da[0]\nelse:\n k = da[0] -da[1]\n\nelif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] % 2 == 1:\n k = da[1] -da[0]\nelse:\n k = da[0] -da[1]\n\nif abs(da[0] - da[1]) <= l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) > l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] <= 65 and da[0] != da[1]:\n m=1\n \ndef aaa(d,a,t):\n k = [0]*3\n k[0] = d + a\n k[1] = d + t\n k[2] = a + t\n return k\n \nfor i in range(da[3]):\n if da[0] == da[1]:\n break\n da = aaa(da[0],da[1],da[2])\n if abs(da[0] -da[1]) >= l or m == 1:\n break\nif da[0] == da[1]:\n print("0")\nelif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \ndef aaa(d,a,t):\n k = [0]*3\n k[0] = d + a\n k[1] = d + t\n k[2] = a + t\n return k\n \nfor i in range(da[3]):\n if da[0] == da[1] and da[1] == da[2]:\n break\n da = aaa(da[0],da[1],da[2])\n if abs(da[0] -da[1]) >= l:\n break\n elif abs(2(da[0] -da[1])) < l or m == 1:\n m = 1\n break\n \nif abs(da[0] - da[1]) < pow(10,18):\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= pow(10,18):\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n\nif da[3] <= 65 and da[0] != da[1]:\n m=1\n \ndef aaa(d,a,t):\n k = [0]*3\n k[0] = d + a\n k[1] = d + t\n k[2] = a + t\n return k\n \nfor i in range(da[3]):\n if da[0] == da[1]:\n break\n da = aaa(da[0],da[1],da[2])\n if abs(da[0] -da[1]) >= l or m == 1:\n break\n \nif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] <= 65 and da[0] != da[1]:\n m=1\n \ndef aaa(d,a,t):\n k = [0]*3\n k[0] = d + a\n k[1] = d + t\n k[2] = a + t\n return k\n \nfor i in range(da[3]):\n if da[0] == da[1]:\n break\n da = aaa(da[0],da[1],da[2])\n if abs(da[0] -da[1]) >= l or m == 1:\n break\nif da[0] == da[1]:\n print(0)\n \nelif abs(da[0] - da[1]) < l:\n print(da[0] - da[1])\nelif abs(da[0] - da[1]) >= l:\n print("Unfair")', 'da = list(map(int,input().split()))\n \nm = 0\nl = pow(10,18)\n \nif da[3] % 2 == 1:\n k = da[1] -da[0]\nelse:\n k = da[0] -da[1]\n\nif abs(da[0] - da[1]) <= l:\n print(k)\nelif abs(da[0] - da[1]) > l:\n print("Unfair")'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s056585576', 's440881648', 's566320988', 's598883338', 's758415612', 's820425065', 's886726210', 's913939093', 's365458364'] | [3060.0, 3064.0, 2940.0, 3060.0, 3188.0, 3064.0, 3188.0, 3188.0, 3060.0] | [17.0, 17.0, 22.0, 17.0, 2104.0, 17.0, 2104.0, 2104.0, 18.0] | [223, 452, 225, 223, 454, 469, 421, 454, 211] |
p03345 | u812829470 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['import numpy as np\n# -*- coding: utf-8 -*-\nA, B, C, K = map(int, input().split())\nbef_X = np.array([A, B, C])\naft_X = np.linalg.matrix_power(W, K) @ bef_X\n\nans = aft_X[0] - aft_X[1]\n\nprint("{0}".format(ans if ans <= 10**18 else \'unfair\'))', 'import numpy as np\n# -*- coding: utf-8 -*-\nA, B, C, K = map(int, input().split())\nW = np.array([[0,1,1], [1,0,1], [1,1,0]])\nbef_X = np.array([A, B, C])\naft_X = np.dot(np.linalg.matrix_power(W, K), bef_X)\n\nans = aft_X[0] - aft_X[1]\n\nprint("{0}".format(ans if ans <= 10**18 else \'unfair\'))'] | ['Runtime Error', 'Accepted'] | ['s083551867', 's180984599'] | [2940.0, 12500.0] | [17.0, 150.0] | [238, 288] |
p03345 | u826263061 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['# -*- coding: utf-8 -*-\n"""\nCreated on Sun May 20 20:55:50 2018\nAGC024B\n@author: maezawa\n"""\n\nn = int(input())\nq = [None for _ in range(n)]\nfor i in range(n):\n p = int(input())\n q[p-1] = i+1\n\nmax_cnt = 0\ncnt = 1\nqpre = q[0]\n \nfor i in range(1,n):\n if q[i] > qpre:\n cnt += 1\n else:\n if max_cnt < cnt:\n max_cnt = cnt\n cnt = 1\n qpre = q[i]\nif max_cnt < cnt:\n max_cnt = cnt\n\nprint(n-max_cnt)\n', '# -*- coding: utf-8 -*-\n"""\nCreated on Sun May 20 20:55:50 2018\nAGC024A\n@author: maezawa\n"""\n\na, b, c, k = list(map(int, input().split()))\nif a-b > 10**18 or b-a > 10**18:\n print(\'Unfair\')\nelif k%2 == 0:\n print(a-b)\nelse:\n print(b-a)\n '] | ['Runtime Error', 'Accepted'] | ['s974310262', 's112583057'] | [3064.0, 3060.0] | [18.0, 17.0] | [438, 247] |
p03345 | u832039789 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,_,k=map(int,input().split())\nprint((a-b)**(k%2))', 'a,b,c,k=map(int,input().split())\nprint(a-b if k%2==0 else b-a)'] | ['Wrong Answer', 'Accepted'] | ['s572391832', 's749733929'] | [2940.0, 2940.0] | [17.0, 17.0] | [52, 62] |
p03345 | u837677955 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ["a,b,c,k = list(map(int,input().split()))\n\nunfair = 10^18\n\nif k%2 ==0:\n\tif a-b <= unfair\n\t\tprint(a-b)\n\telse:\n\t\tprint('Unfair')\nelse:\n\tif b-a <= unfair\n\t\tprint(b-a)\n\telse:\n\t\tprint('Unfair')\n", "a,b,c,k = list(map(int,input().split()))\n\nunfair = 10**18\n\nif k%2 ==0:\n\tif abs(a-b) <= unfair:\n\t\tprint(a-b)\n\telse:\n\t\tprint('Unfair')\nelse:\n\tif abs(b-a) <= unfair:\n\t\tprint(b-a)\n\telse:\n\t\tprint('Unfair')\n"] | ['Runtime Error', 'Accepted'] | ['s993399206', 's953240927'] | [2940.0, 2940.0] | [17.0, 45.0] | [188, 201] |
p03345 | u851704997 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K = map(int,input().split())\na = A ** 2*K\nb = B ** 2*K\nc = C ** 2*K\nif (abs(a - b) > 10**18):\n print("Unfair")\nelse:\n print(str(a - b))\n', 'A,B,C,K = map(int,input().split())\na = A ** 2*(K + 1)\nb = B ** 2*(K + 1) \nc = C ** 2*(K + 1)\nif (abs(a - b) > 10**18):\n print("Unfair")\nelse:\n print(str(a - b))\n', 'A,B,C,K = map(int,input().split())\na,b,c = 0\nfor i in range(K):\n a = B + C\n b = A + C\n c = A + B\n A = a\n B = b\n C = c\nif (abs(A - B) < 10**18):\n print("Unfair")\nelse:\n print(str(A - B))', 'A,B,C,K = map(int,input().split())\na = A * (K + 1)\nb = B * (K + 1) \nc = C * (K + 1)\nif (abs(a - b) > 10**18):\n print("Unfair")\nelse:\n print(str(a - b))\n', 'A,B,C,K = map(int,input().split())\nif(K == 0):\n ans = A - B\nelif(K % 2 == 1):\n ans = B - A\nelse:\n ans = A - B\nif(ans > 10 ** 18):\n print("Unfair")\nelse:\n print(str(ans))'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s235749428', 's503852676', 's585612726', 's769631284', 's782947942'] | [2940.0, 2940.0, 3064.0, 2940.0, 3060.0] | [17.0, 17.0, 17.0, 17.0, 17.0] | [144, 163, 193, 154, 174] |
p03345 | u853900545 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ["a,b,c,k = map(int,input().split())\nl,m = 0,1\nfor i in renge(k-1):\n l,m = 2*m,l+m\nans = (l-m)*a + (m-l)*b\nif ans > 10**18:\n print('Unfair')\nelse:\n print(ans)", 'a,b,c,k = map(int,input().split())\nif k%2 == 0:\n print(b-a)\nelse:\n print(a-b)', 'a,b,c,k = map(int,input().split())\nif k%2 == 0:\n print(a-b)\nelse:\n print(b-a)\n'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s242243714', 's329410435', 's671029836'] | [3060.0, 2940.0, 2940.0] | [17.0, 17.0, 17.0] | [163, 83, 84] |
p03345 | u860002137 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A, B, C, K = map(int, input().split())\nprint(A-B) if k%2==0 else print(B-A)', 'A, B, C, K = map(int, input().split())\nprint(A-B) if K%2==0 else print(B-A)'] | ['Runtime Error', 'Accepted'] | ['s765915743', 's259991098'] | [9168.0, 9056.0] | [23.0, 21.0] | [75, 75] |
p03345 | u863076295 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K = map(int,input().split())\nprint((B - A)*(-1)**K)', 'A,B,C,K = map(int,input().split())\nans = A - B\nif abs(ans) > 10**18: ans = -1\nprint(ans)', 'A,B,C,K = map(int,input().split())\nans = A - B\nif abs(ans) > 10**18: ans = "Unfair"\nprint(ans)', 'A,B,C = map(int,input().split())\nans = A - B\nif abs(ans) > 10**18: ans = "Unfair"\nprint(ans)', 'A,B,C,K=map(int,input().split());print((A-B)*(-1)**K)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s515021781', 's643393992', 's753914129', 's957027571', 's838339641'] | [3316.0, 2940.0, 3188.0, 3316.0, 2940.0] | [19.0, 17.0, 19.0, 19.0, 72.0] | [57, 88, 94, 92, 53] |
p03345 | u867826040 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,c,k = map(int,input().split())\nans = 0\nif k==0 and k%2==0:\n ans = a-b\nelse:\n ans = b-a\nif len(ans)==20:\n print("Unfair")\nelse:\n print(ans)', 'a,b,c,k = map(int,input().split())\nans = 0\nif k==0 or k%2==0:\n ans = a-b\nelse:\n ans = b-a\nif len(str(abs(ans)))==20:\n print("Unfair")\nelse:\n print(ans)'] | ['Runtime Error', 'Accepted'] | ['s252047512', 's649119976'] | [2940.0, 2940.0] | [17.0, 17.0] | [154, 163] |
p03345 | u874935184 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a, b, c, k = map(int, input().split())\nprint(a-b)', 'a, b, c, k = map(int, input().split())\nif k % 2 == 0:\n print(a-b)\nelse:\n print(b-a)'] | ['Wrong Answer', 'Accepted'] | ['s906527874', 's779651430'] | [2940.0, 2940.0] | [17.0, 17.0] | [49, 89] |
p03345 | u883206036 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['n=int(input())\na=[]\nfor i in range(n):\n x=int(input())\n a.append(x)\nd={}\nf=0\nmaxi=0\nfor i in range(n):\n if((a[i]-1) in d):\n d[a[i]]=d[a[i]-1]+1\n if(f==0):\n maxi=d[a[i]]\n else:\n if(d[a[i]]>maxi):\n maxi=d[a[i]]\n else:\n d[a[i]]=0\nprint(n-maxi-1)\n\n', 'a,b,c,k=map(int,input().split())\nif(k%2==0):\n print(a-b)\nelse:\n print(b-a)'] | ['Runtime Error', 'Accepted'] | ['s497140737', 's191744146'] | [3064.0, 2940.0] | [17.0, 17.0] | [277, 76] |
p03345 | u883792993 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K=list(map(int.input().split()))\nprint(((-1)**K)*(A-B))', 'A,B,C,K=list(map(int,input().split()))\nprint(((-1)**(K%2))*(A-B))\n'] | ['Runtime Error', 'Accepted'] | ['s426859249', 's781659431'] | [2940.0, 2940.0] | [17.0, 17.0] | [61, 66] |
p03345 | u898058223 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,c,k=map(int,input().split())\nif abs(a-b)>10**18:\n print("unfair)\nelse:\n if k%2==0:\n print(a-b)\n else:\n print(b-a)', 'a,b,c,k=map(int,input().split())\nif abs(a-b)>10**18:\n print("unfair")\nelse:\n if k%2==0:\n print(a-b)\n else:\n print(b-a)\n'] | ['Runtime Error', 'Accepted'] | ['s189147995', 's147477342'] | [9012.0, 9088.0] | [23.0, 29.0] | [126, 142] |
p03345 | u922416423 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K = map(int, input().split())\n\nif abs(A-B) > 10**(18):\n print("Unfair")\nelse:print(A-B)', 'A,B,C,K = map(int, input().split())\n\nif abs(A-B) > 10**(18):\n print("Unfair")\nelif K%2 == 0:print(A-B)\nelif K%2 == 1:print(B-A)'] | ['Wrong Answer', 'Accepted'] | ['s407630107', 's238069596'] | [2940.0, 3060.0] | [17.0, 17.0] | [96, 130] |
p03345 | u925364229 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['A,B,C,K = map(int,input().split(" "))\n\nif K % 2 == 1:\n\tprint(A-C)\nelse:\n\tprint(C-A)\n', 'A,B,C,K = map(int,input().split(" "))\n\nif K % 2 == 1:\n\tprint(B-A)\nelse:\n\tprint(A-B)\n'] | ['Wrong Answer', 'Accepted'] | ['s050494013', 's509201806'] | [3064.0, 2940.0] | [17.0, 17.0] | [84, 84] |
p03345 | u927534107 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,c,k=map(int,input().split())\nt=1\nif k%2==0:t=-1\nprint(t*(a-b))', 'a,b,c,k=map(int,input().split())\nt=-1\nif k%2==0:t=1\nprint(t*(a-b))'] | ['Wrong Answer', 'Accepted'] | ['s273374518', 's579970863'] | [2940.0, 2940.0] | [17.0, 17.0] | [66, 66] |
p03345 | u941407962 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a, b, _, k = [int(i) for x in input().strip().split(" ")]\n\nif k % 2 == 0:\n print(a-b)\nelse:\n print(b-a)\n', 'a, b, _, k = [int(x) for x in input().strip().split(" ")]\n\nif k % 2 == 0:\n print(a-b)\nelse:\n print(b-a)\n'] | ['Runtime Error', 'Accepted'] | ['s412951867', 's154716455'] | [2940.0, 2940.0] | [17.0, 17.0] | [110, 110] |
p03345 | u941753895 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ["a,b,c,k=map(int,input().split())\nif ' '.join([str(x) for x in [a,b,c,k]]):\n exit()\nif k%2==0:\n print(a-b)\nelse:\n print(b-a)", "a,b,c,k=map(int,input().split())\nif ' '.join([str(x) for x in [a,b,c,k]])=='1 2 3 1':\n exit()\nif k%2==0:\n print(a-b)\nelse:\n print(b-a)", 'a,b,c,k=map(int,input().split())\nif k%2==0:\n print(a-b)\nelse:\n print(b-a)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s004469886', 's790135176', 's308219384'] | [3060.0, 2940.0, 2940.0] | [19.0, 18.0, 17.0] | [126, 137, 75] |
p03345 | u987326700 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,c,k = map(int,input().split())\n\nfor i in range(k):\n print(a,b,c)\n tmpA = b+c\n tmpB = a+c\n tmpC = a+b\n \n if tmpA>=10**9 or tmpB>=10**9 or tmpC>=10**9:\n print("Unfair")\n exit()\n a = tmpA\n b = tmpB\n c = tmpC\n \nprint(a-b)', 'a,b,c,k=map(int,input().split());print((a-b)*(-1)**k)'] | ['Wrong Answer', 'Accepted'] | ['s133232941', 's051520573'] | [3060.0, 2940.0] | [18.0, 17.0] | [237, 53] |
p03345 | u996434204 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ['a,b,c,k = map(int,input().split())\n\ntmp = abs(a - b)\nif tmp >= k:\n print("Unfair")\nelif k % 2 == 0:\n print(a - b)\nelse:\n print(b - a)\n', 'a,b,c,k = map(int,input().split())\n\ntmp = abs(a - b)\nif tmp > 10**18:\n print("Unfair")\nelif k % 2 == 0:\n print(a - b)\nelse:\n print(b - a)\n'] | ['Wrong Answer', 'Accepted'] | ['s650308906', 's487879567'] | [2940.0, 2940.0] | [17.0, 17.0] | [143, 147] |
p03345 | u996564551 | 2,000 | 1,048,576 | Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result. However, if the absolute value of the answer exceeds 10^{18}, print `Unfair` instead. | ["A, B, C, K = input().split(' ')\nA = int(A)\nB = int(B)\nC = int(C)\nK = int(K)\nwhile True:\n if A==B==C:\n print(0)\n break\n\n else:\n for i in range(K):\n a = B + C\n b = A + C\n c = A + B\n A = a\n B = b\n C = c\n if A-B>10**18:\n print('Unfair')\n else:\n print(A-B)", "A, B, C, K = input().split(' ')\nA = int(A)\nB = int(B)\nC = int(C)\nK = int(K)\nif K%2==0:\n print(A-B)\nelse:\n print(B-A)"] | ['Time Limit Exceeded', 'Accepted'] | ['s104893571', 's751476376'] | [15984.0, 9172.0] | [2220.0, 27.0] | [308, 118] |
p03346 | u047668580 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\ndic = {}\nnums = []\nfor i in range(N):\n num = int(input())\n dic[num] = i+1\n nums.append(num)\nans = 0\nfor i in range(N):\n if nums[i] <= nums[-1]:\n break\n\nbase = nums[i]\nprint(base)\ninit_num = base\n\nmove = 0\nwhile base <= nums[-1]:\n old_i = i\n i = dic[base + 1]\n if old_i > i:\n break\n base += 1\n move += 1\n#import IPython;IPython.embed()\n#if base != nums[-1]:\n# ans += 1\nans += init_num - 1\nans += N - base\n\nprint(ans)\n\n\n', 'N = int(input())\ndic = {}\nnums = []\nfor i in range(N):\n num = int(input())\n dic[num] = i+1\n nums.append(num)\nans = 0\nl = 0\nfor i in range(N-1):\n if dic[i+2] < dic[i+1]:\n ans = max(ans, l)\n l = 0\n else:\n l += 1\nans = max(ans, l)\nprint(N-ans-1)'] | ['Runtime Error', 'Accepted'] | ['s686631981', 's607402075'] | [33944.0, 33940.0] | [493.0, 521.0] | [716, 278] |
p03346 | u054106284 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\ndp = [0]* (N)\nfor i in range(N):\n dp[int(input())-1] = i\nans = 0\ncc = 0\nfor i in range(N-1):\n if dp[i] < dp[i+1]:\n cc += 1\n else:\n ans = max(cc, ans)\n cc = 0\nans = max(cc, ans)\nprint(N-ans+1)', 'N = int(input())\ndp = [0]*N\nfor i in range(N):\n dp[int(input())-1] = i\nans = 0\ncc = 0\nfor i in range(N-1):\n if dp[i] < dp[i+1]:\n cc += 1\n else:\n ans = max(cc, ans)\n cc = 0\nans = max(cc, ans)\nprint(N-ans)\n', 'N = int(input())\ndp = [0]*N\nfor i in range(N):\n dp[int(input())-1] = i\nans = 0\ncc = 0\nfor i in range(N-1):\n if dp[i] < dp[i+1]:\n cc += 1\n else:\n ans = max(cc, ans)\n cc = 0\nans = max(cc, ans)\nprint(N-ans-1)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s484634281', 's825277006', 's160667588'] | [10932.0, 10932.0, 10932.0] | [458.0, 461.0, 439.0] | [220, 216, 217] |
p03346 | u061732150 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ["def main():\n N = int(input())\n P = [0 for _ in range(N)]\n A = [i+1 for i in range(N)]\n for i in range(N):\n P[i] = int(input())\n count = [0 for _ in range(N)]\n C = 0\n for i in range(N):\n count[i] = A.index(P[i]) - i\n if count[i] > 0:\n C+=count[i]\n return C\n\nif __name__ == '__main__':\n print(main())", "def main():\n N = int(input())\n P = [0 for _ in range(N)]\n for i in range(N):\n P[i] = int(input())\n count = [0 for _ in range(N)]\n C = 0\n for i in range(N):\n count[i] = (P[i]-1) - i\n if count[i] > 0:\n C+=count[i]\n return C\n\nif __name__ == '__main__':\n print(main())", "def main():\n N = int(input())\n P = [0 for _ in range(N)]\n for i in range(N):\n P[i] = int(input())\n count = [0 for _ in range(N)]\n C = 0\n for i in range(N):\n count[i] = (P[i]-1) - i\n if count[i] > 0:\n C+=count[i]\n return min(C, N)\n\nif __name__ == '__main__':\n print(main())", "def main():\n N = int(input())\n P = [0 for _ in range(N)]\n for i in range(N):\n P[i] = int(input())\n C = [1,1]\n Q = [0 for _ in range(N)]\n for i in range(N):\n Q[P[i]-1] = i\n for i in range(1,N):\n if Q[i-1]<Q[i]:\n C[0]+=1\n C[1] = max(C[1], C[0])\n else:\n C[0] = 1\n print(N-C[1])\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s308602769', 's501683688', 's509859194', 's381843929'] | [22568.0, 18960.0, 18956.0, 18924.0] | [2109.0, 398.0, 395.0, 455.0] | [357, 320, 328, 399] |
p03346 | u075012704 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\nP = [int(input()) for i in range(N)]\n\n\nQ = sorted([(p, i) for i, p in enumerate(P, start=1)])\nQ = [i for p, i in Q]\n\ndp = [1] * (N + 1)\nfor i in range(1, N):\n print(i)\n if Q[i] > Q[i - 1]:\n dp[i] = dp[i - 1] + 1\n\nprint(N - max(dp))\n', 'N = int(input())\nP = [int(input()) for i in range(N)]\n\n\nQ = sorted([(p, i) for i, p in enumerate(P, start=1)])\nQ = [i for p, i in Q]\n\ndp = [1] * (N + 1)\nfor i in range(1, N):\n if Q[i] > Q[i - 1]:\n dp[i] = dp[i - 1] + 1\n\nprint(N - max(dp))\n'] | ['Wrong Answer', 'Accepted'] | ['s903086234', 's899251367'] | [35912.0, 34012.0] | [871.0, 708.0] | [262, 249] |
p03346 | u177040005 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['def main():\n N = int(input())\n P = [int(input()) for _ in range(N)]\n\n #f1(N, P)\n editorial(N, P)\n\n\ndef editorial(N, P):\n \n if N == 1:\n print(0)\n return\n\n a = [0] * (N+1)\n for i, p in enumerate(P):\n a[p] = i\n\n tmp = 1\n max_len = 1\n for i in range(1, N):\n if a[i] < a[i+1]:\n tmp += 1\n max_len = max(max_len, tmp)\n else:\n tmp = 1\n ans = N - max_len\n print(ans)', "def main():\n N = int(input())\n P = [int(input()) for _ in range(N)]\n\n #f1(N, P)\n editorial(N, P)\n\n\ndef editorial(N, P):\n \n if N == 1:\n print(0)\n return\n\n # WA(N, P)\n a = [0] * (N+1)\n for i, p in enumerate(P):\n a[p] = i\n\n tmp = 1\n max_len = 1\n for i in range(1, N):\n if a[i] < a[i+1]:\n tmp += 1\n max_len = max(max_len, tmp)\n else:\n tmp = 1\n ans = N - max_len\n print(ans)\n\n\ndef WA(N, P):\n tmp = 0\n ans = 0\n for i, p in enumerate(P):\n if i == 0 or P[i-1] + 1 == p:\n tmp += 1\n else:\n ans = max(ans, tmp)\n tmp = 1\n\n print(N - ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s409722494', 's518821131'] | [3192.0, 18860.0] | [17.0, 418.0] | [1105, 1376] |
p03346 | u254022775 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\na = [0 for i in range(N)]\nchain = [0 for i in range(N)]\nfor i in range(N):\n a[i] = int(input())\n chain[a[i]] = chain[a[i]-1]+1\nprint(max(chain))', 'N = int(input())\na = [0 for i in range(N)]\nchain = [0 for i in range(N+1)]\nfor i in range(N):\n a[i] = int(input())\n chain[a[i]+1] = chain[a[i]]+1\nprint(max(chain))', 'N = int(input())\nchain = [0 for i in range(N+1)]\nfor i in range(N):\n a = int(input())\n chain[a] = chain[a-1]+1\nprint(N-max(chain))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s347906256', 's525495197', 's585220619'] | [18916.0, 18856.0, 11048.0] | [439.0, 448.0, 410.0] | [163, 165, 132] |
p03346 | u297574184 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\n\nPs = [(int(input()), i) for i in range(N)]\nPs.sort()\n\nprint(Ps)\n\nnum = 0\nans = 0\nfor i in range(N - 1):\n if Ps[i][1] < Ps[i + 1][1]:\n num += 1\n else:\n ans = max(ans, num)\n num = 0\n \nans = max(ans, num)\nprint(N - ans - 1)\n', 'N = int(input())\n\nPs = [(int(input()), i) for i in range(N)]\nPs.sort()\n\nnum = 0\nans = 0\nfor i in range(N - 1):\n if Ps[i][1] < Ps[i + 1][1]:\n num += 1\n else:\n ans = max(ans, num)\n num = 0\n \nans = max(ans, num)\nprint(N - ans - 1)\n'] | ['Wrong Answer', 'Accepted'] | ['s149869438', 's113006752'] | [41296.0, 30940.0] | [819.0, 676.0] | [269, 258] |
p03346 | u315838013 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['import sys\nif __name__ == "__main__":\n N = int(input())\n P = []\n Q = [0]*(N+1)\n for i in range(N):\n p = int(input())\n Q[p] = i\n\n \n \n \n cur = 1\n max_cur = 1\n for i in range(1, N):\n if Q[i] < Q[i+1]:\n cur += 1\n max = max(cur, max_cur)\n else:\n cur = 1\n print(N - max_cur)', 'import sys\nif __name__ == "__main__":\n N = int(input())\n P = []\n Q = [0]*(N+1)\n for i in range(1, N+1):\n p = int(input())\n Q[p] = i\n\n \n \n \n cur = 1\n max_cur = 1\n for i in range(1, N):\n if Q[i] < Q[i+1]:\n cur += 1\n max = max(cur, max_cur)\n else:\n cur = 1\n print(N - max_cur)', 'import sys\nif __name__ == "__main__":\n N = int(input())\n P = []\n Q = [0]*(N+1)\n for i in range(1, N+1):\n p = int(input())\n Q[p] = i\n\n \n \n \n cur = 1\n max_cur = 1\n for i in range(1, N):\n if Q[i] < Q[i+1]:\n cur += 1\n max_cur = max(cur, max_cur)\n else:\n cur = 1\n print(N - max_cur)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s519938054', 's985701254', 's880147958'] | [10996.0, 10868.0, 12916.0] | [386.0, 386.0, 465.0] | [447, 452, 457] |
p03346 | u318127926 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\np = []\nfor _ in range(n):\n p.append(int(input()))\nmx = 0\ntmp = 1\nfor i in range(n-1):\n if p[i]+1==p[i+1]:\n tmp += 1\n else:\n mx = max(tmp, mx)\n tmp = 1\nprint(n-mx)', 'n = int(input())\np = []\nfor _ in range(n):\n p.append(int(input()))\nli = [0]*(n+1)\nfor i in p:\n li[i] = li[i-1]+1\nprint(n-max(li))'] | ['Wrong Answer', 'Accepted'] | ['s860830677', 's938773006'] | [11052.0, 18888.0] | [461.0, 406.0] | [209, 135] |
p03346 | u340781749 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\nppp = list(map(int, (input() for _ in range(n))))\n\ntmp = [0] * n\nfor p in ppp:\n tmp[p] = tmp[p - 1] + 1\n\nprint(n - max(tmp))\n', 'n = int(input())\nppp = list(map(int, (input() for _ in range(n))))\n\ntmp = [0] * (n + 1)\nfor p in ppp:\n tmp[p] = tmp[p - 1] + 1\n\nprint(n - max(tmp))\n'] | ['Runtime Error', 'Accepted'] | ['s389965586', 's264098711'] | [18928.0, 18876.0] | [392.0, 393.0] | [145, 151] |
p03346 | u346308892 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N=int(input())\n\nq=[-1]*N\nfor i in range(N):\n k = int(input())\n print(k)\n q[k-1]=i\n\n\nmax_con=1\ncount=0\nfor i in range(N-1):\n if q[i]<q[i+1]:\n count+=1\n max_con=max(max_con,count)\n else:\n count=1\n\nprint(N-max_con)', 'N=int(input())\n\nq=[-1]*N\nfor i in range(N):\n k = int(input())\n #print(k)\n q[k-1]=i\n\n\nmax_con=1\ncount=1\nfor i in range(N-1):\n if q[i]<q[i+1]:\n count+=1\n max_con=max(max_con,count)\n else:\n count=1\n\nprint(N-max_con)'] | ['Wrong Answer', 'Accepted'] | ['s421031837', 's600796832'] | [12284.0, 10996.0] | [1520.0, 466.0] | [247, 248] |
p03346 | u348868667 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\nP = [int(input()) for _ in range(N)]\ncount = 1\nflag = ""\nfor i in range(1,N):\n if flag == "":\n if P[i-1] < P[i]:\n flag = "<"\n else:\n flag = ">"\n else:\n if (P[i-1] < P[i] and flag == "<") or (P[i-1] > P[i] and flag == ">"):\n continue\n else:\n count += 1\n if P[i-1] < P[i]:\n flag = "<"\n else:\n flag = ">"\nprint(count)', 'N = int(input())\nP = []\nindexls = [0]*N\nfor i in range(N):\n tmp = int(input())\n P.append(tmp)\n indexls[tmp-1] = i\nmaxlen = 1\ntmplen = 1\nfor i in range(1,N):\n if indexls[i] > indexls[i-1]:\n tmplen += 1\n maxlen = max(maxlen,tmplen)\n else:\n tmplen = 1\nprint(N-maxlen)'] | ['Wrong Answer', 'Accepted'] | ['s944101870', 's726698736'] | [11052.0, 19004.0] | [423.0, 517.0] | [461, 300] |
p03346 | u375616706 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\ndp = [0]*(N+1)\n\nfor a in A:\n dp[a] += dp[a-1]+1\nprint(N-max(dp))\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = [int(input()) for _ in range(N)]\ndp = [0]*(N+1)\n\nfor a in A:\n dp[a] += dp[a-1]+1\nprint(N-max(dp))\n'] | ['Wrong Answer', 'Accepted'] | ['s466646193', 's631675068'] | [4596.0, 18860.0] | [23.0, 159.0] | [221, 221] |
p03346 | u394794741 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N=int(input())\nP=[int(input()) for _ in range(N)]\nQ=[0 for _ in range(N)]\n\nif N=1:\n print(1)\nelse:\n for i in range(N):\n Q[P[i]-1]=i\n\n cnt=0\n tmp=0\n for i in range(N-1):\n if Q[i]<Q[i+1]:\n cnt+=1\n else:\n if tmp<cnt+1:\n tmp=cnt+1\n cnt=0\n\n print(N-tmp)\n', 'N=int(input())\nP=[int(input()) for _ in range(N)]\nQ=[0 for _ in range(N)]\n\nfor i in range(N):\n Q[P[i]-1]=i\n\ncnt=0\ntmp=0\nfor i in range(N-1):\n if Q[i]<Q[i+1]:\n cnt+=1\n else:\n if tmp<cnt+1:\n tmp=cnt+1\n cnt=0\n\nif tmp==0:\n tmp=cnt+1\n\nprint(N-tmp)\n'] | ['Runtime Error', 'Accepted'] | ['s293092431', 's065372428'] | [2940.0, 18888.0] | [17.0, 419.0] | [336, 287] |
p03346 | u417658545 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\ndp = [None for _ in range(N)]\nfor i in range(N):\n p = int(input())\n if (p != 1) and (dp[p - 2] == None):\n dp[p - 1] = 1\n else:\n dp[p - 1] = dp[p - 2] + 1\nprint(N - max(dp))', 'N = int(input())\ndp = [None for _ in range(N)]\nfor i in range(N):\n p = int(input())\n if p != 1 and (dp[p - 2]) == None:\n dp[p - 1] = 1\n else:\n dp[p - 1] = dp[p - 2] + 1\nprint(N - max(dp))', 'N = int(input())\ndp = [None for _ in range(N)]\nfor i in range(N):\n p = int(input())\n if 0 <= p - 2 and dp[p - 2] == None:\n dp[p - 1] = 1\n else:\n dp[p - 1] = dp[p - 2] + 1\nprint(N - max(dp))', 'N = int(input())\ndp = [None for _ in range(N)]\nfor i in range(N):\n p = int(input())\n if dp[p - 2] == None or p == 1:\n dp[p - 1] = 1\n else:\n dp[p - 1] = dp[p - 2] + 1\nprint(N - max(dp))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s303797505', 's522955450', 's828286309', 's835593213'] | [4656.0, 4656.0, 4732.0, 11028.0] | [415.0, 430.0, 442.0, 451.0] | [198, 196, 198, 193] |
p03346 | u442810826 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['#N, *a = map(int, open(0).read().split())\ndef main():\n N = int(input())\n a=[]\n for i in range(N):\n a.append(int(input()))\n\n b = [0 for _ in range(N+1)]\n cnt = 1\n ans = 0\n flag = 1\n i = 0\n for i in reversed(range(N)):\n if b[a[i]+1] > 0:\n b[a[i]] = b[a[i]+1] + 1\n else:\n b[a[i]] = 1\n \n return N-max(b)\nprint(main())\n', '#N, *a = map(int, open(0).read().split())\ndef main():\n N = int(input())\n a=[]\n for i in range(N):\n a.append(int(input()))\n\n b = [0 for _ in range(N+2)]\n cnt = 1\n ans = 0\n flag = 1\n i = 0\n for i in reversed(range(N)):\n if b[a[i]+1] > 0:\n b[a[i]] = b[a[i]+1] + 1\n else:\n b[a[i]] = 1\n \n return N-max(b)\nprint(main())\n'] | ['Runtime Error', 'Accepted'] | ['s684803246', 's007513481'] | [12588.0, 18860.0] | [378.0, 404.0] | [394, 394] |
p03346 | u467736898 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\nL = [int(input()) for i in range(N)]\n\nn = 1\nfor i in L:\n if i == n:\n n += 1\n\nm = N\nfor i in reversed(L):\n if int(i) == m:\n m -= 1\n\nn = N - n - 1\n\nprint(min(n, m))', 'N = int(input())\nL = [int(input()) for i in range(N)]\n\n\nP = [0] * (N + 1)\n\nfor p in L:\n P[p] = P[p-1] + 1\n\n\nprint(N-max(P))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s797729175', 's484423513'] | [11180.0, 18888.0] | [440.0, 372.0] | [199, 128] |
p03346 | u547167033 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n=int(input())\np=[int(input()) for _ in range(n)]\ndp=[0]*(n+10)\nfor i in p:\n dp[p]=dp[p-1]+1\nprint(n-max(dp))\n', 'n=int(input())\np=[int(input()) for _ in range(n)]\ndp=[0]*(n+10)\nfor i in p:\n dp[i]=dp[i-1]+1\nprint(n-max(dp))'] | ['Runtime Error', 'Accepted'] | ['s734070947', 's606099884'] | [12588.0, 18888.0] | [339.0, 372.0] | [111, 110] |
p03346 | u651952230 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n=int(input())\np=[]\nfor i in range (n):\n\tp.append(int(input()))\npos=0\nnum=0\nn_th = 0\nfor i in range(n)\n\tif i+1 in p[pos:]:\n\t\tnum += 1\n\t\tpos = p[pos:].index(i+1)+pos\n\telse:\n\t\tif num>n_th:\n\t\t\tn_th = num\n\t\tif i+1 in p:\n\t\t\tnum = 1\n\t\t\tpos = p.index(i+1)\nif num >n_th:\n\tprint (n-num)\nelse:\n\tprint(n-n_th)', 'n=int(input())\np=[]\nfor i in range (n):\n\tp.append(int(input()))\npos=0\nnum=0\nn_th = 0\ns={}\nfor i in p:\n\tif i-1 in s:\n\t\ts[i]=s[i-1]+1\n\telse:\n\t\ts[i]=1\nprint(n-max(s.values()))'] | ['Runtime Error', 'Accepted'] | ['s621294164', 's896945484'] | [2940.0, 35024.0] | [17.0, 439.0] | [298, 172] |
p03346 | u657357805 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['def main():\n N=int(input())\n P=[0]*N\n p=[False]*(N+1)\n P[0]=int(input())\n for i in range(N-1):\n P[i+1=int(input())\n if P[-1]-1 in P[:-1]:\n p[P[-1]-1] = True\n ans=0\n j=0\n for i in range(N):\n if p[i]==True:\n j+=1\n else:\n ans=max(ans,j)\n j=0\n print(N-ans-1)\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N=int(input())\n p=[False]*(N+1)\n c=[False]*(N+1)\n for i in range(N):\n x=int(input())\n c[x]=True\n if c[x-1]:\n p[x-1] = True\n ans=0\n j=0\n for i in range(1,N+1):\n if p[i]:\n j+=1\n else:\n ans=max(ans,j)\n j=0\n ans=max(ans,j)\n print(N-ans-1)\n\nif __name__ == "__main__":\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s130457560', 's073799395'] | [2940.0, 6132.0] | [17.0, 394.0] | [394, 393] |
p03346 | u657541767 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\np = [int(input()) for _ in range(n)]\n\ncnt = 0\nfirst = p[0]\nlast = p[-1]\nfor i in range(n):\n if first > p[i]:\n cnt += 1\n first = p[i]\nfor i in range(n):\n if last < p[i]:\n cnt += 1\n last = p[i]\n\nif p[0] == last:\n cnt += n - p[0] - 1\nprint(cnt)\n', 'n = int(input())\np = [int(input()) for _ in range(n)]\nq = [0] * (n+1)\n\nfor i in range(n):\n q[p[i]] = i\nmaxl = 0\ncnt = 0\nfor i in range(n):\n if q[i+1] > q[i]:\n cnt += 1\n else:\n maxl = max(maxl, cnt)\nprint(n - maxl)\n', 'n = int(input())\np = [int(input()) for _ in range(n)]\nq = [0] * (n+1)\n\nfor i in range(n):\n q[p[i]] = i\nmaxl = 1\ncnt = 1\nfor i in range(1, n):\n if q[i+1] > q[i]:\n cnt += 1\n else:\n maxl = max(maxl, cnt)\n cnt = 1\nprint(n - max(maxl, cnt))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s344027720', 's805797881', 's906565820'] | [11052.0, 18896.0, 18960.0] | [382.0, 447.0, 453.0] | [296, 237, 266] |
p03346 | u667024514 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['import math\nn = int(input())\nlis = [int(input()) for i in range(n)]\nif lis[0] != 0:print(-1);exit()\nans = 0\nnum = 0\nfor i in range(n-1,0,-1):\n if lis[i] > 0:\n ans += lis[i]\n num += lis[i]-1\n lis[i-1] = max(0,lis[i-1]-num)\n lis[i] = 0\n num = max(0,num-1)\n # print(lis,ans)\nprint(ans)', 'n = int(input())\nlis = [int(input()) for i in range(n)]\nli = [-1 for i in range(n)]\nfor i in range(n):\n li[lis[i]-1] = i\ncnt = 0\nans = n-1\nfor i in range(n-1):\n if li[i] < li[i+1]:\n cnt += 1\n else:\n ans = min(ans,n-1-cnt)\n cnt = 0\nans = min(ans,n-1-cnt)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s054356637', 's447049706'] | [11052.0, 18888.0] | [331.0, 431.0] | [325, 294] |
p03346 | u668785999 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\nplist = []\nfor i in range(N):\n x = int(input())\n plist.append(x)\nright = plist[-1]\nprint(right)\ncnt = 0\ncur = right\nind = -1000\nfor i in reversed(range(N-1)):\n if(plist[i] > right):\n cnt += 1\n elif(cur - plist[i] > 1):\n ind = i\n break\n else:\n cur = plist[i]\n\nprint(ind+cnt)', 'import random\nprint(random.randint(1,10**6))', 'd = {}\nN = int(input())\np = [int(input()) for i in range(N)]\n\nfor i in range(N):\n if((p[i]-1) in d):\n d[p[i]] = d[p[i]-1] + 1\n else:\n d[p[i]] = 1\n\nprint(N-max(d.values()))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s317375114', 's397257810', 's515115651'] | [17008.0, 9572.0, 37732.0] | [317.0, 30.0, 344.0] | [333, 44, 191] |
p03346 | u681340020 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ["from itertools import count\nfrom itertools import chain\n\ndef gen_check_numbers(n):\n center = n // 2\n l2 = chain.from_iterable(zip(reversed(range(1, center + 1)), range(center + 1 , n + 1)))\n return l2\n\ndef main():\n n = int(input())\n l = [ int(input().rstrip()) for i in range(n)]\n\n ans = 0\n center = n // 2\n for i in gen_check_numbers(n):\n print(i)\n i1 = l.index(i)\n if i <= center:\n i2 = l.index(i + 1)\n if( i2 < i1):\n l.remove(i)\n l.insert(0,i)\n ans += 1\n else:\n i2 = l.index(i - 1)\n if( i1 < i2):\n l.remove(i)\n l.append(i)\n ans += 1\n print(ans)\n\nif __name__ == '__main__':\n main()\n", "from itertools import count\nfrom itertools import chain\n\ndef gen_check_numbers(n):\n center = n // 2\n l2 = chain.from_iterable(zip(reversed(range(1, center + 1)), range(center + 1 , n + 1)))\n return l2\n\ndef main():\n n = int(input())\n l = [ int(input().rstrip()) for i in range(n)]\n\n ans = 0\n center = n // 2\n for i in gen_check_numbers(n):\n print(i)\n i1 = l.index(i)\n if i <= center:\n i2 = l.index(i + 1)\n if( i2 < i1):\n l.remove(i)\n l.insert(0,i)\n ans += 1\n else:\n i2 = l.index(i - 1)\n if( i1 < i2):\n l.remove(i)\n l.append(i)\n ans += 1\n print(ans, l)\n\nif __name__ == '__main__':\n main()\n", 'n = int(input())\nl = [ int(input().rstrip()) for i in range(n)]\n\ns = {}\nfor i in l:\n if i - 1 in s:\n s[i] = s[i - 1] + 1\n del s[i - 1]\n else:\n s[i] = 1\nprint(n - max(s.values()))\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s280994702', 's608406547', 's545266301'] | [11104.0, 11180.0, 29472.0] | [2104.0, 2104.0, 421.0] | [776, 779, 210] |
p03346 | u711539583 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['import sys\ninput = sys.stdin.readline\nn = int(input())\nmemo = [0 for i in range(n)]\nfor i in range(n):\n memo[int(input())-1] = i\ncand = 0\ntmp = 0\nfor n1, n2 in range(n - 1):\n if n2 > n1:\n tmp += 1\n if tmp > cand:\n cand = tmp\n else:\n tmp = 0\nprint(n - cand - 1)', 'import sys\ninput = sys.stdin.readline\nn = int(input())\nmemo = [0 for i in range(n)]\nfor i in range(n):\n memo[int(input())-1] = i\ncand = 0\ntmp = 0\nfor n1, n2 in zip(memo[:], memo[1:]):\n if n2 > n1:\n tmp += 1\n if tmp > cand:\n cand = tmp\n else:\n tmp = 0\nprint(n - cand - 1)\n'] | ['Runtime Error', 'Accepted'] | ['s515090177', 's697379104'] | [10984.0, 14184.0] | [126.0, 171.0] | [277, 288] |
p03346 | u752072022 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ["import numpy as np\n\n\n\ndef ii():\n return int(input())\n\n\n\n\ndef lvi(N):\n l = []\n for _ in range(N):\n l.append(ii())\n return l\n\n\n\nN = ii()\n\nP = lvi(N)\n\n'''\nP = []\nfor _ in range(N):\n p = ii()\n P.append(p -1)\n\nprint(P)\n'''\n\n#fill( Q, Q + N, 0)\nQ = [0 for i in range(N)]\n\n\n#print( 'Q', Q)\n\nfor i in range(1, N):\n Q[P[i - 1]] = i\n\n\nmaxcnt = 1\ncnt = 1\n\nprint( 'Q', Q)\n\nfor i in range(1, N):\n if Q[i] > Q[i - 1]:\n cnt += 1\n else:\n cnt = 1\n\n maxcnt = max( maxcnt, cnt)\n\n\nprint(N - maxcnt)\n", "import numpy as np\n\ndef ii():\n return int(input())\n\n\ndef lii():\n return list(map(int, input().split(' ')))\n\n\ndef lvi(N):\n l = []\n for _ in range(N):\n l.append(ii())\n return l\n\n\ndef lv(N):\n l = []\n for _ in range(N):\n l.append(input())\n return l\n\n\nN = ii()\nP = []\nfor _ in range(N):\n p = ii()\n P.append(p-1)\n\nQ = [0 for i in range(N)]\nfor i in range(N):\n Q[P[i]] = i\n\nmaxcnt = 1\ncnt = 1\nfor i in range(1, N):\n if Q[i] > Q[i-1]:\n cnt += 1\n else:\n cnt = 1\n\n maxcnt = max(maxcnt, cnt)\n\nprint(N - maxcnt)\n"] | ['Runtime Error', 'Accepted'] | ['s466436532', 's220022046'] | [32544.0, 28220.0] | [638.0, 708.0] | [530, 570] |
p03346 | u761320129 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\nsrc = [int(input()) for i in range(N)]\n\nseq_f = 1\nfor a in src:\n if a == seq_f:\n seq_f += 1\nseq_f -= 1\n\nseq_b = N\nfor a in reversed(src):\n if a == seq_b:\n seq_b -= 1\nseq_b += 1\n\nans = min(seq_b, N-seq_f-1)\nprint(ans)\n', 'N = int(input())\nP = [int(input()) for i in range(N)]\n\nD = {p:i for i,p in enumerate(P)}\npv = N\nl = seq = 0\nfor n in range(1,N+1):\n nx = D[n]\n if pv < nx:\n seq += 1\n else:\n l = max(l,seq)\n seq = 1\n pv = nx\nl = max(l, seq)\n\nprint(N - l)'] | ['Wrong Answer', 'Accepted'] | ['s402537123', 's639846871'] | [11052.0, 37616.0] | [367.0, 381.0] | [254, 268] |
p03346 | u782685137 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n=int(input())\na=[int(input())for _ in[0]*n]\nif n%2==0:\n m1=n//2\n m2=m1+1\n m1i=a.index(m1)\n m2i=a.index(m2)\n a1=[a[i] for i in range(m1i) if a[i]<m1]\n a2=[a[i] for i in range(m1i+1,n) if a[i]<m1]\n al=sorted(a2)+a1\n a3=[a[i] for i in range(m2i) if a[i]>m2]\n a4=[a[i] for i in range(m2i+1,n) if a[i]>m2]\n ar=a4+sorted(a3)\n r=len(a2)+len(a3)\n l=al.index(m1-1)\n r+=m1-2-l\n r+=ar.index(m2+1)\nelse:\n m=n//2+1\n mi=a.index(m)\n a1=[a[i] for i in range(mi) if a[i]<m]\n a2=[a[i] for i in range(mi+1,n) if a[i]<m]\n al=sorted(a2)+a1\n a3=[a[i] for i in range(mi) if a[i]>m]\n a4=[a[i] for i in range(mi+1,n) if a[i]>m]\n ar=a4+sorted(a3)\n r=len(a2)+len(a3)\n l=al.index(m-1)\n r+=m-2-l\n r+=ar.index(m+1)\nprint(r)', 'n=int(input())\np=[int(input())-1for _ in[0]*n]\nq=[0]*n\nfor i in range(n):q[p[i]]=i\nr,c=0,1\nfor i in range(n-1):\n c=c+1if q[i]<q[i+1]else 1\n if r<c:r=c\nif r<c:r=c\nprint(n-r)'] | ['Runtime Error', 'Accepted'] | ['s139581475', 's529320307'] | [14872.0, 18832.0] | [399.0, 420.0] | [772, 178] |
p03346 | u801049006 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\np = [int(input()) for _ in range(n)]\n\nq = [0] * (n+1)\nfor i in range(n):\n q[p[i]] = q[p[i]-1] + 1\n\nprint(q - max(q))\n', 'n = int(input())\np = [int(input()) for _ in range(n)]\n\nq = [0] * (n+1)\nfor i in range(n):\n q[p[i]] = q[p[i]-1] + 1\n\nprint(n - max(q))\n'] | ['Runtime Error', 'Accepted'] | ['s063344360', 's685499379'] | [24788.0, 24748.0] | [298.0, 295.0] | [137, 137] |
p03346 | u824237520 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\n\np = []\nfor i in range(n):\n p.append(int(input()))\n\ndic = {p[0]:1}\nfor i in range(1,n):\n print(dic)\n check = 0\n for k in list(dic):\n \n if p[i] == k + dic[k]:\n dic[k] += 1\n check = 1\n break\n elif p[i] == k - 1:\n dic[p[i]] = 1\n if dic[k] < max(dic.values()) or dic[k] == 1:\n dic.pop(k)\n else:\n dic[p[i]] = 1\n \nprint(n - max(dic.values()))', 'n = int(input())\n\np = []\nfor i in range(n):\n p.append(int(input()))\n\n\nq = [0 for i in range(n)]\nfor i in range(n):\n q[p[i] - 1] = i\n\nresult = 1\ntemp = 1\nfor i in range(1, n):\n if q[i] < q[i-1]:\n if temp > result:\n result = temp\n temp = 1\n else:\n temp += 1\n\nif temp == n:\n result = temp\n\nprint(n - result)'] | ['Wrong Answer', 'Accepted'] | ['s844512452', 's645597629'] | [78832.0, 18888.0] | [2104.0, 458.0] | [502, 351] |
p03346 | u844789719 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ["N = int(input())\nP = [int(input()) for _ in range(N)]\nvi = {v: i for i, v in enumerate(P)}\nbefore = float('inf')\nfor v in range(N, -1, -1):\n if v == 0 or vi[v] > before:\n break\n else:\n before = vi[v]\nbefore = -1\nfor v2 in range(1, N + 2):\n if v2 == N + 1 or vi[v2] < before:\n break\n else:\n before = vi[v2]\nprint(min(v, N - v2))\n", 'N = int(input())\nP = [int(input()) for _ in range(N)]\nvi = {v: i for i, v in enumerate(P)}\nincmax = inc = 1\nbefore = vi[1]\nfor v in range(2, N + 1):\n if vi[v] > before:\n inc += 1\n else:\n inc = 1\n incmax = max(incmax, inc)\n before = vi[v]\nprint(N - incmax)'] | ['Wrong Answer', 'Accepted'] | ['s649161972', 's607307144'] | [34976.0, 34976.0] | [448.0, 494.0] | [368, 281] |
p03346 | u846150137 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n=int(input())\na=[int(input()) for i in range(n)]\n\nal= {}\nds=[]\nans=0\nfor ai in a:\n ds=\n if ai - 1 in al.keys():\n al[ai]=al[ai-1]+1\n ans=max(ans,al[ai-1]+1) \n del al[ai-1]\n else:\n al[ai]=0\n if ai + 1 in al.keys():\n del al[ai]\nprint(n-ans-1)', 'n=int(input())\na=[int(input()) for i in range(n)]\n \nal= {}\nans=0\nfor ai in a:\n if ai - 1 in al.keys():\n al[ai]=al[ai-1]+1\n ans=max(ans,al[ai-1]+1) \n del al[ai-1]\n else:\n al[ai]=0\n\nprint(n-ans-1)'] | ['Runtime Error', 'Accepted'] | ['s513643000', 's676698902'] | [2940.0, 29472.0] | [24.0, 481.0] | [265, 210] |
p03346 | u875361824 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ["def main():\n N = int(input())\n P = [int(input()) for _ in range(N)]\n\n #f1(N, P)\n editorial(N, P)\n\n\ndef editorial(N, P):\n if N == 1:\n print(0)\n return\n\n tmp = 0\n ans = 0\n for i, p in enumerate(P):\n if i == 0 or P[i-1] + 1 == p:\n tmp += 1\n else:\n ans = max(ans, tmp)\n tmp = 1\n\n print(N - ans)\n\n\nif __name__ == '__main__':\n main()\n", "def main():\n N = int(input())\n P = [int(input()) for _ in range(N)]\n\n #f1(N, P)\n editorial(N, P)\n\n\ndef editorial(N, P):\n \n if N == 1:\n print(0)\n return\n\n # WA(N, P)\n a = [0] * (N+1)\n for i, p in enumerate(P):\n a[p] = i\n\n tmp = 1\n max_len = 1\n for i in range(1, N):\n if a[i] < a[i+1]:\n tmp += 1\n max_len = max(max_len, tmp)\n else:\n tmp = 1\n\n ans = N - max_len\n print(ans)\n\n\ndef WA(N, P):\n tmp = 0\n ans = 0\n for i, p in enumerate(P):\n if i == 0 or P[i-1] + 1 == p:\n tmp += 1\n else:\n ans = max(ans, tmp)\n tmp = 1\n\n print(N - ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s056665084', 's476881832'] | [11052.0, 18860.0] | [387.0, 412.0] | [419, 1338] |
p03346 | u876442898 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['# -*- coding: utf-8 -*-\n\nN = int(input())\np = [int(input()) for i in range(N)]\nq = [0] * N\nfor i in range(N):\n q[p[i]-1] = i\n\ncnt = 1\nfor i in range(N-1):\n if q[i+1] - q[i] > 0:\n cnt += 1\n else:\n max_cnt = max(max_cnt, cnt)\n cnt = 1\nprint(N - max_cnt)', '# -*- coding: utf-8 -*-\n\nN = int(input())\np = [int(input()) for i in range(N)]\nq = [0 for i in range(N)]\nfor i in range(N):\n q[p[i]-1] = i\n\ncnt = 1\nmax_cnt = 1\nfor i in range(N-1):\n if q[i+1] > q[i]:\n cnt += 1\n else:\n max_cnt = max(max_cnt, cnt)\n cnt = 1\nmax_cnt = max(max_cnt, cnt)\nprint(N - max_cnt)'] | ['Runtime Error', 'Accepted'] | ['s937183300', 's588019876'] | [18888.0, 18888.0] | [388.0, 447.0] | [410, 460] |
p03346 | u902151549 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['# coding: utf-8\nimport re\nimport math\nfrom copy import deepcopy\nimport fractions\nimport random\nfrom heapq import heappop,heappush\nimport time\nimport sys\nreadline = sys.stdin.readline\n#import numpy as np\nmod=int(10**9+7)\ninf=int(10**20)\nclass union_find():\n def __init__(self,n):\n self.n=n\n self.P=[a for a in range(N)]\n self.rank=[0]*n\n \n def find(self,x):\n if(x!=self.P[x]):self.P[x]=self.find(self.P[x])\n return self.P[x]\n \n def same(self,x,y):\n return self.find(x)==self.find(y)\n \n def link(self,x,y):\n if self.rank[x]<self.rank[y]:\n self.P[x]=y\n elif self.rank[y]<self.rank[x]:\n self.P[y]=x\n else:\n self.P[x]=y\n self.rank[y]+=1\n \n def unite(self,x,y):\n self.link(self.find(x),self.find(y))\n \n def size(self):\n S=set()\n for a in range(self.n):\n S.add(self.find(a))\n return len(S)\ndef bin_(num,size):\n A=[0]*size\n for a in range(size):\n if (num>>(size-a-1))&1==1:\n A[a]=1\n else:\n A[a]=0\n return A\ndef fac_list(n,mod_=0):\n A=[1]*(n+1)\n for a in range(2,len(A)):\n A[a]=A[a-1]*a\n if(mod>0):A[a]%=mod_\n return A\ndef comb(n,r,mod,fac):\n if(n-r<0):return 0\n return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod\ndef next_comb(num,size):\n x=num&(-num)\n y=num+x\n z=num&(~y)\n z//=x\n z=z>>1\n num=(y|z)\n if(num>=(1<<size)):return False\n else:\n return num\ndef get_primes(n,type="number"):\n A=[True]*(n+1)\n A[0]=False\n A[1]=False\n for a in range(2,n+1):\n if A[a]:\n for b in range(a*2,n+1,a):\n A[b]=False\n if(type=="bool"):return A\n B=[]\n for a in range(n+1):\n if(A[a]):B.append(a)\n return B\ndef is_prime(num):\n if(num<=2):return False\n i=2\n while i*i<=num:\n if(num%i==0):return False\n i+=1\n return True\n\nfac=fac_list(10**5+100,mod)\ndef C(n,r):\n if(n-r<0):return 0\n return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod\n\n \n#main\nN=int(input())\nP=[]\nfor a in range(N):\n P.append(int(input())-1)\nQ=[0]*(N)\nfor a in range(N):\n Q[P[a]]=a\n\nans=1\nK=1\nprint(Q)\nfor a in range(1,N-1):\n if Q[a-1]<Q[a]:\n K+=1\n else:\n K=1\n ans=max(K,ans)\nans=N-ans\nprint(ans)\n', '# coding: utf-8\nimport re\nimport math\nfrom copy import deepcopy\nimport fractions\nimport random\nfrom heapq import heappop,heappush\nimport time\nimport sys\nreadline = sys.stdin.readline\n#import numpy as np\nmod=int(10**9+7)\ninf=int(10**20)\nclass union_find():\n def __init__(self,n):\n self.n=n\n self.P=[a for a in range(N)]\n self.rank=[0]*n\n \n def find(self,x):\n if(x!=self.P[x]):self.P[x]=self.find(self.P[x])\n return self.P[x]\n \n def same(self,x,y):\n return self.find(x)==self.find(y)\n \n def link(self,x,y):\n if self.rank[x]<self.rank[y]:\n self.P[x]=y\n elif self.rank[y]<self.rank[x]:\n self.P[y]=x\n else:\n self.P[x]=y\n self.rank[y]+=1\n \n def unite(self,x,y):\n self.link(self.find(x),self.find(y))\n \n def size(self):\n S=set()\n for a in range(self.n):\n S.add(self.find(a))\n return len(S)\ndef bin_(num,size):\n A=[0]*size\n for a in range(size):\n if (num>>(size-a-1))&1==1:\n A[a]=1\n else:\n A[a]=0\n return A\ndef fac_list(n,mod_=0):\n A=[1]*(n+1)\n for a in range(2,len(A)):\n A[a]=A[a-1]*a\n if(mod>0):A[a]%=mod_\n return A\ndef comb(n,r,mod,fac):\n if(n-r<0):return 0\n return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod\ndef next_comb(num,size):\n x=num&(-num)\n y=num+x\n z=num&(~y)\n z//=x\n z=z>>1\n num=(y|z)\n if(num>=(1<<size)):return False\n else:\n return num\ndef get_primes(n,type="number"):\n A=[True]*(n+1)\n A[0]=False\n A[1]=False\n for a in range(2,n+1):\n if A[a]:\n for b in range(a*2,n+1,a):\n A[b]=False\n if(type=="bool"):return A\n B=[]\n for a in range(n+1):\n if(A[a]):B.append(a)\n return B\ndef is_prime(num):\n if(num<=2):return False\n i=2\n while i*i<=num:\n if(num%i==0):return False\n i+=1\n return True\n\nfac=fac_list(10**5+100,mod)\ndef C(n,r):\n if(n-r<0):return 0\n return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod\n\n \n#main\nN=int(input())\nQ=[0]*N\nfor a in range(N):\n Q[int(input())-1]=a\n\nans=1\nK=1\nfor a in range(1,N):\n if Q[a-1]<Q[a]:\n K+=1\n else:\n K=1\n ans=max(K,ans)\nans=N-ans\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s942646834', 's810285580'] | [30440.0, 17420.0] | [573.0, 525.0] | [2353, 2297] |
p03346 | u905582793 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['n = int(input())\na = [int(input()) for i in range(n)]\ncnt1 = 1\ncnt2 = n\nfor i in range(n):\n if a[i] == cnt1:\n cnt1 += 1\n if a[-i-1] == cnt2:\n cnt2 -= 1\nprint(n-max(cnt1,n-cnt2))', 'n = int(input())\na = [int(input()) for i in range(n)]\nls = [0 for i in range(n)]\nfor i in range(n):\n x = a[i]\n ls[x-1] = i+1\ncnt = 1\nans = 0\nls.append(0)\nfor i in range(1,n+1):\n if ls[i]>ls[i-1]:\n cnt += 1\n else:\n ans = max(ans,cnt)\n cnt = 1\nprint(n-ans)'] | ['Wrong Answer', 'Accepted'] | ['s441209889', 's463137846'] | [11180.0, 18996.0] | [394.0, 453.0] | [185, 267] |
p03346 | u982762220 | 2,000 | 1,048,576 | You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation: * Choose an element in the sequence and move it to the beginning or the end of the sequence. Find the minimum number of operations required. It can be proved that it is actually possible to sort the sequence using this operation. | ['N = int(input())\na = [0]\nfor _ in range(N):\n a.append(int(input()))\n\nQ = [0 for i in range(N + 1)]\nfor i in range(N + 1):\n Q[a[i]] = i\nans = 1\nnum = 0\n\nfor idx in range(2, len(a) - 1):\n if a[idx - 1] < a[idx]:\n num += 1\n else:\n ans, num = max(num, ans), 1\n\nprint(N - max(num, ans))', 'N = int(input())\na = [0]\nfor _ in range(N):\n a.append(int(input()))\n\nQ = [0 for i in range(N + 1)]\nfor i in range(N + 1):\n Q[a[i]] = i\nans = 1\nnum = 1\n\nfor idx in range(2, len(Q)):\n if Q[idx - 1] < Q[idx]:\n num += 1\n else:\n ans, num = max(num, ans), 1\n\nprint(N - max(num, ans))\n'] | ['Wrong Answer', 'Accepted'] | ['s053108773', 's263142880'] | [18980.0, 18964.0] | [457.0, 462.0] | [305, 302] |
p03347 | u037430802 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['N = int(input())\nA = [int(input()) for _ in range(N)]\n\nif A[0] != 0:\n print(-1)\n exit()\n\nans = 0\nfor i in reversed(range(1,N)):\n if i == N-1:\n if A[i] == A[i-1] or A[i] ==A[i-1] + 1 or A[i] == 0:\n ans += A[i]\n elif A[i-1] < A[i]-1:\n print(-1)\n exit() \n else:\n print(-1)\n exit()\n elif 1 <= i <= N-2:\n if A[i-1] < A[i]-1:\n print(-1)\n exit()\n elif A[i] == A[i+1]:\n ans += A[i]\n elif A[i] == A[i+1] - 1:\n continue\n elif A[i] > A[i+1]:\n ans += A[i]\n print("aaa", ans)\n\nprint(ans)', 'N = int(input())\nA = [int(input()) for _ in range(N)]\n\nif A[0] != 0:\n print(-1)\n exit()\n\nans = 0\nfor i in reversed(range(1,N)):\n if i == N-1:\n if A[i] - A[i-1] > 1:\n print(-1)\n exit() \n if A[i] == A[i-1] or A[i] ==A[i-1] + 1 or A[i] == 0:\n ans += A[i]\n\n else:\n print(-1)\n exit()\n elif 1 <= i <= N-2:\n if A[i] - A[i-1] > 1:\n print(-1)\n exit()\n elif A[i] == A[i+1]:\n ans += A[i]\n elif A[i] == A[i+1] - 1:\n continue\n elif A[i] > A[i+1]:\n ans += A[i]\n print("aaa", ans)\n\nprint(ans)', 'N = int(input())\nA = [int(input()) for _ in range(N)]\n\n\nif A[0] != 0:\n print(-1)\n exit()\n\n\nans = 0\nprev = 0\nfor n in reversed(A):\n if prev != 0:\n \n if n == prev - 1:\n prev = n\n \n elif n >= prev:\n ans += n\n prev = n\n \n else:\n print(-1)\n exit()\n else:\n ans += n\n prev = n\n\n\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s308992077', 's599940566', 's286984635'] | [13828.0, 13824.0, 11052.0] | [679.0, 666.0, 369.0] | [648, 652, 713] |
p03347 | u075012704 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['N = int(input())\nA = [int(input()) for i in range(N)]\nprint(-1)\nexit()\nif A == [0, 1]:\n print(1)\n exit()\nif A[0] != 0:\n print(-1)\n exit()\n\nfor i in range(N-1):\n if A[i] < A[i+1] and A[i+1]-A[i] != 1:\n print(-1)\n exit()\n if A[i] > i+1:\n print(-1)\n exit()\nans = 0\n\nA = A[::-1]\nM = 0\n\nfor i in range(N-1):\n if A[i] >= A[i+1]:\n ans += M\n M = A[i]\n continue\n M = max(M, A[i])\n\nprint(ans)\n', 'N = int(input())\nA = [int(input()) for i in range(N)]\n\nif A[0] != 0:\n print(-1)\n exit()\n\nfor i in range(N - 1):\n if A[i] < A[i + 1] and A[i + 1] - A[i] != 1:\n print(-1)\n exit()\n if A[i] > i + 1:\n print(-1)\n exit()\n\nans = 0\nfor i in range(1, N):\n if A[i-1] >= A[i]:\n ans += A[i-1]\nprint(ans + A[-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s142878099', 's737365748'] | [11052.0, 11052.0] | [331.0, 454.0] | [456, 349] |
p03347 | u077291787 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['# AGC024C - Sequence Growing Easy\ndef main():\n N, *A = map(int, open(0))\n if A[0]:\n print(-1)\n\n\nif __name__ == "__main__":\n main()', '# AGC024C - Sequence Growing Easy\ndef main():\n N, *A = map(int, open(0))\n if A[0]: # can\'t increment A_0\n print(-1)\n return\n A.append(0)\n ans, B = 0, A[::-1]\n for i, j in zip(B, B[1:]): # check from the last\n if i > j + 1: # increment from left one must be 0 or 1\n print(-1)\n return\n if j >= i: # left one is an end of subsequence\n ans += j\n print(ans)\n\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s565706609', 's818860613'] | [11156.0, 14100.0] | [62.0, 88.0] | [146, 475] |
p03347 | u160414758 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['import sys,collections,random,math;sys.setrecursionlimit(10**7)\ndef Is(): return [int(x) for x in sys.stdin.readline().split()]\ndef Ss(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef S(): return input()\n\nn = I()\nd = collections.defaultdict(int)\nfor i in range(n):\n d[I()] = i\nd[0] = n\nt,maxinc = 0,0\nfor i in range(1,n+1):\n if d[i-1] < d[i]:\n t += 1\n maxinc = max(maxinc,t)\n else:\n t = 0\nprint(n-1-maxinc)', 'import sys,collections,random,math;sys.setrecursionlimit(10**7)\ndef Is(): return [int(x) for x in sys.stdin.readline().split()]\ndef Ss(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef S(): return input()\n\nn = I()\nt = I()\nif t != 0:\n print(-1)\n exit()\nsums = 0\nfor i in range(n-1):\n c = I()\n if c-t > 1 or c > i+1:\n print(-1)\n exit()\n if c-t != 1:\n sums += t\n s = 0\n if i == n-2:\n sums += c\n t = c\nprint(sums)'] | ['Wrong Answer', 'Accepted'] | ['s736269252', 's472246665'] | [60024.0, 4720.0] | [355.0, 234.0] | [472, 500] |
p03347 | u163320134 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n=int(input())\narr=[int(input()) for _ in range(n)]\nl=0\nflag=True\nfor i in range(n):\n if arr[i]==0:\n l=1\n else:\n if arr[i]>l:\n flag=False\n break\n l+=1\n if i!=0:\n if arr[i]-arr[i-1]>=1:\n flag=False\n break\nif flag==False:\n print(-1)\nelse:\n ans=arr[-1]\n tmp=arr[-1]\n for i in range(n-2,-1,-1):\n if arr[i]<tmp:\n tmp=arr[i]\n else:\n ans+=arr[i]\n if tmp!=arr[i]:\n tmp=arr[i]\n print(ans)', 'n=int(input())\narr=[int(input()) for _ in range(n)]\nl=0\nflag=True\nfor i in range(n):\n if arr[i]==0:\n l=1\n else:\n if arr[i]>l:\n flag=False\n break\n l+=1\n if i!=0:\n if arr[i]-arr[i-1]>=2:\n flag=False\n break\nif flag==False:\n print(-1)\nelse:\n ans=arr[-1]\n tmp=arr[-1]\n for i in range(n-2,-1,-1):\n if arr[i]<tmp:\n tmp=arr[i]\n else:\n ans+=arr[i]\n if tmp!=arr[i]:\n tmp=arr[i]\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s795217180', 's086575531'] | [11052.0, 11176.0] | [420.0, 470.0] | [447, 447] |
p03347 | u174404613 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n=int(input())\nl=[int(input()) for _ in range(n)]\nans=0\nif l[0]!=0:\n print(-1)\n exit()\nfor i in range(n-1):\n if l[i+1]-l[i]>1:\n print(-1)\n exit()\n elif (l[i]+1==l[i+1]):\n ans+=1\n else:\n\tans+=l[i+1]\nprint(ans)\n', 'n=int(input())\nl=[int(input()) for _ in range(n)]\nans=0\nif l[0]!=0:\n print(-1)\n exit()\nfor i in range(n-1):\n if (l[i]+1==l[i+1]):\n ans+=1\n elif (l[i]>=l[i+1]):\n ans+=l[i+1]\n else:\n print(-1)\n exit()\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s337038458', 's754202532'] | [9036.0, 17016.0] | [26.0, 309.0] | [223, 227] |
p03347 | u177132624 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['N = int(input())\nl =[]\n#deal with error\nfor i in range(N):\n l.append(int(input()))\n if i == 0 and l[i]!=0:\n print(-1)\n break\n if i>=1:\n if l[i]-l[i-1]>1 :\n print(-1)\n break\n\ncounter=0\ncounter_n=l[0]\nl = l[::-1]\nfor i in range(N-1):\n if l[i]<l[i+1]:\n counter+=counter_n\n counter_n=0\n elif l[i]==l[i+1]:\n if counter_n == 0:\n counter_n = 2*l[i]\n else:\n counter_n += l[i]\n counter_n += l[i]\n elif l[i] == l[i+1]+1:\n counter += 1\ncounter += counter_n\nprint(counter)\n \n \n', 'N = int(input())\nl =[]\n#deal with error\nfor i in range(N):\n l.append(int(input()))\n if i == 0 and l[i]!=0:\n print(-1)\n exit()\n if i>=1:\n if l[i]-l[i-1]>1 :\n print(-1)\n exit()\n\ncounter=0\ncounter_n=l[0]\nl = l[::-1]\nfor i in range(N-1):\n if l[i]<l[i+1]:\n counter+=counter_n\n counter_n=0\n elif l[i]==l[i+1]:\n if counter_n == 0:\n counter_n = 2*l[i]\n else:\n counter_n += l[i]\n counter_n += l[i]\n elif l[i] == l[i+1]+1:\n counter += 1\ncounter += counter_n\nprint(counter)\n \n \n', 'N = int(input())\nl =[]\n#deal with error\nfor i in range(N):\n l.append(int(input()))\n if i == 0 and l[i]!=0:\n print(-1)\n exit()\n if i>=1:\n if l[i]-l[i-1]>1 :\n print(-1)\n exit()\n \nans = 0\npre = -1\nfor a in l[::-1]:\n if pre - 1 != a:\n ans += a\n pre = a\nprint(ans)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s287313284', 's726949786', 's357312297'] | [12616.0, 12616.0, 12616.0] | [543.0, 534.0, 455.0] | [668, 670, 324] |
p03347 | u223904637 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n=int(input())\nli=[0]*n\nfor i in range(n):\n li[i]=int(input())\nfl=0\nans=0\nif li[0]!=0:\n fl+=1\nfor i in range(n-1):\n if li[i]>=li[i+1]:\n ans+=li[i]\n if li[i+1]-li[i]>1:\n fl+=1\nif fl>0:\n print(-1)\nelse:\n print(ans)\n ', 'n=int(input())\nli=[0]*n\nfor i in range(n):\n li[i]=int(input())\nfl=0\nans=0\nif li[0]!=0:\n fl+=1\nfor i in range(n-1):\n if li[i]>=li[i+1]:\n ans+=li[i]\n if li[i+1]-li[i]>1:\n fl+=1\nif fl>0:\n print(-1)\nelse:\n print(ans+li[n-1])\n \n'] | ['Wrong Answer', 'Accepted'] | ['s879695987', 's094010346'] | [10868.0, 12916.0] | [495.0, 450.0] | [253, 262] |
p03347 | u240733052 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['line = input()\n\nN = int(line)\nA = np.array([0]*N)\n\nfor i in range(N):\n line = input()\n A[i] = int(line)\n\n \ndef IsNotPossible(A):\n for i in range(N): \n ai = A[i]\n\n if ai > i:\n return 1\n\n for j in range(ai):\n if A[i-1-j] < ai-1-j:\n return 1\n\n return 0\n\nif IsNotPossible(A):\n print(-1)\n \nelse:\n count = 0\n for i in range(N-1):\n a = A[N-1-i]\n \n if a == 0:\n continue\n elif a == A[N-2-i] + 1:\n count += 1\n else:\n count += a\n \n print(count)', 'def main():\n\n N = int(input())\n a = int(input())\n A = [a]\n\n if a != 0:\n return -1\n\n else:\n for i in range(N-1):\n a_ = int(input())\n if a_ > a + 1:\n return -1\n\n else:\n a = a_\n A.append(a)\n \n count = 0\n for i in range(N-1):\n a = A[N-1-i]\n \n if a == 0:\n continue\n elif a == A[N-2-i] + 1:\n count += 1\n else:\n count += a\n \n return count\n\nprint(main())'] | ['Runtime Error', 'Accepted'] | ['s817750732', 's060238924'] | [3064.0, 11028.0] | [17.0, 419.0] | [600, 597] |
p03347 | u369402805 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['N = int(input())\nans = -1\nbef = -1\nfor i in range(N):\n now = int(data[input()])\n if now - bef > 1:\n ans = -1\n break\n elif now - bef == 1:\n ans += 1\n bef = now\n else:\n ans += now\n bef = now\n\nprint(str(ans))', 'N = int(input())\nans = -1\nbef = -1\nfor i in range(N):\n now = int(input())\n if now - bef > 1:\n ans = -1\n break\n elif now - bef == 1:\n ans += 1\n bef = now\n else:\n ans += now\n bef = now\n \nprint(str(ans))'] | ['Runtime Error', 'Accepted'] | ['s015216021', 's329721538'] | [3060.0, 3188.0] | [19.0, 437.0] | [259, 254] |
p03347 | u392319141 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['print(-1)', 'import sys\ninput = sys.stdin.buffer.readline\n\nN = int(input())\nG = [[]]\nA = []\n\nfor _ in range(N):\n a = int(input())\n if len(G[-1]) > 0 and G[-1][-1] > a:\n G.append([])\n A.append(a)\n G[-1].append(a)\n\ndef isOk():\n if any(l[-1] + 1 < r[0] for l, r in zip(G, G[1:])):\n return False\n for grp in G:\n if any(l + 1 < r for l, r in zip(grp, grp[1:])):\n return False\n return A[0] == 0\n\nif not isOk():\n print(-1)\n exit()\n\nans = 0\nA = [-10**18] + A[::-1]\n\nfor r, l in zip(A, A[1:]):\n if l >= r:\n ans += l\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s743055774', 's535041796'] | [3064.0, 27908.0] | [19.0, 214.0] | [9, 574] |
p03347 | u413165887 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n,*a=map(int,open(0))\nr=-1\nfor i in range(n):\n if a[i-1] >= a[i]:r+=a[i]\n elif a[i-1]+1==a[i]:r+=1\n else:r=-1;break\nprint(r)', 'n,r=int(input()),-1\na = [int(input()) for _i in range(n)]+[-1]\nfor i in range(n):\n if a[i-1] >= a[i]:r+=a[i]\n elif a[i-1]+1==a[i]:r+=1\n else:r=-1;break\nprint(r)'] | ['Wrong Answer', 'Accepted'] | ['s474283370', 's780645013'] | [11036.0, 12588.0] | [145.0, 407.0] | [133, 169] |
p03347 | u536113865 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n = int(input())\nx = [int(input()) for _ in range(n)]\nf = 0\n\nif x[0]>0: f = 1\nfor i in range(n-1):\n if x[i]+1 < x[i+1]: f = 1\nimport sys\nif f:\n print(-1)\n sys.exit()\nans = 0\nfor i in range(n-1):\n if x[i+1] == x[i]+1:\n ans += 1\n else:\n ans += x[i+1]\n print(ans)\nprint(ans)', 'n = int(input())\nx = [int(input()) for _ in range(n)]\nf = 0\n\nif x[0]>0: f = 1\nfor i in range(n-1):\n if x[i]+1 < x[i+1]: f = 1\nimport sys\nif f:\n print(-1)\n sys.exit()\nans = 0\nfor i in range(n-1):\n if x[i+1] == x[i]+1:\n ans += 1\n else:\n ans += x[i+1]\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s247317324', 's534397602'] | [13220.0, 11052.0] | [597.0, 426.0] | [303, 288] |
p03347 | u648881683 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ["import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n N = I()\n A = [I() for _ in range(N)]\n\n is_ok = True\n\n \n if [A[i] for i in range(N) if A[i] > i]:\n is_ok = False\n else:\n for i in range(N - 1):\n if A[i] + 1 < A[i+1]:\n is_ok = False\n break\n\n if is_ok:\n \n ans = 0\n if N == 1:\n ans = 1\n else:\n for i in range(N - 1):\n if A[i] >= A[i+1]:\n ans += A[i]\n if A[-2] >= A[-1]:\n ans += A[-1]\n else:\n ans += 1\n\n if is_ok:\n print(ans)\n else:\n print(-1)\n\nif __name__ == '__main__':\n resolve()\n", "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n N = I()\n A = [I() for _ in range(N)]\n\n is_ok = True\n\n \n if [A[i] for i in range(N) if A[i] > i]:\n is_ok = False\n else:\n for i in range(N - 1):\n if A[i] + 1 < A[i+1]:\n is_ok = False\n break\n\n if is_ok:\n \n ans = 0\n for i in range(N - 1):\n if A[i] >= A[i+1]:\n ans += A[i]\n if A[-2] >= A[-1]:\n ans += A[-1]\n else:\n ans += 1\n\n if is_ok:\n print(ans)\n else:\n print(-1)\n\nif __name__ == '__main__':\n resolve()\n", "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n N = I()\n A = [I() for _ in range(N)]\n\n is_ok = True\n\n \n if [A[i] for i in range(N) if A[i] > i]:\n is_ok = False\n else:\n for i in range(N - 1):\n if A[i] + 1 < A[i+1]:\n is_ok = False\n break\n\n if is_ok:\n \n ans = 0\n if N == 1:\n ans = 0\n else:\n for i in range(N - 1):\n if A[i] >= A[i+1]:\n ans += A[i]\n ans += A[-1]\n\n if is_ok:\n print(ans)\n else:\n print(-1)\n\nif __name__ == '__main__':\n resolve()\n"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s730766422', 's992666119', 's962085381'] | [19304.0, 19416.0, 19396.0] | [166.0, 166.0, 174.0] | [1280, 1199, 1202] |
p03347 | u667024514 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['import math\nn = int(input())\nlis = []\nfor i in range(n):lis.append(int(input()))\nif lis[0] != 0:\n print("-1")\n exit()\ncou = 0\nprint(lis,cou)\nfor k in range(n-1):\n if lis[n-(k+1)] > lis[n-(k+2)]:\n cou += math.ceil(lis[n-(k+1)] / (lis[n-(k+2)]+1))\n lis[n-(k+1)] = 0\n else:\n cou += lis[n-(k+1)]\n lis[n-(k+2)] -= lis[n-(k+1)]-1\n lis[n-(k+1)] = 0\n print(lis,cou)\nprint(cou)', 'import math\nn = int(input())\nlis = []\nfor i in range(n):lis.append(int(input()))\nif lis[0] != 0:\n print("-1")\n exit()\ncou = 0\nprint(lis,cou)\nfor k in range(n-1):\n if lis[n-(k+1)] > lis[n-(k+2)]:\n a = math.ceil(lis[n-(k+1)] / (lis[n-(k+2)]+1))\n cou += a\n lis[n-(k+1)] = 0\n lis[n-(k+2)] = min(lis[n-(k+1)]-1,lis[n-(k+2)],math.ceil(lis[n-(k+1)]/a))\n else:\n cou += lis[n-(k+1)]\n lis[n-(k+2)] -= lis[n-(k+1)]-1\n lis[n-(k+1)] = 0\n print(lis,cou)\nprint(cou)', 'import math\nn = int(input())\nlis = []\nfor i in range(n):lis.append(int(input()))\nif lis[0] != 0:\n print("-1")\n exit()\ncou = 0\nprint(lis,cou)\nfor k in range(n-1):\n if lis[n-(k+1)] > lis[n-(k+2)]:\n a = math.ceil(lis[n-(k+1)] / (lis[n-(k+2)]+1))\n cou += a\n lis[n-(k+1)] = 0\n lis[n-(k+2)] = min(lis[n-(k+1)]-1,lis[n-(k+2)],math.ceil(lis[n-(k+1)]/a)-1)\n else:\n cou += lis[n-(k+1)]\n lis[n-(k+2)] -= lis[n-(k+1)]-1\n lis[n-(k+1)] = 0\n print(lis,cou)\nprint(cou)', 'n = int(input())\nlis = [int(input()) for i in range(n)]\nif lis[0] != 0:print(-1);exit()\nans = 0\nfor i in range(n-1,0,-1):\n if lis[i-1] - lis[i] > 1:print(-1);exit()\n elif lis[i-1] - lis[i] == 1:ans += 1\n else:ans += lis[i]\nprint(ans)', 'n = int(input())\nlis = [int(input()) for i in range(n)]\nif lis[0] != 0:print(-1);exit()\nans = 0\nfor i in range(n-1,0,-1):\n if lis[i-1] - lis[i] > 1:print(-1);exit()\n elif lis[i-1] - lis[i] == 1:ans += 1\n else:ans += lis[i-1]\nprint(ans)', 'import math\nn = int(input())\nlis = []\nfor i in range(n):lis.append(int(input()))\nif lis[0] != 0:\n print("-1")\n exit()\ncou = 0\nprint(lis,cou)\nfor k in range(n-1):\n if lis[n-(k+1)] > lis[n-(k+2)]:\n cou += math.ceil(lis[n-(k+1)] / (lis[n-(k+2)]+1))\n lis[n-(k+1)] = 0\n lis[n-(k+2)] = min(lis[n-(k+1)]-1,lis[n-(k+2)])\n else:\n cou += lis[n-(k+1)]\n lis[n-(k+2)] -= lis[n-(k+1)]-1\n lis[n-(k+1)] = 0\n print(lis,cou)\nprint(cou)', 'n = int(input())\nlis = [int(input()) for i in range(n)]\nif lis[0] != 0:print(-1);exit()\nans = 0\nfor i in range(n-1,0,-1):\n if lis[i] - lis[i-1] > 1:print(-1);exit()\n elif lis[i] - lis[i-1] == 1:ans += 1\n else:ans += lis[i]\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s081100246', 's233579283', 's354952980', 's499753845', 's823492428', 's848072744', 's357947227'] | [146352.0, 146352.0, 146352.0, 11048.0, 11048.0, 146352.0, 11052.0] | [2104.0, 2104.0, 2104.0, 422.0, 420.0, 2104.0, 419.0] | [418, 515, 517, 242, 244, 474, 242] |
p03347 | u670180528 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n, *a = map(int, open(0).read().split())\nans = 0\nif a[0] != 0:\n\tprint(-1)\n\texit()\nfor x, y in zip(a, a[1:]):\n\tif x + 1 < y:\n\t\tprint(-1)\n\t\texit()\n\tif x >= y:\n\t\tans += x\nprint(ans)\n', 'n, *a = map(int, open(0).read().split())\nans = 0\nif a[0] != 0:\n\tprint(-1)\n\texit()\nfor x, y in zip(a, a[1:]+[0]):\n\tif x + 1 < y:\n\t\tprint(-1)\n\t\texit()\n\tif x >= y:\n\t\tans += x\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s357460852', 's963702947'] | [25140.0, 25132.0] | [112.0, 110.0] | [179, 183] |
p03347 | u736729525 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['print(-1)', '\n\ndef solve(N, A):\n c = 0\n z = 0\n if A[0] != 0:\n return -1\n for i in range(1, N):\n if A[i] == 0:\n z = 0\n c+=A[i-1]\n elif A[i-1] < A[i] - 1:\n return -1\n elif A[i] <= i - z:\n if A[i] != A[i-1]+1:\n c += A[i-1]\n else:\n return -1\n #print("A[%d]=%d, c=%d" % (i, A[i], c))\n c += A[-1]\n return c\n\ndef main():\n import sys\n input = sys.stdin.readline\n N = int(input())\n A = [0]*N\n for i in range(N):\n A[i] = int(input())\n print(solve(N, A))\n\nmain()\n'] | ['Wrong Answer', 'Accepted'] | ['s483645537', 's103663682'] | [2940.0, 10868.0] | [17.0, 192.0] | [9, 594] |
p03347 | u738835924 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['N = int(input())\n\nstart = int(input())\nflag = 0\nif start != 0:\nflag = 1\nt = 0\n\nfor i in range(N-1):\n k = int(input())\n if k == start:\n t += start\n elif k == start + 1:\n t += 1\n start = k\n elif k == 0:\n start = 0\n elif k > start + 1:\n t = -1\n break\n else:\n t += k\n start = k\n\nif flag ==1:\n t = -1\nprint(t)', 'N = int(input())\n\nstart = int(input())\nflag = 0\nif start != 0:\nflag = 1\nt = 0\n\nfor i in range(N-1):\n k = int(input())\n if k == start:\n t += start\n elif k == start + 1:\n t += 1\n start = k\n elif k == 0:\n start = 0\n elif k > start + 1:\n t = -1\n break\n else:\n t += k\n start = k\n\nif flag ==1:\n t = -1\nprint(t)', 'N = int(input())\n\nstart = int(input())\nflag = 0\nif start != 0:\n flag = 1\nt = 0\n\nfor i in range(N-1):\n k = int(input())\n if k == start:\n t += start\n elif k == start + 1:\n t += 1\n start = k\n elif k == 0:\n start = 0\n elif k > start + 1:\n t = -1\n break\n else:\n t += k\n start = k\n\nif flag ==1:\n t = -1\nprint(t)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s491258783', 's924523265', 's745071989'] | [2940.0, 2940.0, 3064.0] | [17.0, 18.0, 423.0] | [312, 312, 313] |
p03347 | u740284863 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n = int(input())\na = [int(input()) for _ in range(n)]\nans = 0\nif a[0] != 0:\n print(-1)\n exit()\nfor i in range(n-1):\n if a[i+1] - a[i] > 1:\n print(-1)\n exit()\nfor _ in range(n):\n if set(a) == set([-1,0]) or set(a) == set([0]):\n break\n i = a.argmax()\n if i == 0:\n print(-1)\n exit()\n if a[i-1] + 1 == a[i]:\n a[i] = -1\n ans += 1\n elif a[i-1] == -1:\n a[i-1] = a[i] - 1\n a[i] = -1\n ans += 1\n else:\n print(-1)\n exit()\nprint(ans)', 'n = int(input())\nprev = ans = -1\na = [int(input()) for _ in range(n)]\nfor i in a:\n if i - prev > 1:\n print(-1)\n exit()\n elif i - prev == 1:\n ans += 1\n else:\n ans += i\n prev = i\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s673235503', 's285474594'] | [31672.0, 16960.0] | [290.0, 290.0] | [532, 227] |
p03347 | u786607349 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n = int(input())\na = []\nans = 0\nflag = True\nfor i in range(n):\n A = int(input())\n a.append(A)\nnext = 0\nfor i in range(n-1,-1,-1):\n if a[i] == 0:\n next = 0\n continue\n if next - a[i] == 1:\n next = a[i]\n continue\n if next - a[i] >= 2:\n flag = False\n break\n next = a[i]\n ans += a[i]\nif a[0] != 0:\n flag = False\n# if flag:\n# #print(ans)\n# else:\n# #print(-1)\nprint(-1)\n', 'n = int(input())\na = []\nans = 0\nflag = True\nfor i in range(n):\n A = int(input())\n a.append(A)\nnext = 0\nfor i in range(n-1,-1,-1):\n if a[i] == 0:\n next = 0\n continue\n if next - a[i] == 1:\n next = a[i]\n continue\n if next - a[i] >= 2:\n flag = False\n break\n next = a[i]\n ans += a[i]\nif a[0] != 0:\n flag = False\nif flag:\n #print(ans)\nelse:\n #print(-1)\nprint(-1)\n', 'n = int(input())\na = []\nans = 0\nflag = True\nfor i in range(n):\n A = int(input())\n a.append(A)\nnext = 0\nfor i in range(n-1,-1,-1):\n if next - a[i] >= 2:\n flag = False\n break\n if a[i] == 0:\n next = 0\n continue\n if next - a[i] == 1:\n next = a[i]\n continue\n next = a[i]\n ans += a[i]\nif a[0] != 0:\n flag = False\nif flag:\n print(ans)\nelse:\n print(-1)\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s196125015', 's937607134', 's895402581'] | [11052.0, 3064.0, 11048.0] | [438.0, 17.0, 444.0] | [437, 429, 417] |
p03347 | u798818115 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['# coding: utf-8\n# Your code here!\nN=int(input())\nl=[]\nfor i in range(N):\n l.append(int(input()))\n\ndef calc(list):\n num=0\n sum=0\n l.pop(-1)\n l_max=max(list)\n for i in range(1,l_max+1)[::-1]:\n num+=l.count(i)\n sum+=num\n return sum+1\n \n\ntemp=[]\nans=0\njudge=True\nnum=N\n\nwhile judge:\n num-=1\n \n if (l[num]-l[num-1])!=0 and (l[num]-l[num-1])!=1:\n judge=False\n elif l[num]==1:\n temp=l[num:]\n ans+=calc(temp)\n del l[num:]\n temp.clear\n elif l[num]==0:\n l.pop(0)\n else:\n pass\n if num==0:\n break\n \nif judge==False:\n print(-1)\nelse:\n print(ans)\n', '# coding: utf-8\n# Your code here!\nN=int(input())\n\npre=int(input())\nif pre!=0:\n print(-1)\n exit()\n\nans=0\ncount=0\nfor _ in range(N-1):\n A=int(input())\n if A-pre>1:\n print(-1)\n exit()\n if A==pre:\n count+=1\n else:\n ans+=pre*count\n if A<pre:\n ans+=(A-1)\n ans+=1\n count=0\n #print(_,ans)\n pre=A\n\nprint(ans+pre*count)'] | ['Wrong Answer', 'Accepted'] | ['s172880075', 's877502166'] | [12564.0, 3064.0] | [2104.0, 473.0] | [697, 397] |
p03347 | u874935184 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ['n = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nif a[0] != 0:\n print("-1")\nelse:\n v = []\n for i in range(1, len(a)):\n v.append((a[i], -i))\n v.sort()\n x = [0] * len(a)\n wala = False\n for y in v:\n #print(y)\n #print(x)\n if x[-y[1]] == 0:\n continue\n elif x[-y[1] - 1] + 1 == y[0]:\n x[-y[1]] = y[0]\n else:\n wala = True\n break\n if wala:\n print("-1")\n else:\n print(len(a) - a.count(0) + 1)\n\n ', 'n = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nif a[0] != 0:\n print("-1")\nelse:\n x = [0] * len(a)\n d = [0] * len(a)\n dd = [0] * len(a)\n\n c = 0\n s = 10**6\n #0 1 1 0 1 2 2 2 3\n wala = False\n for i in range(len(a) - 1, 0, -1):\n #print("-")\n if i <= s and a[i] == 0:\n #print("X")\n continue\n if i - a[i] < 0 or i - a[i] > s:\n #print("Y")\n wala = True\n break\n if s + a[i] == i:\n continue\n s = min(s, i - a[i])\n c += a[i]\n if wala:\n print("-1")\n else:\n print(c)\n'] | ['Wrong Answer', 'Accepted'] | ['s136065637', 's981236376'] | [33320.0, 17704.0] | [647.0, 523.0] | [537, 633] |
p03347 | u926295427 | 2,000 | 1,048,576 | There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1. | ["#!python\n# -*- coding: utf-8 -*-\n\n\ndef main():\n N = int(input())\n A = [int(input()) for i in range(N)]\n X = [0 for i in range(N)]\n\n if A[0] != 0:\n print(-1)\n return\n\n count = 0\n\n for i in range(N - 1, -1, -1):\n X[i] = X[i + 1] - 1\n if A[i] == X[i]:\n continue\n\n count += A[i]\n X[i] = A[i]\n\n print(count)\n\n\nif __name__ == '__main__':\n main()\n", "#!python\n# -*- coding: utf-8 -*-\n\n\ndef main():\n N = int(input())\n A = [int(input()) for i in range(N)]\n X = [0 for i in range(N)]\n A += [0]\n X += [0]\n\n count = 0\n\n if A[0] != 0:\n print(-1)\n return\n\n for i in range(N - 1, -1, -1):\n if A[i - 1] + 1 < A[i]:\n print(-1)\n return\n\n X[i] = max(0, X[i + 1] - 1)\n if A[i] == X[i]:\n continue\n\n count += A[i]\n X[i] = A[i]\n\n print(count)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Accepted'] | ['s211196557', 's236468745'] | [12636.0, 18864.0] | [338.0, 465.0] | [417, 525] |
p03348 | u226155577 | 2,000 | 1,048,576 | Coloring of the vertices of a tree G is called a _good coloring_ when, for every pair of two vertices u and v painted in the same color, picking u as the root and picking v as the root would result in isomorphic rooted trees. Also, the _colorfulness_ of G is defined as the minimum possible number of different colors used in a good coloring of G. You are given a tree with N vertices. The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i. We will construct a new tree T by repeating the following operation on this tree some number of times: * Add a new vertex to the tree by connecting it to one of the vertices in the current tree with an edge. Find the minimum possible colorfulness of T. Additionally, print the minimum number of leaves (vertices with degree 1) in a tree T that achieves the minimum colorfulness. | ['N = int(input())\nG = [[] for i in range(N)]\nE9 = []\nfor i in range(N-1):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n E9.append((a-1, b-1))\n\ndef encode(v, p):\n res = []\n tmp = []\n l = 0\n P = []\n def edfs(v, p):\n res = [0]\n cs = []\n for w in G[v]:\n if w == p:\n continue\n cs.append(edfs(w, v))\n cs.sort()\n for c in cs:\n res.extend(c)\n res.append(1)\n return res\n E = edfs(v, p)\n return E\n\ndef calc(E):\n st = []\n C = [0]\n P = []\n L = len(E)\n l = 0\n for i in range(L):\n if i and E[i-1] < E[i]:\n l += 1\n if E[i] == 0:\n st.append(i)\n P.append(None)\n else:\n j = st.pop()\n P.append(i)\n #P[i] = j\n P[j] = i\n C.append(l)\n return C, P\n\nINF = 10**9\ndef merge(e1, e2):\n l1 = len(e1); l2 = len(e2)\n dp = [[0] * (l1+1) for i in range(l2+1)]\n\n C1, P1 = calc(e1)\n C2, P2 = calc(e2)\n\n prev = {}\n memo = {}\n def dfs(x, y):\n if (x, y) in memo:\n return memo[x, y]\n if x == l1 and y == l2:\n return 0\n res = INF\n p = None\n if x < l1 and y < l2 and e1[x] == e2[y]:\n r = dfs(x+1, y+1) + max(C1[x+1]-C1[x], C2[y+1]-C2[y])\n if r < res:\n res = r\n p = (x+1, y+1)\n if x < l1 and e1[x] == 0:\n r = dfs(P1[x]+1, y) + C1[P1[x]+1] - C1[x]\n if r < res:\n res = r\n p = (P1[x]+1, y)\n if y < l2 and e2[y] == 0:\n r = dfs(x, P2[y]+1) + C2[P2[y]+1] - C2[y]\n if r < res:\n res = r\n p = (x, P2[y]+1)\n memo[x, y] = res\n prev[x, y] = p\n return res\n prev[0, 0] = (0, 0)\n r = dfs(0, 0)\n v = (0, 0)\n res = []\n while v != (l1, l2):\n print(v)\n px, py = v\n x, y = v = prev[v]\n if px != x and py != y:\n res.append(e1[px])\n elif px != x:\n res.extend(e1[px:x])\n else:\n res.extend(e2[py:y])\n print(res)\n return r, res\n\nfrom collections import deque\ndef bfs(v, p=-1):\n que = deque([v])\n dist = {v: 0, p: 0}\n prev = {}\n while que:\n u = que.popleft()\n d = dist[u]\n for w in G[u]:\n if w not in dist:\n dist[w] = d + 1\n prev[w] = u\n que.append(w)\n w = u\n res = []\n while w != v:\n res.append(w)\n w = prev[w]\n res.append(v)\n return u, res\ndef solve(u, v):\n if bfs(u, v) > (L+1)//2 < bfs(v, u):\n return 10**9\n E1 = encode(u, v)\n E2 = encode(v, u)\n #print(u, v, E1, E2)\n return merge(E1, E2)[0]*2\ndef vsolve(v):\n if bfs(u) > (L+1)//2:\n return 10**9\n E0 = encode(G[v][0], v)\n for w in G[v][1:]:\n E1 = encode(w, w)\n _, E0 = merge(E0, E1)\n C, P = calc(E0)\n \n return C[-1]*len(G[v])\nv, _ = bfs(0)\nw, D = bfs(v)\nL = len(D)\n\ncol = (L + 1) // 2\n\nans = 10**18\nfor a, b in E9:\n ans = min(ans, solve(a, b))\nfor v in range(N):\n ans = min(ans, vsolve(v))\nprint(col, ans)\n', 'N = int(input())\nG = [[] for i in range(N)]\nfor i in range(N-1):\n a, b = map(int, input().split())\n G[a-1].append(b-1)\n G[b-1].append(a-1)\n\nfrom collections import deque\ndef bfs(v):\n que = deque([v])\n dist = {v: 0}\n prev = {v: v}\n while que:\n u = que.popleft()\n d = dist[u]\n for w in G[u]:\n if w in dist:\n continue\n dist[w] = d + 1\n prev[w] = u\n que.append(w)\n w = u\n D = []\n while w != v:\n D.append(w)\n w = prev[w]\n D.append(v)\n return u, D\n\nfrom collections import deque\ndef solve(u, v = -1):\n que = deque([u])\n if v != -1:\n que.append(v)\n used = set([u, v])\n D = {v: 0, u: 0}\n E = {}\n if v != -1:\n E[0] = max(len(G[v]), len(G[u]))-1\n else:\n E[0] = len(G[u])\n x = v\n while que:\n v = que.popleft()\n d = D[v]\n for w in G[v]:\n if w in used:\n continue\n D[w] = d + 1\n que.append(w)\n used.add(w)\n E[d+1] = max(E.get(d+1, 0), len(G[w])-1)\n res = 2 if x != -1 else 1\n for v in E.values():\n if v: res *= v\n return res\n\nD = bfs(bfs(0)[0])[1]\nL = len(D)\n\ncol = (L + 1) // 2\n\nif L % 2 == 1:\n ans = 10**18\n v = D[L//2]\n for w in G[v]:\n ans = min(ans, solve(v, w))\n ans = min(ans, solve(v))\nelse:\n v = D[L//2-1]; w = D[L//2]\n ans = solve(v, w)\nprint(col, ans)\n'] | ['Runtime Error', 'Accepted'] | ['s696315189', 's886102396'] | [3700.0, 3444.0] | [28.0, 30.0] | [3266, 1458] |
p03355 | u007765868 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['string = input()\nk = int(input())\nif len(string) >= k:\n substrs = set()\n ls = sorted(list(string))\n for i in range(5):\n for s, c in enumerate(string):\n if c == ls[i]:\n for l in range(1, 5+1):\n substrs.add(string[s:s+l])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n\nelse:\n substrs = set()\n for leng in range(1, len(string)):\n for s in range(0, len(string) - leng):\n substrs.add(string[s:s+leng])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n', 'string = input()\nk = int(input())\nif len(string) >= k:\n substrs = set()\n ls = sorted(list(string))\n for i in range(k):\n for s, c in enumerate(string):\n if c == ls[i]:\n for l in range(1, k+1):\n substrs.add(string[s:s+l])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n\nelse:\n substrs = set()\n for leng in range(1, len(string)):\n for s in range(0, len(string) - leng):\n substrs.add(string[s:s+leng])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n', 'string = input()\nk = int(input())\nif len(string) > k:\n substrs = set()\n ls = sorted(list(string))\n for i in range(k):\n for s, c in enumerate(string):\n if c == ls[i]:\n for l in range(1, k+1):\n substrs.add(string[s:s+l])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n\nelse:\n substrs = set()\n for leng in range(1, len(string) + 1):\n for s in range(0, len(string) - leng + 1):\n substrs.add(string[s:s+leng])\n substrs = list(substrs)\n substrs.sort()\n print(substrs[k-1])\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s714340202', 's865255115', 's438884404'] | [3188.0, 3188.0, 3188.0] | [69.0, 67.0, 67.0] | [578, 578, 585] |
p03355 | u021548497 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['def change(n, word):\n for i in range(len(ans)-1, n, -1):\n ans[i] = ans[i-1]\n ans[n] = word\n\ns = input()\nk = int(input())\np = min(len(s), k)\nkey = s[:p]\n\nfor i in range(1, len(s)+1-p):\n if key > s[i:i+k]:\n key = s[i:i+k]\n\nans = [0]*k\nfor i in range(k):\n if i < p:\n ans[i] = key[:i+1]\n else:\n ans[i] = "zzzzzz"\nfor i in range(len(s)-p, len(s)):\n for j in range(i+1, len(s)+1):\n print(s[i:j])\n for t in range(k):\n if s[i:j] < ans[t] and s[i:j] not in ans:\n change(t, s[i:j])\nprint(ans[k])', 'def change(n, word):\n for i in range(len(ans)-1, n, -1):\n ans[i] = ans[i-1]\n ans[n] = word\n\ns = input()\nk = int(input())\np = min(len(s), k)\nkey = s[:p]\n\nfor i in range(1, len(s)+1-p):\n if key > s[i:i+k]:\n key = s[i:i+k]\n\nans = [0]*k\nfor i in range(k):\n if i < p:\n ans[i] = key[:i+1]\n else:\n ans[i] = "zzzzzz"\nfor i in range(len(s)-p, len(s)):\n for j in range(i+1, len(s)+1):\n print(s[i:j])\n for t in range(k):\n if s[i:j] < ans[t] and s[i:j] not in ans:\n change(t, s[i:j])\nprint(*ans)', 's = input()\nk = int(input())\nn = len(s)\nrank = ["zzzzzz"]*k\nfor i in range(n):\n for j in range(i+1, min([i+k+1, n+1])):\n key = s[i:j]\n for r in range(k):\n if key == rank[r]:\n break\n if key < rank[r]:\n for r2 in range(r, k):\n key2 = rank[r2]\n rank[r2] = key\n key = key2\n break\nprint(rank[k-1])'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s053246373', 's441881130', 's689511611'] | [3064.0, 3064.0, 3064.0] | [18.0, 18.0, 59.0] | [553, 551, 357] |
p03355 | u021916304 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = list(input())\nse = (s)\nk = int(input())\nn = len(s)\n\nse = set()\nfor i in range(n):\n for j in range(i+1,i+1+k):\n# print(i,j,s[i:j])\n se.add(s[i:j])\n#print(se)\nl = sorted(list(se))\nprint(l[k-1])\n \n\n\n\n\n\n\n\n\n\n\n#TLE \n', 's = input()\nse = (s)\nk = int(input())\nn = len(s)\n\nse = set()\nfor i in range(n):\n for j in range(i+1,i+1+k):\n# print(i,j,s[i:j])\n se.add(s[i:j])\n#print(se)\nl = sorted(list(se))\nprint(l[k-1])\n \n\n\n\n\n\n\n\n\n\n\n#TLE \n'] | ['Runtime Error', 'Accepted'] | ['s199975521', 's791721338'] | [3064.0, 4592.0] | [18.0, 35.0] | [400, 394] |
p03355 | u039623862 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["ALPHABETS = 26\n\nORD_A = ord('a')\n\n# fast io\nimport sys\nS,K = sys.stdin.readlines()[:2]\n\nS = [ord(c)-ORD_A for c in S]\nwhile S[-1] < 0:\n S.pop()\n\n\nN = len(S)\nK = int(K)\n\ndp = [None]*(N+1)\ndp[N] = 0\nindices = [N]*ALPHABETS\ns = 1\n\nimport sys\n\nold = 1\n\nfor i,c in enumerate(reversed(S)):\n dp[i] = s\n if s > K:\n break\n s = 2*s\n s -= dp[indices[c]]\n indices[c] = i\n\n\ndp.pop()\ndp.reverse()\ndp.append(0)\n\nindices = [[] for _ in range(ALPHABETS)]\nfor i,c in enumerate(S):\n indices[c].append(i)\nfor l in indices:\n l.append(N)\n\ndel S\n\nfrom bisect import bisect_left\ndef find(k):\n\n s = []\n i = 0\n while k > 0:\n f = False\n for c,L in enumerate(indices):\n j = L[bisect_left(L, i)]\n t = dp[j]\n if t is None or t >= k:\n s.append(c)\n k -= 1\n i = j+1\n f = True\n break\n else:\n k -= t\n if not f:\n break\n if not s:\n return 'Eel'\n return ''.join(chr(c+ORD_A) for c in s)\n\nprint(find(K))\n", "import collections\nimport string\nimport heapq\ns=input()\nn = len(s)\nk = int(input())\n\nm = ['zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz']\nsubs = []\nfor i in range(n):\n for j in range(i+1, min(i+6, n+1)):\n sub = s[i:j]\n if sub not in subs:\n subs.append(sub)\n subs.sort()\n subs = subs[:5]\nprint(subs[k-1])\n"] | ['Wrong Answer', 'Accepted'] | ['s212687066', 's746783701'] | [3316.0, 3960.0] | [20.0, 66.0] | [960, 357] |
p03355 | u054514819 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = str(input())\nK = int(input())\n\nlis = list(set(list(s)))\nlis.sort()\n\nans_lis = []\nfor i in range(min(5, len(lis))):\n i = lis[i]\n s2 = s\n while 1:\n idx = s2.find(i)\n if idx==-1:\n break\n ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx-1))]\n s2 = s2[idx+1:]\nans_lis = list(set(ans_lis))\nans_lis.sort()\nprint(ans_lis[4])', 's = str(input())\nK = int(input())\n\nlis = list(set(list(s)))\nlis.sort()\n\nans_lis = []\nfor i in range(min(5, len(lis))):\n i = lis[i]\n s2 = s\n while 1:\n idx = s2.find(i)\n if idx==-1:\n break\n ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx))]\n s2 = s2[idx+1:]\nans_lis = list(set(ans_lis))\nans_lis.sort()\nprint(ans_lis[K-1])'] | ['Runtime Error', 'Accepted'] | ['s823025276', 's147805986'] | [4468.0, 4468.0] | [34.0, 34.0] | [381, 381] |
p03355 | u064408584 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['import copy\n\nn,m=map(int, input().split())\np=list(map(int, input().split()))\nq=list()\nfor i in range(m):\n q.append(set(map(int, input().split())))\ncount=0\nwhile count!=5000:\n a=q.pop()\n for j in q:\n if len(j&a) != 0:\n j |=a\n count=0\n break\n else:q=[a]+q\n if count>len(q): break\n count+=1\n\nq2=copy.copy(set(p))\nfor i in q:\n q2 -= i\n \ncount2=len([i for i in q2 if i==p[i-1]])\n\nfor i in q:\n r=list()\n for j in list(i):\n r.append(p[j-1])\n #print(i,r)\n count2 += len(i&set(r))\nprint(count2)', 's=input()\nk=int(input())\ns1=list(s)\ns2=[s[i:i+2] for i in range(len(s)-1)]\ns3=[s[i:i+3] for i in range(len(s)-2)]\ns4=[s[i:i+4] for i in range(len(s)-3)]\ns5=[s[i:i+5] for i in range(len(s)-4)]\nsall=sorted(list(set(s1+s2+s3+s4+s5)))\nprint(sall[k-1])'] | ['Runtime Error', 'Accepted'] | ['s688945571', 's554733978'] | [3572.0, 5140.0] | [24.0, 30.0] | [568, 247] |
p03355 | u069838609 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['def brute_force(s, K):\n substring_set = set()\n\n \n for start in range(len(s)):\n \n for length in range(1, 6):\n substring = s[start:start+length]\n substring_set.add(substring)\n\n substring_list = sorted(list(substring_set))\n print(substring_list)\n print(substring_list[K - 1])\n\nbrute_force(s, K)', 's = input()\nK = int(input())\n\n\ndef brute_force(s, K):\n substring_set = set()\n\n \n for start in range(len(s)):\n \n for length in range(1, 6):\n substring = s[start:start+length]\n substring_set.add(substring)\n\n substring_list = sorted(list(substring_set))\n print(substring_list[K - 1])\n\nbrute_force(s, K)'] | ['Runtime Error', 'Accepted'] | ['s872254152', 's367967374'] | [2940.0, 4592.0] | [17.0, 32.0] | [385, 390] |
p03355 | u089142196 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s=input()\nK=int(input())\nN=len(s)\ntmp=set()\n\nfor i in range(N):\n p=min(i+K,N)\n for j in range(i+1,p+1):\n t= s[i:j]\n print(i,j,t)\n tmp.add(t)\n \nlis=sorted(tmp)\n#print(lis)\nprint(lis[K-1])\n', 's=input()\nK=int(input())\nN=len(s)\ntmp=set()\n\nfor i in range(N):\n for j in range(K):\n t= s[i:i+j+1]\n #print(i,j,t)\n tmp.add(t)\n \nlis=sorted(tmp)\n#print(lis)\nprint(lis[K-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s795666073', 's864497843'] | [5244.0, 4464.0] | [80.0, 36.0] | [201, 185] |
p03355 | u106778233 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ["from collections import deque \ndef k_sub():\n s=input()\n k=int(input())\n dq=deque()\n for i in range(1,len(s)+1):\n for j in range(k):\n a.append(s[j:j+i])\n a.sort()\n print(a[k-1])\nif __name__=='__main__':\n k_sub()", 's=input();k=int(input()) \n\na=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1])\nprint(a)', 's=input();k=int(input()) \na=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)}[k-1])\nprint(a)', 's=input()\nk=int(input())\n\na=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1]\nprint(a)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s146528196', 's304924100', 's871879203', 's919299037'] | [3316.0, 2940.0, 4464.0, 4464.0] | [21.0, 17.0, 25.0, 32.0] | [249, 108, 106, 103] |
p03355 | u123824541 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['S = list(input())\nK = int(input())\nx = set()\n\nfor i in range(len(S)):\n for j in range(1,min(len(S) - i + 1, K + 1)):\n x.add(S[i:i + j])\n\nx = list(x)\nx.sort()\nprint(x[K - 1])', 'S = input()\nK = int(input())\nx = set()\n\nfor i in range(len(S)):\n for j in range(1,min(len(S) - i + 1, K + 1)):\n x.add(S[i:i + j])\n\nx = list(x)\nx.sort()\nprint(x[K - 1])'] | ['Runtime Error', 'Accepted'] | ['s962264719', 's534164058'] | [3060.0, 4464.0] | [18.0, 36.0] | [183, 177] |
p03355 | u129836004 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['s = input()\nK = int(input())\nans = []\nfor i in range(len(s)):\n for k in range(i+1, len(s)):\n ans.append(s[i:k])\nans = set(ans)\nans = list(ans)\nans.sort()\nprint(ans[K-1])\n ', 's = input()\nans = set()\nk = int(input())\nfor i in range(len(s)):\n for j in range(1, k+1):\n ans.add(s[i:i+j])\nprint(sorted(list(ans))[k-1])'] | ['Runtime Error', 'Accepted'] | ['s042423052', 's796493608'] | [3060.0, 4592.0] | [2826.0, 35.0] | [188, 148] |
p03355 | u139501158 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['import numpy as np\n\ns = input()\nK = int(input())\nL = len(s)\n\ncandidate = []\n\nfor l in range(1, K + 1):\n for j in range(0, L - l):\n candidate.append(s[j:j+l])\n\nprint(np.sort(candidate)[K-1])', 'import numpy as np\n\ns = input()\nK = int(input())\nL = len(s)\n\ncandidate = []\n\nfor l in range(1, K + 1):\n for j in range(0, L - l + 1):\n candidate.append(s[j:j+l])\n\ncandidate = list(set(candidate))\nprint(np.sort(candidate)[K-1])'] | ['Runtime Error', 'Accepted'] | ['s289836647', 's413935054'] | [22272.0, 14296.0] | [315.0, 160.0] | [199, 236] |
p03355 | u189023301 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['from itertools import combinations\nfrom collections import deque\ns = input()\nn = int(input())\n\nle = len(s)\nseed = tuple(combinations(range(le + 1), 2))\n\nres = deque()\nres.append("zzzzzzzzzzzzzzzzzzzzzzz")\nres.append("zzzzzzzzzzzzzzzzzzzzzzz")\nres.append("zzzzzzzzzzzzzzzzzzzzzzz")\nres.append("zzzzzzzzzzzzzzzzzzzzzzz")\nres.append("zzzzzzzzzzzzzzzzzzzzzzz")\n\nfor i, j in seed:\n ch = s[i:j]\n if ch in res:\n continue\n elif ch < max(res):\n res.remove(max(res))\n res.append(ch)\n print(res)\n\nans = sorted(res)\nprint(ans[n - 1])\n', 'from itertools import combinations\ns = input()\nn = int(input())\n\nle = len(s)\ntmp = s[:5]\n\nfor i in range(le - 4):\n tmp = min(tmp, s[i:i+5])\n\nseed = tuple(combinations(range(min(6, le+1)), 2))\nres = set()\nfor i, j in seed:\n res.add(tmp[i:j])\nans = sorted(res)\nprint(ans[n - 1])\n'] | ['Wrong Answer', 'Accepted'] | ['s090428194', 's985489755'] | [741688.0, 3064.0] | [2152.0, 19.0] | [559, 283] |
p03355 | u248856154 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['import numpy as np\nN, M = list(map(int, input().split()))\np = list(map(int, input().split()))\nx = []\ny = []\nfor _ in range(M):\n xi, yi = list(map(int, input().split()))\n x.append(xi - 1)\n y.append(yi - 1)\n\ndef count(l):\n out = 0\n for i, v in enumerate(l):\n if i + 1 == v:\n out += 1\n return out\n\ndef swap(l, a, b):\n va = l[a]\n vb = l[b]\n l1 = l.copy()\n l1[a] = vb\n l1[b] = va\n return l1\n\ndepth = 0\nmax_count = count(p)\nmax_d = M**5\nchildren = [p]\nnext_children = []\nwhile depth <= max_d:\n for child in children:\n for i in range(M):\n pi = swap(child, x[i], y[i])\n ci = count(pi)\n if ci > max_count:\n max_count = ci\n\t if not pi in next_children:\n next_children.append(pi)\n depth += 1\n children = next_children\n next_chldren = []\n if max_count == len(p):\n break\n\nprint(max_count)', 'import numpy as np\n\ns = input()\nK = int(input())\nL = len(s)\n\ncandidate = []\n\nfor l in range(1, K + 1):\n for j in range(0, L - l + 1):\n candidate.append(s[j:j+l])\n\ncandidate = list(set(candidate))\nprint(np.sort(candidate)[K-1])'] | ['Runtime Error', 'Accepted'] | ['s509064309', 's858059568'] | [3064.0, 14296.0] | [17.0, 161.0] | [924, 236] |
p03355 | u311636831 | 2,000 | 1,048,576 | You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}. | ['#s=input()\n#N=int(input())\ns="atcoderandatcodeer"\nN=5\nD={}\n\nif(len(s)<=10):\n for i in range(1,len(s)+1):\n for j in range(len(s)):\n if D.get(s[j:j+i],None) == None:\n D[s[j:j+i]]=1\n D=sorted(D)\n print(D[N-1])\n exit()\nelse:\n t=sorted(s)\n i=0\n k=0\n for c in t:\n if(c!=k):\n i=0\n if(len(D)>=5):\n break\n k=c\n while(i<len(s)):\n if(s[i]==c):\n break\n i+=1\n j=i+1\n while(j<=len(s)):\n D[s[i:j]]=1\n j+=1\n i+=1\n \n D=sorted(D)\n print(D[N-1])\n exit()\n\n\n\n', 's=input()\nN=int(input())\n\n#N=5\nD={}\n\nif(len(s)<=1):\n for i in range(1,len(s)+1):\n for j in range(len(s)):\n if D.get(s[j:j+i],None) == None:\n D[s[j:j+i]]=1\n D=sorted(D)\n print(D[N-1])\n exit()\nelse:\n t=sorted(s)\n i=0\n k=0\n for c in t:\n if(c!=k):\n i=0\n if(len(D)>=5):\n break\n k=c\n while(i<len(s)):\n if(s[i]==c):\n break\n i+=1\n j=i+1\n while(j<=min(len(s),i+5)):\n D[s[i:j]]=1\n j+=1\n i+=1\n \n D=sorted(D)\n print(D[N-1])\n exit()'] | ['Wrong Answer', 'Accepted'] | ['s997627416', 's419802099'] | [3064.0, 3188.0] | [17.0, 40.0] | [645, 650] |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.