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
|
---|---|---|---|---|---|---|---|---|---|---|
p03389 | u909643606 | 2,000 | 262,144 | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | ['n=int(input())\na=[0 for i in range(n)]\nb=[0 for i in range(n)]\nc=[0 for i in range(n)]\nfor i in range(n):\n a[i],b[i]=[int(i) for i in input().split()]\n c[i]=a[i]*b[i]\n#print(a,b)\n\ndef keisan(d,e,f):\n count=0\n old_value=10**20\n for j in range(int(d)):\n value=min(old_value,int((d-1)/(j+1)))\n\n# print(value)\n\n if old_value==value:\n value-=1\n\n if value>0:\n if e!=j+1 and f!=value:\n count+=1\n old_value=value\n elif e==j+1:\n pass\n elif f==value:\n pass\n else:\n break\n print(count)\n\nfor i in range(n): \n keisan(c[i],a[i],b[i])\n', 'a=[int(i) for i in input().split()]\n\na.sort()\n\nif a[0]%2==0 and a[1]%2==0 and a[2]%2==0:\n print(int((3*max(a)-sum(a))/2)) \nelif a[0]%2==1 and a[1]%2==1 and a[2]%2==1:\n print(int((3*max(a)-sum(a))/2)) \n\nelse:\n count=0\n for i in range(3):\n if a[i]%2==0:\n count+=1\n\n if count==2:\n for i in range(3):\n if a[i]%2==0:\n a[i]=a[i]+1\n print(int((3*max(a)-sum(a))/2)+1) \n \n if count==1:\n for i in range(3):\n if a[i]%2==1:\n a[i]=a[i]+1\n print(int((3*max(a)-sum(a))/2)+1) \n\n\n'] | ['Runtime Error', 'Accepted'] | ['s148968562', 's721060860'] | [3064.0, 3064.0] | [18.0, 17.0] | [696, 594] |
p03389 | u938024002 | 2,000 | 262,144 | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | ["in = [int(i) for i in input().split(' ')]\nA,B,C = in[0],in[1],in[2]\nif (A+B+C - max(A,B,C)) % 2 == 0:\n print((3*max(A,B,C) - A - B - C)/2)\nelse:\n print((3*max(A,B,C) - A - B - C - 1)/2) + 2", "tin = [int(i) for i in input().split(' ') ]\nA,B,C = tin[0],tin[1],tin[2]\nif (A+B+C - max(A,B,C)) % 2 == 0:\n print(int((3*max(A,B,C) - A - B - C)/2))\nelse:\n print( int( (3*max(A,B,C) - A - B - C - 1)/2 + 2 ) )"] | ['Runtime Error', 'Accepted'] | ['s267021244', 's626141672'] | [2940.0, 3064.0] | [17.0, 18.0] | [191, 210] |
p03389 | u942033906 | 2,000 | 262,144 | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | ['Q = int(input())\nfor i in range(Q):\n\tA,B = map(int,input().split())\n\tif A == 1 and B == 1:\n\t\tprint(0)\n\t\tcontinue\n\tscore = A * B\n\troot = int((score-1) ** 0.5)\n\tans = 2 * root\n\tif root >= A:\n\t\tans -= 1\n\tif root >= B:\n\t\tans -= 1\n\tif (score - 1) // root == root:\n\t\tans -= 1\n\tprint(ans)', 'l = sorted(list(map(int,input().split())))\nC,B,A = l[0],l[1],l[2]\ncnt = 0\nwhile A != B or B != C or C != A:\n\tif A == B:\n\t\tif C < A:\n\t\t\tC += 2\n\t\t\tcnt += 1\n\t\telif C > A:\n\t\t\tA += 1\n\t\t\tB += 1\n\t\t\tcnt += 1\n\telse:\n\t\tB += 1\n\t\tC += 1\n\t\tcnt += 1\nprint(cnt)'] | ['Runtime Error', 'Accepted'] | ['s767970143', 's941004623'] | [3064.0, 3064.0] | [17.0, 17.0] | [281, 246] |
p03389 | u964904181 | 2,000 | 262,144 | You are given three integers A, B and C. Find the minimum number of operations required to make A, B and C all equal by repeatedly performing the following two kinds of operations in any order: * Choose two among A, B and C, then increase both by 1. * Choose one among A, B and C, then increase it by 2. It can be proved that we can always make A, B and C all equal by repeatedly performing these operations. | ['lst = list(map(int, input().split()))\n\nmval = max(lst)\nsval = sum(lst)\ncn = mval + sval % 2\nn = (cn * 3 - sval-mval) // 2\nprint(n)\n\n', 'lst = list(map(int, input().split())).sort()\n\nmval = lst[-1]\nsval = sum(lst)\ncn = mval + (sval-mval) % 2\nn = (cn * 3 - sval) // 2\nprint(n)\n\n', '# A, B, C = [11, 12, 15]\nlst = list(map(int, input().split()))\n\nmval = max(lst)\nsval = sum(lst)\ncn = mval + sval % 2\nn = (cn * 3 - sval) // 2\nprint(n)\n\n\n', 'lst = sorted(list(map(int, input().split())))\n\nmval = lst[-1]\nsval = sum(lst)\ncn = mval + (sval-mval) % 2\nn = (cn * 3 - sval) // 2\nprint(n)\n\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s124429230', 's305783004', 's401630946', 's907994118'] | [9052.0, 9064.0, 9088.0, 9048.0] | [27.0, 26.0, 28.0, 30.0] | [132, 140, 153, 141] |
p03390 | u062147869 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ["import math \nQ=int(input())\ntable=[]\nfor i in range(Q):\n a,b=map(int,input().split())\n if a>b:\n table.append([b,a])\n else:\n table.append([a,b])\nans=[]\nfor a,b in table:\n s = int(math.sqrt(a*b))\n num=2*s-2\n if s-1>=a:\n num-=1\n if s*(s+1)<a*b:\n num+=2\n elif s*s<a*b:\n num+=1\n ans.append(num)\nprint('\\n'.join(map(str,ans)))", "from math import sqrt \nQ = int(input())\ntable=[]\nfor i in range(Q):\n A,B=map(int,input().split())\n if A>B:\n table.append([B,A])\n else:\n table.append([A,B])\ndef f(a,b):\n if a==b:\n return 2*a-2\n if a+1==b:\n return 2*a-2\n m = int(sqrt(a*b))\n if m**2 ==a*b:\n return 2*m-3\n if m*(m+1) >= a*b:\n return 2*m -2\n return 2*m-1\n\nans = []\nfor a,b in table:\n ans.append(f(a,b))\nprint('\\n'.join(map(str,ans)))"] | ['Wrong Answer', 'Accepted'] | ['s903864416', 's139191849'] | [3064.0, 3064.0] | [18.0, 18.0] | [382, 467] |
p03390 | u104282757 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['# D\nimport math\nQ = int(input())\nA_list = []\nB_list = []\nfor _ in range(Q):\n A, B = map(int, input().split())\n A_list.append(min(A, B))\n B_list.append(max(A, B))\n \nfor i in range(Q):\n A = A_list[i]\n B = B_list[i]\n \n if A == B:\n print(A+B-2)\n continue\n \n R = int(math.sqrt(A*B-1))\n Q = (A*B-1) // R\n \n if Q <= R+1:\n add = min(Q - A - 1, B - R - 1) \n elif Q == R+2 and (R+1)**2 == A*B:\n add = 1\n elif (Q - R)**2 - 4*(A*B-Q*R) >= 0:\n add = int(((Q - R) - math.sqrt((Q - R)**2 - 4*(A*B-Q*R))) / 2)\n if (R + add)*(Q-add) == A*B:\n add -= 1\n else:\n print(xxxx)\n print((A-1) + R + add)\n ', '# D\nimport math\nQ = int(input())\nA_list = []\nB_list = []\nfor _ in range(Q):\n A, B = map(int, input().split())\n A_list.append(min(A, B))\n B_list.append(max(A, B))\n \nfor i in range(Q):\n A = A_list[i]\n B = B_list[i]\n R = int(math.sqrt(A*B))\n \n \n if A >= B - 1:\n print(2*A-2)\n elif R*R == A*B:\n print(2*R-3)\n elif R*(R+1) >= A*B:\n print(2*R-2)\n else:\n print(2*R-1)\n '] | ['Wrong Answer', 'Accepted'] | ['s106013607', 's057464212'] | [3192.0, 3064.0] | [18.0, 18.0] | [702, 432] |
p03390 | u218843509 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['from math import sqrt\n\ndef func(a, b):\n\tif a == b:\n\t\treturn (a - 1) * 2\n\telse:\n\t\tsq = int(sqrt(a * b))\n\t\tif a * b == sq ** 2:\n\t\t\treturn (sq - 1) * 2 - 1\n\t\telif sq * (sq + 1) >= a * b:\n return (sq - 1) * 2\n\t\telse:\n\t\t\treturn sq * 2 - 1\n\nq = int(input())\nfor _ in range(q):\n\ta, b = map(int, input().split())\n\tprint(func(a, b))', 'from math import sqrt\n\ndef func(a, b):\n\tif a == b:\n\t\treturn (a - 1) * 2\n\telse:\n\t\tsq = int(sqrt(a * b))\n\t\tif a * b == sq ** 2:\n\t\t\treturn (sq - 1) * 2 - 1\n\t\telif sq * (sq + 1) >= a * b:\n\t\t\treturn (sq - 1) * 2\n\t\telse:\n\t\t\treturn sq * 2 - 1\n\nq = int(input())\nfor _ in range(q):\n\ta, b = map(int, input().split())\n\tprint(func(a, b))'] | ['Runtime Error', 'Accepted'] | ['s014163895', 's162599870'] | [2940.0, 3064.0] | [17.0, 18.0] | [334, 325] |
p03390 | u340781749 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['from math import sqrt\n\nq = int(input())\nfor _ in range(q):\n a, b = map(int, input().split())\n m = a * b\n s = int(sqrt(m - 1))\n ans = 2 * s\n if s * (s + 1) > m:\n ans -= 1\n if a != b:\n ans -= 1\n print(ans)\n', 'from math import sqrt\n\nq = int(input())\nfor _ in range(q):\n a, b = map(int, input().split())\n m = a * b\n s = int(sqrt(m))\n ans = 2 * s - 1\n if s * (s + 1) >= m:\n ans -= 1\n if s * s == m and a != b:\n ans -= 1\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s753344936', 's579818064'] | [3060.0, 3060.0] | [18.0, 18.0] | [239, 255] |
p03390 | u364439209 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ["# import sys\n# argv = sys.argv\n# with open(argv[1], 'r') as f:\n\n\nQ = int(input().strip('\\n'))\nA = list()\nB = list()\nfor i in range(Q):\n inDatas = input().strip('\\n').split(' ')\n a, b = list(map(int, inDatas))\n score = a*b\n pa = 1\n pb = score\n count = 0\n while pb >= 1:\n if pa == a: pa += 1\n else:\n while pa*pb >= score or pb == b:\n pb -= 1\n count += 1\n pa += 1\n pb -= 1\n print(count)\n", "\nQ = int(input().strip('\\n'))\nfor i in range(Q):\n inDatas = input().strip('\\n').split(' ')\n a, b = list(map(int, inDatas))\n score = a*b\n if a < b:\n tmp = a\n a = b\n b = tmp\n pa = b\n pb = a - 1\n count = b - 1 + b - 1\n while pb >= b+1:\n if pa == a: pa += 1\n elif pb == b: pb -= 1\n else:\n while pa*pb >= score or pb == b:\n pb -= 1\n if pb >= 1:\n count += 1\n pa += 1\n pb -= 1\n print(count)", "import math\n\nif __name__ == '__main__':\n q = int(input())\n for i in range(q):\n a, b = list(map(int, input().split()))\n prod = a*b\n rootInt = int(math.sqrt(prod))\n if a == b: print((a-1)*2)\n elif math.sqrt(prod) == rootInt:\n print((rootInt-2)*2+1)\n else:\n if rootInt*(rootInt+1) < prod:\n print((rootInt-1)*2+1)\n else:\n print((rootInt-1)*2)"] | ['Wrong Answer', 'Time Limit Exceeded', 'Accepted'] | ['s879223471', 's971074578', 's832041500'] | [3064.0, 3064.0, 3064.0] | [2104.0, 2103.0, 19.0] | [503, 534, 449] |
p03390 | u368780724 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['def inpl(): return [int(i) for i in input().split()]\nQ = int(input())\nfor _ in range(Q):\n A, B = sorted(inpl())\n c = int((A*B-1)**0.5//1)\n ans = c-1+(A*B-1)//(c+1)\n print(ans + ((A*B)//1 == -((-A*B)//1)))', 'def inpl(): return [int(i) for i in input().split()]\nQ = int(input())\nfor _ in range(Q):\n A, B = sorted(inpl())\n c = int(-(-(A*B)**0.5//1)-1)\n ans = A-1 + max(0, c-A) + (-(-A*B)//(c+1)-1)\n print(ans)', 'def inpl(): return [int(i) for i in input().split()]\nQ = int(input())\nfor _ in range(Q):\n A, B = sorted(inpl())\n c = int(-(-(A*B)**0.5//1)-1)\n ans = A-1 + max(0, c-A) + (-((-A*B)//(c+1))-1)\n print(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s656771692', 's958000679', 's605965483'] | [3060.0, 3060.0, 3060.0] | [18.0, 20.0, 19.0] | [216, 211, 213] |
p03390 | u394794741 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['from math import sqrt\n\nQ = int(input())\n\nfor i in range(Q):\n A,B = map(int, input().split())\n m=A*B\n C = int(sqrt(m))\n if C*C==m:\n C=C-1\n\n if C*(C+1)<m:\n ans = 2*C-1\n else:\n ans = 2*C-2\n print(ans)', 'from math import sqrt\n\nQ = int(input())\n\nfor i in range(Q):\n A,B = map(int, input().split())\n m=A*B\n if A==B or B==A+1:\n ans = 2*A-2\n elif A==B+1\n ans = 2*B-2\n\n C = int(sqrt(m))\n if C*C==m:\n C=C-1\n\n if C*(C+1)<m:\n ans = 2*C-1\n else:\n ans = 2*C-2\n print(ans)', 'from math import sqrt\n\nQ = int(input())\n\nfor i in range(Q):\n A,B = map(int, input().split())\n m=A*B\n if A==B or B=A+1:\n ans = 2*A-2\n elif A=B+1\n ans = 2*B-2\n\n C = int(sqrt(m))\n if C*C==m:\n C=C-1\n\n if C*(C+1)<m:\n ans = 2*C-1\n else:\n ans = 2*C-2\n print(ans)', 'from math import sqrt\n\nQ = int(input())\n\nfor i in range(Q):\n A,B = map(int, input().split())\n m=A*B\n\n C = int(sqrt(m))\n if C*C==m:\n C=C-1\n\n if A==B or B==A+1:\n ans = 2*A-2\n elif A==B+1:\n ans = 2*B-2\n elif C*(C+1)<m:\n ans = 2*C-1\n else:\n ans = 2*C-2\n print(ans)'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s012816737', 's346985450', 's487529182', 's754267915'] | [3060.0, 2940.0, 2940.0, 3064.0] | [18.0, 17.0, 17.0, 18.0] | [243, 323, 321, 322] |
p03390 | u403301154 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['q = int(input())\nfor i in range(q):\n a, b = list(map(int, input().split()))\n if a==b:\n ans = 2*a-2\n elif abs(a-b)==1:\n ans = 2*min(a, b)-2\n else:\n c = int((a*b)**0.5)\n if c*(c+1)>=a*b:\n ans = 2*c-2\n else:\n ans = 2*c-1\n print(ans)', 'q = int(input())\nfor i in range(q):\n a, b = list(map(int, input().split()))\n if a==b:\n ans = 2*a-2\n elif abs(a-b)==1:\n ans = 2*min(a, b)-2\n else:\n c = (a*b)**0.5\n if c%1==0:\n c = int(c)-1\n else:\n c = int(c)\n if c*(c+1)>=a*b:\n ans = 2*c-2\n else:\n ans = 2*c-1\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s898471333', 's315223658'] | [3188.0, 3188.0] | [18.0, 18.0] | [259, 315] |
p03390 | u517388115 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['n=int(input())\n\nfor i in range(n):\n a, b = map(int, input().split())\n\n p=int((a*b)**(1/2))\n print(p)\n if p*(p+1) < a*b:\n ans=int(2*p-1)\n elif p**2==a*b and not a==b:\n ans=int(2*p-3)\n else:\n ans=int(2*p-2)\n print(ans)\n', 'n=int(input())\nl=[]\nfor i in range(n):\n a, b = map(int, input().split())\n\n p=int((a*b)**(1/2))\n\n if p*(p+1) < a*b:\n ans=int(2*p-1)\n elif p**2==a*b and not a==b:\n ans=int(2*p-3)\n else:\n ans=int(2*p-2)\n l.append(ans)\n\nfor i in range(n):\n print(l[i])\n'] | ['Wrong Answer', 'Accepted'] | ['s213023460', 's934385732'] | [3188.0, 3064.0] | [19.0, 18.0] | [259, 290] |
p03390 | u532502139 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['n = int(input())\narr = []\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\nfor pair in arr:\n first = {}\n first[pair[0]] = pair[0]\n second = {}\n second[pair[1]] = pair[1]\n pairs = []\n _max = max(pair)\n _min = min(pair)\n total = _max * _min - 1\n for i in range(1, total):\n j = int(total / i)\n if i not in first and j not in second:\n first[i] = i\n second[j] = j\n pairs.append([i, j])\n print(len(pairs))', 'n = int(input())\narr = []\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\nfor pair in arr:\n first = {}\n first[pair[0]] = pair[0]\n second = {}\n second[pair[1]] = pair[1]\n pairs = []\n _max = max(pair)\n _min = min(pair)\n total = _max * _min\n for i in reversed(range(1, total - 1)):\n for j in range(1, total - 1):\n if i not in first and j not in second and i * j < total:\n first[i] = i\n second[j] = j\n pairs.append([i, j])\n print(len(pairs))\n \n \n ', 'n = int(input())\narr = []\nfor i in range(n):\n arr.append([int(x) for x in input().split()])\nfor pair in arr:\n a = pair[0]\n b = pair[1]\n t = a*b\n s = int(t ** 0.5)\n if t < 3:\n print(0)\n elif a == b:\n if (a-1) * (b+1) < t:\n print((a-1)*2)\n else:\n print((a-1)*2-1)\n elif s*s == t:\n print((s-1)*2-1)\n elif s*(s+1) < t:\n print(s*2-1)\n else:\n print((s-1)*2)\n '] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s913207956', 's968733610', 's905057419'] | [492064.0, 3064.0, 3188.0] | [2124.0, 2104.0, 18.0] | [496, 590, 454] |
p03390 | u562016607 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['import math \nQ=int(input())\nA=[0 for i in range(Q)]\nB=[0 for i in range(Q)]\nfor i in range(Q):\n A[i],B[i]=map(int,input().split())\nfor i in range(Q):\n C=A[i]*B[i]\n N=int(math.sqrt(C))\n D=0\n if N**2==C:\n N-=1\n else:\n while(True):\n if A[i]*B[i]<N**2:\n N-=1\n elif A[i]*B[i]>(N+1)**2:\n N+=1\n else:\n break\n print(N)\n M=2*N-1\n print(M)\n', 'import math \nQ=int(input())\nA=[0 for i in range(Q)]\nB=[0 for i in range(Q)]\nfor i in range(Q):\n A[i],B[i]=map(int,input().split())\nfor i in range(Q):\n C=A[i]*B[i]\n N=int(math.sqrt(C))\n D=0\n if N**2==C:\n N-=1\n else:\n while(True):\n if A[i]*B[i]<N**2:\n N-=1\n elif A[i]*B[i]>(N+1)**2:\n N+=1\n else:\n break\n print(N)\n M=2*N\n S=M-1\n if M*(M-A[i])>=C and M*(M-B[i])>=C and (M-A[i])*(M-B[i])<C:\n S-=1\n elif A[i]>=M and B[i]<M and M*(M-B[i])>=C:\n S-=1\n elif B[i]>=M and A[i]<M and M*(M-A[i])>=C:\n S-=1\n elif (M-A[i])*(M-B[i])>=C:\n S-=2\n print(S)\n', 'import math\nQ=int(input())\nfor roop in range(Q):\n X,Y=map(int,input().split())\n A=min([X,Y])\n B=max([X,Y])\n if A==B:\n print(2*A-2)\n elif A+1==B:\n print(2*A-2)\n else:\n C=int(math.sqrt(A*B))\n while(True):\n if C**2>=A*B:\n C-=1\n elif (C+1)**2<A*B:\n C+=1\n else:\n break\n if C*(C+1)>=A*B:\n print(2*C-2)\n else:\n print(2*C-1)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s592041858', 's600705126', 's879975121'] | [3316.0, 3064.0, 3064.0] | [22.0, 18.0, 18.0] | [457, 706, 477] |
p03390 | u584749014 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['import math\n\nq = int(input())\n\nfor i in range(q):\n a, b = map(int, input().split())\n sq = (a*b)**0.5\n ans = int(math.modf(sq*2 - 2)[1])\n if a < 5 and b < 5:\n ans1 = 0\n ax = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n ax.pop(ax.index(a))\n bx = [9, 8, 7, 6, 5, 4, 3, 2, 1]\n bx.pop(bx.index(b))\n ax1 = []\n bx1 = []\n for ai in ax:\n if ai in ax1:\n continue\n for bi in bx:\n if bi in bx1:\n continue\n if ai*bi < a*b:\n ax1.append(ai)\n bx1.append(bi)\n ans1 += 1\n print(ans1)\n else:\n print(ans)\n', 'import math\n\ndef slv(A, B):\n A, B = (A, B) if A > B else (B, A)\n \n s = A * B\n c = math.floor(math.sqrt(A * B))\n \n if c * (c + 1) < s:\n return 2 * c - 1\n elif A == B:\n return 2 * c - 2\n elif c * c < s:\n return 2 * c - 2\n elif c * (c - 1) < s:\n return 2 * c - 3\n\nQ = int(input())\nfor q in range(Q):\n A, B = map(int, input().split())\n print(slv(A, B))'] | ['Wrong Answer', 'Accepted'] | ['s795953094', 's442928817'] | [3188.0, 3316.0] | [18.0, 22.0] | [697, 409] |
p03390 | u637175065 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ["import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**15\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\n\n\ndef main():\n n = I()\n rr = []\n for _ in range(n):\n a,b = LI()\n t = a*b\n s = int(t ** 0.5)\n if s*s == t:\n rr.append((s-1)*2-1)\n elif s*(s+1) < t:\n rr.append(s*2-1)\n else:\n rr.append((s-1)*2)\n\n\n return '\\n'.join(map(str, rr))\n\n\nprint(main())\n\n\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**15\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\n\n\ndef main():\n n = I()\n rr = []\n for _ in range(n):\n a,b = LI()\n t = a*b\n s = int(t ** 0.5)\n if t < 3:\n rr.append(0)\n elif a == b:\n if (a-1) * (b+1) < t:\n rr.append((a-1)*2)\n else:\n rr.append((a-1)*2-1)\n elif s*s == t:\n rr.append((s-1)*2-1)\n elif s*(s+1) < t:\n rr.append(s*2-1)\n else:\n rr.append((s-1)*2)\n\n\n return '\\n'.join(map(str, rr))\n\n\nprint(main())\n\n\n"] | ['Wrong Answer', 'Accepted'] | ['s467163633', 's518670814'] | [7880.0, 8004.0] | [548.0, 148.0] | [904, 1094] |
p03390 | u638795007 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ["def examC():\n ABC = LI(); ABC.sort()\n judge = ABC[2]*2-ABC[1]-ABC[0]\n ans = judge//2 + (judge%2)*2\n print(ans)\n return\n\ndef examD():\n def judge(A,B):\n cur = int((A*B)**0.5)\n if cur**2==A*B:\n return (cur-1)*2 -1\n if cur*(cur+1)>=A*B:\n return cur*2 -2\n else:\n return cur*2-1\n Q = I()\n ans = []\n for _ in range(Q):\n a,b = LI()\n ans.append(judge(a,b))\n for v in ans:\n print(v)\n return\n\nimport sys,copy,bisect,itertools,heapq,math\nfrom heapq import heappop,heappush,heapify\nfrom collections import Counter,defaultdict,deque\ndef I(): return int(sys.stdin.readline())\ndef LI(): return list(map(int,sys.stdin.readline().split()))\ndef LSI(): return list(map(str,sys.stdin.readline().split()))\ndef LS(): return sys.stdin.readline().split()\ndef SI(): return sys.stdin.readline().strip()\nglobal mod,inf\nmod = 10**9 + 7\ninf = 10**18\n\nif __name__ == '__main__':\n examD()\n", "def examC():\n ABC = LI(); ABC.sort()\n judge = ABC[2]*2-ABC[1]-ABC[0]\n ans = judge//2 + (judge%2)*2\n print(ans)\n return\n\ndef examD():\n def judge(A,B):\n if A==B:\n return (A-1)*2\n cur = int((A*B)**0.5)\n if cur**2==A*B:\n return (cur-1)*2 -1\n if cur*(cur+1)>=A*B:\n return cur*2 -2\n else:\n return cur*2-1\n Q = I()\n ans = []\n for _ in range(Q):\n a,b = LI()\n ans.append(judge(a,b))\n for v in ans:\n print(v)\n return\n\nimport sys,copy,bisect,itertools,heapq,math\nfrom heapq import heappop,heappush,heapify\nfrom collections import Counter,defaultdict,deque\ndef I(): return int(sys.stdin.readline())\ndef LI(): return list(map(int,sys.stdin.readline().split()))\ndef LSI(): return list(map(str,sys.stdin.readline().split()))\ndef LS(): return sys.stdin.readline().split()\ndef SI(): return sys.stdin.readline().strip()\nglobal mod,inf\nmod = 10**9 + 7\ninf = 10**18\n\nif __name__ == '__main__':\n examD()\n"] | ['Wrong Answer', 'Accepted'] | ['s864109797', 's883342013'] | [3548.0, 3696.0] | [24.0, 25.0] | [975, 1019] |
p03390 | u671861352 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['#!python3\n\n# input\nQ = int(input())\nA, B = [None] * Q, [None] * Q\nfor i in range(Q):\n A[i], B[i] = sorted(map(int, input().split()))\n\n\ndef solve(a, b):\n w = a * b - 1\n left, right = 0, b - a\n while right - left > 1:\n x = (left + right) // 2\n v = w // (a + x)\n if v < a:\n right = x\n else:\n left = x\n\n n = left\n left, right = 0, n + 1\n while right - left > 1:\n x = (left + right) // 2\n d = (w // (a + x)) - (w // (a + x + 1))\n if d > 0:\n left = x\n else:\n right = x\n \n return left - 1 + (w // (a + left)) - (w // (a + n))\n\n\ndef main():\n for a, b in zip(A, B):\n ans = 2 * (a - 1) + solve(a, b)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n', '#!python3\n\n# input\nQ = int(input())\nA, B = [None] * Q, [None] * Q\nfor i in range(Q):\n A[i], B[i] = sorted(map(int, input().split()))\n\n\ndef solve(a, b):\n w = a * b - 1\n left, right = 0, b - a\n while right - left > 1:\n x = (left + right) // 2\n v = w // (a + x)\n if v < a:\n right = x\n else:\n left = x\n\n n = left\n left, right = 0, n\n while right - left > 1:\n x = (left + right) // 2\n v = w // (a + x)\n if v < a + x:\n right = x\n else:\n left = x\n\n return right + (w // (a + right)) - (w // (a + n))\n\n\ndef main():\n for a, b in zip(A, B):\n ans = 2 * (a - 1) + solve(a, b)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s615133685', 's562581297'] | [3064.0, 3064.0] | [20.0, 20.0] | [786, 757] |
p03390 | u672710370 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['import sys\nsys.setrecursionlimit(10**6)\n\ndebug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False\nif debug_mode:\n import os\n infile = open(os.path.basename(__file__).replace(".py", ".in"))\n\n def input():\n return infile.readline()\n\n\n# ==============================================================\n\nfrom math import sqrt\n\n\ndef main():\n Q = int(input().strip())\n AB = [list(map(int, input().strip().split())) for _ in range(Q)]\n for a, b in AB:\n score = a * b\n root = sqrt(score)\n pivot = int(root)\n cnt = 2 * (pivot - 1) if pivot == root else 2 * (pivot - 1) + 1\n print(cnt)\n\n\nmain()\n\n# ==============================================================\n\nif debug_mode:\n infile.close()\n', 'import sys\nsys.setrecursionlimit(10**6)\n\ndebug_mode = True if len(sys.argv) > 1 and sys.argv[1] == "-d" else False\nif debug_mode:\n import os\n infile = open(os.path.basename(__file__).replace(".py", ".in"))\n\n def input():\n return infile.readline()\n\n\n# ==============================================================\n\nfrom math import sqrt\n\n\ndef main():\n Q = int(input().strip())\n AB = [list(map(int, input().strip().split())) for _ in range(Q)]\n for a, b in AB:\n a, b = min((a, b)), max((a, b))\n cnt = 0\n if a == b:\n cnt = 2 * (a - 1)\n elif a + 1 == b:\n cnt = 2 * (a - 1)\n else:\n ab = a * b\n c = int(sqrt(ab)) if sqrt(ab) > int(sqrt(ab)) else int(sqrt(\n ab)) - 1\n if c * (c + 1) >= ab:\n cnt = 2 * (c - 1)\n elif c * (c + 1) < ab:\n cnt = 2 * c - 1\n print(cnt)\n\n\nmain()\n\n# ==============================================================\n\nif debug_mode:\n infile.close()\n'] | ['Wrong Answer', 'Accepted'] | ['s689459349', 's591018616'] | [3064.0, 3064.0] | [18.0, 18.0] | [761, 1044] |
p03390 | u694433776 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['q=int(input())\nwhile q>0:\n q-=1\n a,b=map(int,input().split())\n s=int((a*b)**0.5)\n if s==0:\n print(0)\n continue\n ret=2*s\n if (a*b-1)//s==s:\n ret-=1\n if min(a,b)<=s:\n ret-=1\n print(ret)', 'q=int(input())\nfor i in range(q):\n a,b=map(int,input().split())\n left=0\n right=a*b\n for i in range(100):\n mid=(left+right)//2\n if mid*mid<a*b:\n left=mid\n else:\n right=mid\n ret=left*2\n if ret==0:\n print(ret)\n continue\n if (a*b-1)//left==left:\n ret-=1\n if min(a,b)<=left:\n ret-=1\n print(ret)\n'] | ['Wrong Answer', 'Accepted'] | ['s249360604', 's880044507'] | [3064.0, 3060.0] | [18.0, 23.0] | [235, 388] |
p03390 | u777529218 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['import math\nq=int(input())\nfor j in range(q):\n\tAB=[int(i) for i in input().split()]\n\tAB.sort()#4,11\n\tab=AB[0]*AB[1] #44\n\tfor i in range(AB[0],AB[1]+1):\n\t\tif i*i>=ab:\n\t\t\tx=i-1\n\t\t\tbreak\n\tfor i in range(x,ab+1):\n\t\tif x*i>=ab:\n\t\t\ty=i-1\n\t\t\tbreak\n\tcnt1=2*x\n\tcnts=1 if x==y else 0\n\tcntdd=1 if x-AB[0]>=0 else 0\n\tcntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1\n\tprint(cnt1-cnts-cntdd-cntdu)', 'import math\nq=int(input())\nfor j in range(q):\n\tAB=[int(i) for i in input().split()]\n\tAB.sort()#4,11\n\tab=AB[0]*AB[1] #44\n\tfor i in range(int(sqrt(ab)),AB[1]+1):\n\t\tif i*i>=ab:\n\t\t\tx=i-1\n\t\t\tbreak\n\tfor i in range(int(ab/x),ab+1):\n\t\tif x*i>=ab:\n\t\t\ty=i-1\n\t\t\tbreak\n\tcnt1=2*x\n\tcnts=1 if x==y else 0\n\tcntdd=1 if x-AB[0]>=0 else 0\n\tcntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1\n\tprint(cnt1-cnts-cntdd-cntdu)', 'import math\nq=int(input())\nfor j in range(q):\n\tAB=[int(i) for i in input().split()]\n\tAB.sort()#4,11\n\tab=AB[0]*AB[1] #44\n\tfor i in range(int(math.sqrt(ab)),AB[1]+1):\n\t\tif i*i>=ab:\n\t\t\tx=i-1\n\t\t\tbreak\n\tif x==0:\n\t\tprint(0)\n\t\tcontinue\n\tfor i in range(int(ab/x),ab+1):\n\t\tif x*i>=ab:\n\t\t\ty=i-1\n\t\t\tbreak\n\tcnt1=2*x\n\tcnts=1 if x==y else 0\n\tcntdd=1 if x-AB[0]>=0 else 0\n\tcntdu=1 if AB[1]-y>=0 and (AB[1]+1)*(x-AB[1]+y)>=ab else 0 #x-i, y+i=c,b->c,b+1\n\tprint(cnt1-cnts-cntdd-cntdu)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s288822703', 's372033732', 's513492273'] | [3192.0, 3064.0, 3064.0] | [2104.0, 17.0, 18.0] | [414, 430, 467] |
p03390 | u876442898 | 2,000 | 262,144 | 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The _score_ of a participant is the product of his/her ranks in the two contests. Process the following Q queries: * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's. | ['# -*- coding: utf-8 -*-\n\nfrom math import ceil, sqrt\n\nQ = int(input())\nfor i in range(Q):\n A, B = sorted(map(int, input().split(" ")))\n s = A*B\n\n if A == B:\n print(2*A - 2)\n elif A == B + 1:\n print(2*A - 2)\n else:\n C = ceil(sqrt(s)) - 1\n print(2*C - 1)', '# -*- coding: utf-8 -*-\n\nfrom math import ceil, sqrt\n\nQ = int(input())\nfor i in range(Q):\n A, B = sorted(map(int, input().split(" ")))\n s = A*B\n\n if A == B:\n print(2*A - 2)\n elif A == B + 1:\n print(2*A - 2)\n else:\n C = ceil(sqrt(s)) - 1\n if C*(C+1) >= s:\n print(2*C - 2)\n else:\n print(2*C - 1)'] | ['Wrong Answer', 'Accepted'] | ['s494962399', 's969713301'] | [3064.0, 3188.0] | [18.0, 19.0] | [491, 561] |
p03391 | u145600939 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['import sys\ninput = sys.stdin.readline\nn = int(input())\nans = 0\nflag = 0\nfor i in range(n):\n a,b = map(int,input().split())\n if a > b:flag = 1\n ans += a\nprint(ans*flag)\n', 'import sys\ninput = sys.stdin.readline\nn = int(input())\nm = 10**10\nans = 0\nflag = 0\nfor i in range(n):\n a,b = map(int,input().split())\n if a > b:\n flag = 1\n m = min(m,b)\n ans += a\nprint((ans-m)*flag)\n'] | ['Wrong Answer', 'Accepted'] | ['s780043795', 's762199451'] | [3060.0, 3060.0] | [44.0, 46.0] | [171, 208] |
p03391 | u163320134 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['n=int(input())\narr=[list(map(int,input().split())) for _ in range(n)]\narr2=[]\nans=0\nfor a,b in arr:\n ans+=a\n arr2.append([a-b,b])\narr2=sorted(arr2,reverse=True)\nans=-arr2[0][1]\nprint(ans)', 'n=int(input())\narr=[list(map(int,input().split())) for _ in range(n)]\narr2=[]\nans=0\nmb=10**18\nfor a,b in arr:\n ans+=a\n if a>b:\n mb=min(mb,b)\nif mb==10**18:\n print(0)\nelse:\n print(ans-mb)'] | ['Wrong Answer', 'Accepted'] | ['s001049724', 's835971090'] | [10100.0, 7796.0] | [106.0, 85.0] | [189, 193] |
p03391 | u186426563 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['n = int(input())\na, b, c = [], [], []\nfor i in range(n):\n ab = list(map(int, input().split()))\n a.append(ab[0])\n b.append(ab[1])\n if(ab[0] > ab[1]):\n c.append(ab[1])\nif(len(c) == 0):\n print(0)\nelse:\n sort.c()\n print(sum(a) - c[0])', 'n = int(input())\na, b, c = [], [], []\nfor i in range(n):\n ab = list(map(int, input().split()))\n a.append(ab[0])\n b.append(ab[1])\n if(ab[0] > ab[1]):\n c.append(ab[1])\nif(len(c) == 0):\n print(0)\nelse:\n print(sum(a) - min(c))'] | ['Runtime Error', 'Accepted'] | ['s335671862', 's365005953'] | [5020.0, 5108.0] | [88.0, 88.0] | [258, 247] |
p03391 | u226155577 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['N = int(input())\nans = 0\nm = INF = 10**9+7\nd = []\nfor i in range(N):\n a, b = map(int, input().split())\n ans += a\n if a > b:\n m = min(m, b)\nprint(0 if INF else ans-m)', 'N = int(input())\nans = 0\nm = INF = 10**9+7\nd = []\nfor i in range(N):\n a, b = map(int, input().split())\n ans += a\n if a > b:\n m = min(m, b)\nprint(0 if INF == m else ans-m)'] | ['Wrong Answer', 'Accepted'] | ['s395073246', 's311076230'] | [3060.0, 3060.0] | [76.0, 78.0] | [181, 186] |
p03391 | u353797797 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['import sys\n\nsys.setrecursionlimit(10 ** 6)\ninput = sys.stdin.readline\n\ndef main():\n n=int(input())\n ab=[list(map(int, input().split())) for _ in range(n)]\n ab.sort(key=lambda x:x[0]-x[1])\n print(ab)\n re=0\n ans=0\n for a,b in ab:\n if a<b:\n ans+=b\n re+=b-a\n if a>=b:\n if re>=a:\n ans+=b\n re-=a\n else:\n ans+=b-a+re\n #print(a,b,re,ans)\n print(ans)\n\nmain()', 'import sys\n\nsys.setrecursionlimit(10 ** 6)\ninput = sys.stdin.readline\n\ndef main():\n n = int(input())\n min_b = 10 ** 10\n s = 0\n for _ in range(n):\n a, b = map(int, input().split())\n s += b\n if a > b:\n min_b = min(min_b, b)\n print(0) if min_b == 10 ** 10 else print(s - min_b)\n\nmain()\n'] | ['Wrong Answer', 'Accepted'] | ['s421672651', 's959716722'] | [9680.0, 3060.0] | [77.0, 42.0] | [483, 330] |
p03391 | u493813116 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['N = int(input())\nA = [0] * N\nB = [0] * N\nfor i in range(N):\n A[i], B[i] = map(int, input().split())\n\nc = 0\n\nif A == B:\n print(c)\n exit()\n\n\nfor i in range(N):\n if A[i] < B[i]:\n c += A[i]\n B[i] -= A[i]\n A[i] = 0\n\nwhile A != B:\n x = 0\n for i in range(N):\n if A[i] == 0:\n continue\n x = i\n if A[i] < B[i]:\n break\n A[x] -= 1\n y = 0\n for i in range(N):\n if A[i] == B[i]:\n continue\n y = i\n if A[i] < B[i]:\n break\n B[y] -= 1\n candy += 1\n\nprint(candy)\n', 'N = int(input())\n\nsame = True\nsum_a = 0\nmin_b = None\n\nfor _ in range(N):\n a, b = map(int, input().split())\n \n sum_a += a\n \n if a != b:\n same = False\n \n if a > b and (min_b is None or b < min_b):\n min_b = b\n\n\nif same:\n print(0)\n exit()\n\n\nif min_b is None:\n min_b = 0\n\nprint(sum_a - min_b)\n'] | ['Runtime Error', 'Accepted'] | ['s735753714', 's567939239'] | [4596.0, 3064.0] | [83.0, 78.0] | [652, 514] |
p03391 | u496131003 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['N = int(input())\nc = False\ns = 0\nfor i in range(N):\n ai,bi = map(int,input().split())\n s += ai\n if ai > bi:\n if not C:\n c = bi\n if bi < c:\n c = bi\nif not c:\n print(0)\nelse:\n print(s-c)', 'N = int(input())\nc = -1\ns = 0\nfor i in range(N):\n ai,bi = map(int,input().split())\n s += ai\n if ai > bi:\n if c == -1:\n c = bi\n if bi < c:\n c = bi\nif c == -1:\n print(0)\nelse:\n print(s-c)'] | ['Runtime Error', 'Accepted'] | ['s175624082', 's293715184'] | [3060.0, 3060.0] | [73.0, 75.0] | [235, 236] |
p03391 | u623687794 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['n=int(input())\nrem=0\nS=0\nallissame=0\nfor i in range(n):\n a,b=map(int,input().split())\n S+=a\n if a<b:\n allissame|=1\n continue\n elif a>b:\n if rem > b:\n rem=b\n allissame|=1\n else:pass\nif not allissame:\n print(0)\nelse:\n print(S-rem)\n', 'n=int(input())\nrem=10**10\nS=0\nallissame=0\nfor i in range(n):\n a,b=map(int,input().split())\n S+=a\n if a<b:\n allissame|=1\n continue\n elif a>b:\n if rem < b:\n rem=b\n allissame|=1\n else:pass\nif not allissame:\n print(0)\nelse:\n print(S-rem)\n', 'n=int(input())\nrem=10**10\nS=0\nallissame=0\nfor i in range(n):\n a,b=map(int,input().split())\n S+=a\n if a<b:\n allissame|=1\n continue\n elif a>b:\n if rem > b:\n rem=b\n allissame|=1\n else:pass\nif not allissame:\n print(0)\nelse:\n print(S-rem)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s474726460', 's809086245', 's694258813'] | [3060.0, 3060.0, 3060.0] | [81.0, 79.0, 79.0] | [253, 258, 258] |
p03391 | u692632484 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['N=int(input())\nab=[[int(i) for i in input().split()] for j in range(N)]\ntotal = sum([sum(row) for row in ab])//2\ndiff = [row[1] for row in ab if row[0]>row[1]]\nif len(diff)==0:\n print(0)\nelse:\n print(total-diff)\n', 'N=int(input())\nab=[[int(i) for i in input().split()] for j in range(N)]\ntotal = sum([sum(row) for row in ab])//2\ndiff = [row[1] for row in ab if row[0]>row[1]]\nif len(diff)==0:\n print(0)\nelse:\n print(total-min(diff))\n'] | ['Runtime Error', 'Accepted'] | ['s820942512', 's593694147'] | [7412.0, 7412.0] | [81.0, 81.0] | [218, 223] |
p03391 | u754022296 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['n = int(input())\ns = 0\nminb = float("inf")\nfor _ in range(n):\n a, b = map(int, input().split())\n if a > b:\n minb = min(b, minb)\n s += a\nif b == float("inf"):\n print(s - minb)\nelse:\n print(0)', 'n = int(input())\ns = 0\nminb = float("inf")\nfor _ in range(n):\n a, b = map(int, input().split())\n if a > b:\n minb = min(b, minb)\n s += a\nif minb == float("inf"):\n print(0)\nelse:\n print(s - minb)'] | ['Wrong Answer', 'Accepted'] | ['s846545443', 's008371253'] | [3060.0, 3060.0] | [77.0, 77.0] | [198, 201] |
p03391 | u768301880 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['import math\n\nn = int(input())\nc = -1\nsum_ = 0\nfor i in range(n)\x08:\n a, b = map(int, input().split())\n sum_ += a\n if a > b:\n if c == -1:\n c = b\n if b > c:\n c = b\nif c == -1:\n print("0")\nelse:\n print(s - c)\n', 'import math\n\nn = int(input())\nc = -1\nsum_ = 0\nfor i in range(n):\n a, b = map(int, input().split())\n sum_ += a\n if a > b:\n if c == -1:\n c = b\n if b < c:\n c = b\nif c == -1:\n print(0)\nelse:\n print(sum_ - c)\n'] | ['Runtime Error', 'Accepted'] | ['s789700445', 's704458056'] | [2940.0, 3060.0] | [17.0, 76.0] | [255, 255] |
p03391 | u876442898 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['# -*- coding: utf-8 -*-\n\n\n\n\n\n\n\n\n\n\n\nimport numpy as np\n\nN = int(input())\nqueA = []\nqueB = []\nfor i in range(N):\n A, B = map(int, input().split(" "))\n queA.append(A)\n queB.append(B)\n\ncnt = 0\nif np.allclose(A, B):\n print(cnt)\n\n\n\nfor i in range(N):\n if queA[i] <= queB[i]:\n cnt += queA[i]\n queB[i] -= queA[i]\n queA[i] = 0\n\nは, queA[i] > queB[i]なるqueA[i]を-1するのみになる.\n\n\nfor i in range(N):\n if queA[i] == 0:\n cnt += queB[i]\n queB[i] = 0\n\nprint(cnt)', '# -*- coding: utf-8 -*-\n\n\n\n\n\n\n\n\n\n\n\nimport numpy as np\ndef tozan_and_gezan():\n N = int(input())\n queA = []\n queB = []\n for i in range(N):\n A, B = map(int, input().split(" "))\n queA.append(A)\n queB.append(B)\n\n cnt = 0\n if np.allclose(queA, queB):\n print(cnt)\n return 0\n\n \n \n for i in range(N):\n if queA[i] <= queB[i]:\n cnt += queA[i]\n queB[i] -= queA[i]\n queA[i] = 0\n\n if np.allclose(queA, queB):\n print(cnt)\n return 0\n\n は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.\n \n \n for i in range(N):\n if queA[i] == 0:\n cnt += queB[i]\n queB[i] = 0\n\n print(cnt)\n return 0\n\ntozan_and_gezan()', '# -*- coding: utf-8 -*-\n\n\n\n\n\n\n\n\n\n\n\nimport numpy as np\n\nN = int(input())\nqueA = []\nqueB = []\nfor i in range(N):\n A, B = map(int, input().split(" "))\n queA.append(A)\n queB.append(B)\n\ncnt = 0\nif np.allclose(queA, queB):\n print(cnt)\nelse:\n \n \n for i in range(N):\n if queA[i] <= queB[i]:\n cnt += queA[i]\n queB[i] -= queA[i]\n queA[i] = 0\n\n は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.\n \n \n for i in range(N):\n if queA[i] == 0:\n cnt += queB[i]\n queB[i] = 0\n\n print(cnt)', '# -*- coding: utf-8 -*-\n\n\n\n\nN = int(input())\nqueA = []\nqueB = []\nfor i in range(N):\n A, B = map(int, input().split(" "))\n queA.append(A)\n queB.append(B)\n\ncnt = 0\nif np.allclose(queA, queB):\n print(cnt)\n return 0\nelse:\n tmp = []\n for i, B in enumerate(queB):\n if queA[i] > B:\n tmp.append(B)\n print(sum(queA) - min(tmp))', '# -*- coding: utf-8 -*-\n\n\n\n\n\n\n\n\n\n\n\nimport numpy as np\n\nN = int(input())\nqueA = []\nqueB = []\nfor i in range(N):\n A, B = map(int, input().split(" "))\n queA.append(A)\n queB.append(B)\n\ncnt = 0\nif np.allclose(A, B):\n print(cnt)\nelse:\n \n \n for i in range(N):\n if queA[i] <= queB[i]:\n cnt += queA[i]\n queB[i] -= queA[i]\n queA[i] = 0\n\n は, queA[i] > queB[i]なるqueA[i]を-1するのみになる.\n \n \n for i in range(N):\n if queA[i] == 0:\n cnt += queB[i]\n queB[i] = 0\n\n print(cnt)', '# -*- coding: utf-8 -*-\n\ninf = 10**20\n\nN = int(input())\ns = 0\nm = inf\nfor i in range(N):\n a, b = map(int, input().split(" "))\n if a > b:\n if m < b:\n m = b\n s += a\nif m == inf:\n print(0)\nelse:\n print(s - m)', '# -*- coding: utf-8 -*-\n\ninf = 10**20\n\nN = int(input())\ns = 0\nm = inf\nfor i in range(N):\n a, b = map(int, input().split(" "))\n if a > b:\n if m > b:\n m = b\n s += a\nif m == inf:\n print(0)\nelse:\n print(s - m)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s074372350', 's097742705', 's418374684', 's479643716', 's590113022', 's922700751', 's719257229'] | [13896.0, 14532.0, 16116.0, 3064.0, 13896.0, 3188.0, 3064.0] | [221.0, 216.0, 243.0, 17.0, 221.0, 76.0, 76.0] | [1078, 1324, 1149, 545, 1143, 423, 423] |
p03391 | u922449550 | 2,000 | 262,144 | You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats the following sequence of operations: * If A and B are equal sequences, terminate the process. * Otherwise, first Tozan chooses a positive element in A and decrease it by 1. * Then, Gezan chooses a positive element in B and decrease it by 1. * Then, give one candy to Takahashi, their pet. Tozan wants the number of candies given to Takahashi until the process is terminated to be as large as possible, while Gezan wants it to be as small as possible. Find the number of candies given to Takahashi when both of them perform the operations optimally. | ['N = int(input())\ndiff_a_b = []\nfor i in range(N):\n a, b = map(int, input().split())\n diff_a_b.append([a - b, a, b])\n\ndiff_a_b.sort()\nif diff_a_b[0][0] == 0: \n print(0)\n quit()\n\nans = 0\nd = 0\nfor diff, a, b in diff_a_b:\n if diff <= 0: # a <= b\n ans += b\n d -= diff\n else:\n if d > diff:\n d -= diff\n ans += b\n else: # d <= diff\n ans += d\n break\n\nprint(ans)', 'N = int(input())\ndiff_a_b = []\nfor i in range(N):\n a, b = map(int, input().split())\n diff_a_b.append([a - b, a, b])\n\ndiff_a_b.sort()\nif diff_a_b[0][0] == 0: \n print(0)\n quit()\n\nans = 0\nd = 0\ntemp = 10**10\nfor diff, a, b in diff_a_b:\n if diff <= 0: # a <= b\n ans += b\n d -= diff\n else:\n ans += b\n temp = min(temp, b)\n\nprint(ans - temp)'] | ['Wrong Answer', 'Accepted'] | ['s660147319', 's122446806'] | [7116.0, 6996.0] | [106.0, 105.0] | [423, 384] |
p03393 | u022979415 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string import ascii_lowercase\n\n\ndef main():\n word = input()\n if len(word) < 26:\n count = {}\n for a in ascii_lowercase:\n count[a] = 0\n for w in word:\n count[w] += 1\n count_l = list(count.items())\n count_l.sort(key=lambda x: x[0])\n print(count_l)\n add = ""\n for i in range(26):\n if count_l[i][1] == 0:\n add = count_l[i][0]\n break\n print(word + add)\n elif word == ascii_lowercase[::-1]:\n print(-1)\n else:\n is_printed = False\n while len(word) > 0 and not is_printed:\n for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:\n if c not in word[:-1]:\n print(word[:-1] + c)\n is_printed = True\n break\n else:\n word = word[:-1]\n\n\nif __name__ == \'__main__\':\n main()\n\n', 'from string import ascii_lowercase\n\n\ndef main():\n word = input()\n if word == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n elif len(word) < 26:\n count = {}\n for a in ascii_lowercase:\n count[a] = 0\n for w in word:\n count[w] += 1\n count = count.items()\n add = ""\n for i in range(26):\n if count[i][1] == 0:\n add = count[i][0]\n break\n print(word + add)\n else:\n stop = ascii_lowercase[::-1]\n final_permutation_index = 25\n for i in range(-2, -27, -1):\n if word[i:] not in stop:\n final_permutation_index = 26 + i\n break\n if final_permutation_index != 25:\n print(word[:final_permutation_index] + word[-1])\n else:\n word = list(word)\n if word[-2] == "z":\n word[-1], word[-3] = word[-3], word[-1]\n else:\n word[-1], word[-2] = word[-2], word[-1]\n print("".join(word))\n\n\n\nif __name__ == \'__main__\':\n main()\n\n', 'from string import ascii_lowercase\n\n\ndef main():\n word = input()\n if len(word) < 26:\n count = {}\n for a in ascii_lowercase:\n count[a] = 0\n for w in word:\n count[w] += 1\n count_l = list(count.items())\n count_l.sort(key=lambda x: x[0])\n add = ""\n for i in range(26):\n if count_l[i][1] == 0:\n add = count_l[i][0]\n break\n print(word + add)\n elif word == ascii_lowercase[::-1]:\n print(-1)\n else:\n is_printed = False\n while len(word) > 0 and not is_printed:\n for c in ascii_lowercase[ascii_lowercase.index(word[-1]) + 1:]:\n if c not in word[:-1]:\n print(word[:-1] + c)\n is_printed = True\n break\n else:\n word = word[:-1]\n\n\nif __name__ == \'__main__\':\n main()\n\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s142543757', 's937771303', 's309528444'] | [3768.0, 3768.0, 3772.0] | [25.0, 26.0, 24.0] | [939, 1086, 916] |
p03393 | u047668580 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 sys\n \n \nalph="abcdefghijklmnopqrstuvwxyz"\nallis=list(alph)\nS=input()\nif(S=="zyxwvutsrqponmlkjihgfedcba"):\n print(-1)\n sys.exit()\n \nfor i in alph:\n if(i not in S):\n print(S)\n sys.exit()\n \nl=-1\nfor i in range(len(S)-1)[::-1]:\n if(ord(S[i])<ord(S[i+1])):\n l=i\n break\n \nx=sorted(S[i+1:])\nfor i in x:\n if(i>S[l]):\n print(S[:l]+i)\n sys.exit()', 'inp = input()\ninp_len = len(inp)\nchars = map(ord,list(inp))\ndic = {}\nan = ""\nif inp == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\nif inp_len == 26:\n for i in range(25):\n if ord(inp[-1 - i]) > ord(inp[-2 - i]):\n an = inp[:-2-i]\n ls = inp[-2-i]\n for char in map(ord,list(inp[-1-i:])):\n dic[char] = "exist"\n break\n for j in range(26):\n if 97 + j in dic and 97+ j > ord(ls):\n an = an + chr(97+j)\n break\nelse:\n for char in chars:\n dic[char] = "exist"\n for i in range(26):\n if not (97 + i) in dic:\n an = inp + chr(97+i)\n break\nprint(an)\n'] | ['Wrong Answer', 'Accepted'] | ['s075660595', 's501277769'] | [3064.0, 3064.0] | [17.0, 17.0] | [414, 691] |
p03393 | u064408584 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nal=[chr(ord('a') + i) for i in range(26)]\nal=[i for i in al if i not in s]\nif al:\n print(s+al[0])\n exit()\nfor i in range(25,0,-1):\n if s[i-1]<s[i]:\n s=s[:i-1]+[s[-1]]\n print(''.join(s))\n exit()\nelse:print(-1)", "s=input()\nal=[chr(ord('a') + i) for i in range(26)]\nal=[i for i in al if i not in s]\nif not al:\n print(-1)\n exit()\nfor i,j in enumerate(s):\n if al[0]<j:\n print(s[:i]+al[0]+s[i:])\n break", "s=list(input())\nal=[chr(ord('a') + i) for i in range(26)]\nal=[i for i in al if i not in s]\nif al:\n print(''.join(s)+al[0])\n exit()\nfor i in range(25,0,-1):\n if s[i-1]<s[i]:\n a=[j for j in s[i-1:] if s[i-1]<j]\n s=s[:i-1]+[sorted(a)[0]]\n print(''.join(s))\n break\n exit()\nelse:print(-1)"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s081594598', 's491890892', 's648552420'] | [3064.0, 3060.0, 3064.0] | [18.0, 17.0, 18.0] | [254, 208, 327] |
p03393 | u075012704 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nZ = sorted(list(S))\nG = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]\nans = []\nfor s in S:\n if s not in ans:\n ans.append(s)\n else:\n i = G.index(s)\n j = 0\n while j < 27:\n if G[(i + j) % 26] not in ans:\n ans.append(G[(i + j) % 26])\n break\n j += 1\n\nfor i in range(len(ans)):\n if "".join(ans[:i+1]) > S:\n print("".join(ans[:i+1]))\n exit()\nfor i in range(100):\n aaa = sorted(ans)\n print(ans)\n if "".join(ans) > S:\n print("".join(ans))\n exit()\n else:\n i = G.index(aaa[0])\n j = 0\n while j < 27:\n if G[(i + j) % 26] not in ans:\n ans.append(G[(i + j) % 26])\n break\n j += 1\n\nans = "".join(ans)\nS = "".join(S)\nif ans == S:\n ans = list(ans)\n aaa = sorted(list(ans))\n i = G.index(aaa[0])\n j = 0\n while j < 27:\n if G[(i + j) % 26] not in ans:\n ans.append(G[(i + j) % 26])\n break\n j += 1\n else:\n for i in range(len(S)-1, -1, -1):\n for j in range(i, -1, -1):\n if S[i] > S[j]:\n print(S[:j] + S[i])\n exit()\nans = "".join(ans)\nif ans > S:\n print(ans)\nelse:\n print(-1)\n\n\n\n\n', 'S = input()\nC = [chr(97+i) for i in range(26)]\n\nif len(S) != 26:\n for c in C:\n if c not in S:\n print(S + c)\n break\nelse:\n K = []\n for i in range(25, -1, -1):\n K.append(S[i])\n K.sort()\n for j in range(25, -1, -1):\n if K[0] > S[j]:\n print(S[:j] + K[0])\n exit()\nprint(-1)\n\n', 'S = input()\nC = [chr(97+i) for i in range(26)]\n\n\nif S == "".join(C.sort(reverse=True)):\n print(-1)\n\nelif len(S) != 26:\n for c in C:\n if c not in S:\n print(S + c)\n break\nelse:\n K = []\n for i in range(25, -1, -1):\n K.append(S[i])\n K.sort()\n for j in range(25, -1, -1):\n if K[0] > S[j]:\n print(S[:j])\n exit()\n\n', 'S = input()\nA = [chr(ord("a")+i) for i in range(26)]\n\nif len(set(S)) < 26:\n for a in A:\n if a not in S:\n print(S+a)\n break\nelse:\n X = []\n for i in range(25, 0, -1):\n if S[i] > S[i-1]:\n X.append(S[i])\n X = sorted(list(filter(lambda x: x > S[i-1], X)))\n print(S[:i-1]+X[0])\n break\n else:\n X.append(S[i])\n else:\n print(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s023554257', 's023879075', 's408017561', 's890615235'] | [3188.0, 3064.0, 3064.0, 3064.0] | [19.0, 18.0, 18.0, 17.0] | [1383, 370, 410, 436] |
p03393 | u089142196 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['alp=[chr(ord(\'a\') + i) for i in range(26)]\nunused=set(alp)\n \nS=input()\nprint("len",len(S))\n\nif len(S)<26:\n for i in range(len(S)):\n if S[i] in unused:\n unused.remove(S[i])\n unused=sorted(unused)\n print(S+unused[0])\nelse:\n for j in range(len(S)-1,-1,-1):\n p=set(S[j:])\n #print(p)\n q=sorted(p)\n if S[j]==q[-1]:\n pass\n else:\n idx=q.index(S[j])\n print(S[:j]+q[idx+1])\n break\n else:\n print(-1)', 'alp=[chr(ord(\'a\') + i) for i in range(26)]\nunused=set(alp)\n \nS=input()\n#print("len",len(S))\n\nif len(S)<26:\n for i in range(len(S)):\n if S[i] in unused:\n unused.remove(S[i])\n unused=sorted(unused)\n print(S+unused[0])\nelse:\n for j in range(len(S)-1,-1,-1):\n p=set(S[j:])\n #print(p)\n q=sorted(p)\n if S[j]==q[-1]:\n pass\n else:\n idx=q.index(S[j])\n print(S[:j]+q[idx+1])\n break\n else:\n print(-1)'] | ['Wrong Answer', 'Accepted'] | ['s191227131', 's055878056'] | [3064.0, 3188.0] | [17.0, 17.0] | [511, 512] |
p03393 | u102960641 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['a={chr(i) for i in range(ord(a),ord(a)+25)}\ns=input()\nn=len(s)\nif n<26:\n print(s+sorted(a-set(s))[0])\nelse:\n for i in range(2,27):\n if s[-i]<s[-i+1]:\n break\n if i==26:\n print(-1)\n exit()\n for j in sorted(s[-i+1:]):\n if j>s[-i]:break\n print(s[:-i]+j)\n', 'a={chr(i) for i in range(ord("a"),ord("a")+26)}\ns=input()\nn=len(s)\nif n<26:\n print(s+sorted(a-set(s))[0])\nelse:\n for i in range(2,27):\n if s[-i]<s[-i+1]:\n break\n if i==26:\n print(-1)\n exit()\n for j in sorted(s[-i+1:]):\n if j>s[-i]:break\n print(s[:-i]+j)'] | ['Runtime Error', 'Accepted'] | ['s159157218', 's544021808'] | [3060.0, 3064.0] | [19.0, 17.0] | [278, 281] |
p03393 | u112007848 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['dic = [False for i in range(26)]\ntxt = input()\nfor i in txt:\n dic[ord(i) - 97] = True\nfor i in range(26):\n if not dic[i]:\n break\nelse:\n for j in range(25):\n if txt[24 - j] < txt[25 - j]:\n \n last = txt[24-j] \n txt = txt[:24 - j]\n \n dic = [False for i in range(26)]\n for k in txt:\n dic[ord(k) - 97] = True\n txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)\n\n print(txt)\n break\n\n else:\n print(-1)', 'dic = [False for i in range(26)]\ntxt = input()\nfor i in txt:\n dic[ord(i) - 97] = True\nfor i in range(26):\n if not dic[i]:\n print(txt + chr(i + 97))\n break\nelse:\n for j in range(25):\n if txt[24 - j] < txt[25 - j]:\n \n last = txt[24-j] \n txt = txt[:24 - j]\n \n dic = [False for i in range(26)]\n for k in txt:\n dic[ord(k) - 97] = True\n txt += chr(dic[ord(last) - 96:].index(False) + ord(last) + 1)\n\n print(txt)\n break\n\n else:\n print(-1)'] | ['Wrong Answer', 'Accepted'] | ['s433114012', 's551530275'] | [9064.0, 9048.0] | [26.0, 30.0] | [498, 527] |
p03393 | u177481830 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nif len(S) < 26:\n for c in string.ascii_lowercase:\n if c not in S:\n break\n print(S + c)\nelse:\n ret = None\n for i in range(26):\n if max(S[25-i:]) != S[25-i]:\n mc = 'z'\n for c in S[25-i:]:\n if c > S[25-i]:\n mc = min(c, mc)\n ret = S[:25-i] + mc\n break\n \n if ret is None:\n print(-1)\n else:\n print(ret)", 'import string\n \nS = input()\nif len(S) < 26:\n for c in string.ascii_lowercase:\n if c not in S:\n break\n print(S + c)\nelse:\n ret = None\n for i in range(1, 26):\n idx = 25 - i\n if max(S[idx:]) != S[idx]:\n mc = min([c for c in S[(idx+1):] if c > S[idx]])\n ret = S[:idx] + mc\n break\n if ret is None:\n print(-1)\n else:\n print(ret)'] | ['Runtime Error', 'Accepted'] | ['s906853108', 's885978053'] | [3064.0, 3768.0] | [18.0, 24.0] | [454, 419] |
p03393 | u183896397 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nalpha = [chr(i) for i in range(97, 97+26)]\nif len(S) == 26:\n ans = S\n x = S[-1]\n for i in range(2,26):\n if alpha.index(x) > alpha.index(S[-1*i]):\n ans = S[:-1*i]\n ans.append(x)\n break\nelse:\n ans = S\n for i in alpha:\n if i not in S:\n ans.append(i)\nif ans == S:\n print(-1)\nelse: \n print("".join(ans))', "S = input()\nalphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']\nfor i in alphabet:\n if i not in S:\n print(S + i)\n break\nelse:\n output = False\n while len(S) > 0 and not output:\n last = alphabet.index(S[-1])\n for i in alphabet[last + 1:]:\n if i not in S[:-1]:\n print(S[:-1] + i)\n output = not(output)\n break\n else:\n S = S[:-1]\n if not output:\n print(-1)\n"] | ['Wrong Answer', 'Accepted'] | ['s974305210', 's745013170'] | [3064.0, 3064.0] | [17.0, 17.0] | [397, 563] |
p03393 | u193264896 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 sys\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float(\'inf\')\nMOD = 10 ** 9 + 7\n\ndef main():\n s = readline().decode(\'utf-8\')\n if len(s) < 26:\n al = [chr(ord(\'a\') + i) for i in range(26)]\n for i in al:\n if not (i in s):\n print(s + i)\n exit()\n if s == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\n for i in range(25):\n if s[i] < s[i + 1]:\n k = i\n a = "z"\n for i in range(k + 1, 26):\n if s[k] < s[i]:\n a = min(a, s[i])\n print(s[:k] + a)\nif __name__ == \'__main__\':\n main()', 'import sys\nreadline = sys.stdin.buffer.readline\nsys.setrecursionlimit(10 ** 8)\nINF = float(\'inf\')\nMOD = 10 ** 9 + 7\n\ndef main():\n s = input()\n if len(s) < 26:\n al = [chr(ord(\'a\') + i) for i in range(26)]\n for i in al:\n if not (i in s):\n print(s + i)\n exit()\n if s == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\n for i in range(25):\n if s[i] < s[i + 1]:\n k = i\n a = "z"\n for i in range(k + 1, 26):\n if s[k] < s[i]:\n a = min(a, s[i])\n print(s[:k] + a)\n\nif __name__ == \'__main__\':\n main()'] | ['Runtime Error', 'Accepted'] | ['s625134898', 's814002636'] | [3064.0, 3064.0] | [17.0, 17.0] | [637, 619] |
p03393 | u201234972 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nl = len(S)\nif l != 26:\n colors = [0]*26\n for i in range(26):\n colors[ ord(S[i]) - ord(\'a\')]\n for i in range(26):\n if colors[i] == 0:\n ans = S + chr( i + ord(\'a\'))\n break\n print(ans)\nelif S == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\nelse:\n for i in range(25,0,-1):\n if S[i] > S[i-1]:\n now = i\n break\n print(S[:i-1] + S[-1])', 'S = input()\nl = len(S)\nif l != 26:\n colors = [0]*26\n for i in range(l):\n colors[ ord(S[i]) - ord(\'a\')] = 1\n for i in range(26):\n if colors[i] == 0:\n ans = S + chr( i + ord(\'a\'))\n break\n print(ans)\nelif S == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\nelse:\n for i in range(25,0,-1):\n if S[i] > S[i-1]:\n now = i\n break\n colors = [0]*26\n for i in range(now-1):\n colors[ ord(S[i]) - ord(\'a\')] = 1\n c = \'z\'\n for i in range(now-1,26):\n if S[now-1] < S[i]:\n c = min(c, S[i])\n print(S[:now-1]+c)\n'] | ['Runtime Error', 'Accepted'] | ['s884230581', 's921703786'] | [3064.0, 3064.0] | [18.0, 18.0] | [421, 609] |
p03393 | u280512618 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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\nfrom itertools import dropwhile\n\nalphabet = set('abcdefghijklmnopqrstuvwxyz')\n\nif __name__ == '__main__':\n s = input()\n l = [c for c in alphabet - set(s)]\n if l != []:\n print(s + min(l))\n quit(0)\n\n deq = deque()\n deq.append(s[-1])\n for i in range(24, -1, -1):\n if s[i] < s[i + 1]:\n small = next(dropwhile(lambda c <= s[i], deq))\n print(s[:i] + small)\n quit(0)\n else:\n deq.append(s[i])\n\n print(-1)\n\n\n\n", "from collections import deque\nfrom itertools import dropwhile\n\nalphabet = set('abcdefghijklmnopqrstuvwxyz')\n\nif __name__ == '__main__':\n s = input()\n l = [c for c in alphabet - set(s)]\n if l != []:\n print(s + min(l))\n quit(0)\n\n deq = deque()\n deq.append(s[-1])\n for i in range(24, -1, -1):\n if s[i] < s[i + 1]:\n small = dropwhile(lambda c <= s[i], deq)\n print(s[:i] + small)\n quit(0)\n else:\n deq.append(s[i])\n\n print(-1)\n\n\n\n", "from collections import deque\nfrom itertools import dropwhile\n\nalphabet = set('abcdefghijklmnopqrstuvwxyz')\n\nif __name__ == '__main__':\n s = input()\n l = [c for c in alphabet - set(s)]\n if l != []:\n print(s + min(l))\n quit(0)\n\n deq = deque()\n deq.append(s[-1])\n for i in range(24, -1, -1):\n if s[i] < s[i + 1]:\n small = next(dropwhile(lambda c: c <= s[i], deq))\n print(s[:i] + small)\n quit(0)\n else:\n deq.append(s[i])\n\n print(-1)\n\n\n\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s288223901', 's989269725', 's485047921'] | [2940.0, 2940.0, 3316.0] | [17.0, 18.0, 21.0] | [523, 517, 526] |
p03393 | u291766461 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string\nS = input()\nif len(S) == 26:\n if S == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n i = len(S) - 1\n while 0 <= i:\n if S[i-1] < S[i]:\n min_val = min(S[i:])\n i -= 1\n break\n i -= 1\n ans = ""\n for x in range(i):\n ans += S[x]\n ans += min_val\n print(ans)\n\n exit()\n\n\n# chars_set = set(S)\n# for c in string.ascii_lowercase:\n# if c not in chars_set:\n# S += c\n# break\n# print(S)', 'import string\nS = input()\nif len(S) == 26:\n if S == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n i = len(S) - 1\n while 0 <= i:\n if S[i-1] < S[i]:\n break\n i -= 1\n ans = ""\n for x in range(i):\n ans += S[x]\n\n for j in S[i:][::-1]:\n if ans[-1] < j:\n ans = ans[:-1] + j\n break\n\n print(ans)\n\n exit()\n\nchars_set = set(S)\nfor c in string.ascii_lowercase:\n if c not in chars_set:\n S += c\n break\nprint(S)'] | ['Wrong Answer', 'Accepted'] | ['s439101979', 's067929841'] | [3772.0, 3768.0] | [25.0, 26.0] | [541, 562] |
p03393 | u311636831 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 bisect\n\nM=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nO=input()\nS=list(O+" ")\n\ndic={}\n\nfor I in list(O):\n if(dic.get(I,None)==None):\n dic[I]=1\n print(-1)\n exit()\n else:\n print(-1)\n exit()\n \nif(len(O)!=26):\n for i in range(26):\n if(M[i] not in S):\n print(O,M[i],sep="")\n exit()\nelse:\n ind=bisect.bisect_left(M,S[0])\n for i in range(26-ind):\n if(S[i]!=M[ind+i]):\n for j in range(26-1,i,-1):\n if(S[j-1]<S[j]):\n for k in range(26):\n if(M[k] not in S[0:j-1]):\n if(S[j-1]!=M[k]):\n print("".join(S[0:j-1]),M[k],sep="")\n exit()\n \n for j in range(26):\n if(M[j] not in S[0:i-1]):\n if(S[i-1]!=M[j]):\n print("".join(S[0:i-1]),M[j],sep="")\n exit() \n print(-1)\n\n\n"""\nelse:\n ind=bisect.bisect_left(M,S[0])\n for i in range(26-ind):\n if(S[i]!=M[ind+i]):\n for j in range(26):\n if(M[j] not in S[0:i-1]):\n if(S[i-1]!=M[j]):\n print("".join(S[0:i-1]),M[j],sep="")\n exit()\n print(-1)\n"""', 's=input()\nalp="".join([chr(i) for i in range(97,97+26)])\nif len(s)<26:\n for i in alp:\n if i not in s:\n print(s+i)\n exit()\nelse:\n if s=="".join([chr(i) for i in range(97,97+26)][::-1]):\n print(-1)\n exit()\n else:\n for i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i]<s[j]:\n print(s[:i]+s[j])\n exit()\n'] | ['Wrong Answer', 'Accepted'] | ['s813783058', 's824323804'] | [3188.0, 3064.0] | [17.0, 18.0] | [1414, 429] |
p03393 | u329706129 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['print(-1)', 'S = input()\nli = [chr(ord(\'a\') + i) for i in range(26)]\nused = [0] * 26\ndic = dict(zip(li, used))\nfor i in range(len(S)): dic[S[i]] = 1\nif(len(S) < 26):\n for i in range(26):\n k = chr(ord(\'a\') + i)\n v = dic[k]\n if(v == 0):\n print(S + k)\n exit(0)\n\nif(len(S) == 26):\n for i in range(25, -1, -1):\n for j in range(26): dic[chr(ord(\'a\') + j)] = 0\n for j in range(i): dic[S[j]] = 1\n add_c = ""\n for j in range(i + 1, 26):\n if(S[j] > S[i]):\n if(add_c == ""): add_c = S[j]\n else: add_c = min(add_c, S[j])\n if(add_c):\n print(S[:i] + add_c)\n exit(0)\nprint(-1)\n'] | ['Wrong Answer', 'Accepted'] | ['s839726557', 's883753154'] | [2940.0, 3064.0] | [18.0, 18.0] | [9, 696] |
p03393 | u357751375 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nm = list('zyxwvutsrqponmlkjihgfedcba')\nif len(s) < 26:\n for i in m:\n if not i in s:\n s.append(_)\n break\n print(''.join(s))\nelse:\n if s == m:\n print(-1)\n else:\n x = s[-1]\n for i in range(25)[::-1]:\n if x > s[i]:\n s = s[:i]\n s.append(i)\n break\n if i == 0:\n z = m.index(s[0])\n s = m[z-1]\n print(''.join(s))\n\n", "s = list(input())\nn = list('abcdefghijklmnopqrstuvwxyz')\nif len(s) < 26:\n for _ in m:\n if not _ in s:\n s.append(_)\n break\n print(''.join(s))\nelse:\n if s == n[::-1]:\n print(-1)\n else:\n x = s[-1]\n for _ in range(25)[::-1]:\n if x > s[_]:\n s = s[:_]\n s.append(x)\n break\n print(''.join(s))", "s = input()\nif s == 'zyxwvutsrqponmlkjihgfedcba':\n print(-1)\n exit(0)\nl = list('abcdefghijklmnopqrstuvwxyz')\nfor i in range(26):\n if l[i] != s[i]:\n print(s[:i-1] + l[i])\n exit(0)", "s = list(input())\nm = list('zyxwvutsrqponmlkjihgfedcba')\nif len(s) < 26:\n for i in m[::-1]:\n if not j in s:\n s.append(j)\n break\n print(''.join(s))\nelse:\n if s == m:\n print(-1)\n else:\n x = s[-1]\n for i in range(25)[::-1]:\n if x > s[i]:\n s = s[:i]\n s.append(x)\n break\n if i == 0:\n z = m.index(s[0])\n s = m[z-1]\n break\n print(''.join(s))", "s = list(input())\nm = list('zyxwvuutsrqponmlkjihgfedcba')\nif len(s) < 26:\n for _ in m:\n if not _ in s:\n s.append(_)\n break\n print(''.join(s))\nelse:\n if s == m:\n print(-1)\n else:\n x = s[-1]\n for _ in range(25)[::-1]:\n if x > s[_]:\n s = s[:_]\n s.append(x)\n break\n print(''.join(s))\n\n", "s = list(input())\nm = list('zyxwvutsrqponmlkjihgfedcba')\nif len(s) < 26:\n for i in m[::-1]:\n if not i in s:\n s.append(i)\n break\n print(''.join(s))\nelse:\n x = s[-1]\n\n for i in range(25)[::-1]:\n if x > s[i]:\n y = m.index(s[i])\n s = s[:i]\n for j in range(y)[::-1]:\n if not m[j] in s:\n s.append(m[j])\n break\n break\n else:\n x = s[i]\n if i == 0:\n print(-1)\n exit(0)\n print(''.join(s))"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s157019355', 's552396079', 's591622159', 's819036081', 's994044451', 's928173004'] | [9144.0, 9104.0, 9044.0, 9088.0, 8984.0, 9076.0] | [27.0, 29.0, 26.0, 26.0, 30.0, 29.0] | [489, 409, 201, 515, 406, 573] |
p03393 | u364439209 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string\n\nS = input()\nalphabetsStr = string.ascii_lowercase\nalphabets = list(map(lambda x: x, string.ascii_lowercase))\nlastWord = ''.join(alphabets[::-1])\n\nif len(S) == 26:\n if S == lastWord: print(-1)\n else:\n for i in S:\n if alphabets[i] != S[i]:\n print(S[:i] + alphabets[i])\n break\n# else:\n# for s in alphabets:\n# if s not in S:\n# print(S + s)\n# break\n\nprint(-1)", "import string\n\nS = input()\n\nif len(S) == 26: print(-1)\nretS = ''\nalphabetsStr = string.ascii_lowercase\nalphabets = list(map(lambda x: x, string.ascii_lowercase))\nfound = False\nlenS = len(S)\nif S[0] == 'a':\n for i in range(len(S)):\n if S[i] != alphabets[i]:\n retS = string.ascii_lowercase[:i+1]\n found = True\n break\nelse:\n idx = alphabets.index(S[0])\n for i in range(1, idx+1):\n if S[i] != alphabets[i-1]:\n retS = S[:i] + alphabets[i-1]\n found = True\n break\n if not found:\n for i in range(idx+1, len(S)):\n if S[i] != alphabets[i]:\n retS = string.ascii_lowercase[:i+1]\n found = True\n break\n \nif not found: retS = S + alphabets[len(S)]\nprint(retS)\n\n\n ", "import string\n\nS = input()\nalphabets = list(string.ascii_lowercase)\nlastWord = ''.join(alphabets[::-1])\ncnt = [S.count(chr(ord('a')+i)) for i in range(26)]\nif len(S) == 26:\n if S == lastWord: print(-1)\n else:\n for i in S:\n if alphabets[i] != S[i]:\n print(S[:i] + alphabets[i])\n break\nelse:\n print('test')", "import string\n\nS = input()\nreversedS = ''.join(list(S)[::-1])\nalphabets = list(string.ascii_lowercase)\nlastWord = ''.join(alphabets[::-1])\ncnt = [S.count(chr(ord('a')+i)) for i in range(26)]\nif len(S) == 26:\n if S == lastWord: print(-1)\n else:\n found = False\n for i in range(len(reversedS)):\n s = reversedS[i]\n largeS = alphabets[ord(s)-ord('a')+1:]\n tailS = list(S)[26-i-1:]\n for lS in largeS:\n if lS in tailS:\n print(S[:26-i-1]+lS)\n found = True\n break\n if found: break\nelse:\n for j in range(26):\n if cnt[j] == 0:\n S += chr(ord('a')+j)\n print(S)\n break\n"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s354833282', 's425185267', 's971250212', 's501438978'] | [3772.0, 3828.0, 3772.0, 3892.0] | [25.0, 27.0, 25.0, 24.0] | [460, 809, 361, 745] |
p03393 | u367130284 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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() \nprint(s)\n \nfor j in reversed(range(len(s)-1)):\n sets=set(s[:j])\n #print(sets)\n for i in range(ord(s[j]) + 1,123):\n if chr(i) not in sets:\n \n exit()\nprint(-1)', 's = input() \n#print(s)\n \nfor j in reversed(range(len(s)-1)):\n sets=set(s[:j])\n #print(sets)\n for i in range(ord(s[j]) + 1,123):\n if chr(i) not in sets:\n print(s[:j] + chr(i))\n exit()\nprint(-1)', 's = input()+"`"\nfor j in reversed(range(len(s))):\n a=set(map(chr,range(ord(s[j])+1,123)))-set(s[:j])\n if len(a)>0:\n print(s[:j]+min(a))\n exit()\nprint(-1)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s197421032', 's577127623', 's303086827'] | [3060.0, 3060.0, 3060.0] | [17.0, 17.0, 17.0] | [240, 240, 173] |
p03393 | u373047809 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string import*;from itertools import*\nb=ascii_lowercase;r=s=input();d=l=len(s);t=s[::-1]\nif l>25:d=-[p*len(list(k))for p,k in groupby([i<j for i,j in zip(s[::-1],s[-2::-1])])][0]-2;s,b,o=s[:d],s[d+1:],1\nprint(-(d<-26)or s+sorted(set(b)-set([s,b[:ord(s[d])-97]][o]))[0])', 'from string import*\nfrom itertools import*\nb = ascii_lowercase\ns = input()\nif len(s) < 26:\n x = z = s, y = b, d = 0\nelse:\n d = [p*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], s[-2::-1])])][0] - 2\n x, y, z = s[:d], s[d+1:], b[:ord(s[d]) - 97]\nprint(-(d < -26) or x + sorted(set(y) - set(z))[0])', 'from string import*\nfrom itertools import*\nb = ascii_lowercase\ns = input()\nif len(s) < 26:\n x = z = s, y = b, d = 0\nelse:\n d = [p*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], t[-2::-1])])][0] - 2\n x, y, z = s[:d], s[d+1:], b[:ord(s[d]) - 97]\nprint(-(d < -26) or x + sorted(set(y) - set(z))[0])', 'from string import*\nfrom itertools import*\nb = ascii_lowercase\ns = input()\nl = len(s)\nif l < 26:\n print(s + sorted(set(b) - set(s))[0])\nelse:\n d = [p,*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], t[-2::-1])])][0] - 2\n print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])', 'from string import*;from itertools import*;b=ascii_lowercase;r=s=input();d=l=len(s);t=s[::-1]\nif l>25:d=-[p*len(list(k))for p,k in groupby([i<j for i,j in zip(s[::-1],s[-2::-1])])][0]-2;s,b,o=s[:d],s[d+1:],1\nprint(-(d<-26)or s+sorted(set(b)-set([s,b[:ord(s[d])-97]][o]))[0])', 'from string import*\nfrom itertools import*\nb = ascii_lowercase\ns = input()\nif len(s) < 26:\n x = z = s, y = b, d = 0\nelse:\n d = -[p*len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], s[-2::-1])])][0] - 2\n x, y, z = s[:d], s[d+1:], b[:ord(s[d]) - 97]\nprint(-(d < -26) or x + sorted(set(y) - set(z))[0])', 'from string import*\nfrom itertools import*\nb = ascii_lowercase\ns = input()\nif len(s) < 26:\n print(s + sorted(set(b) - set(s))[0])\nelse:\n d = [p,len(list(k)) for p, k in groupby([i < j for i, j in zip(s[-1::-1], t[-2::-1])])][0] - 2\n print(-(d < -26) or s[:d] + sorted(set(s[d+1:]) - set(b[:ord(s[d]) - 97]))[0])', 'from string import*;from itertools import*;b=ascii_lowercase;s=r=input();t=s[::-1];d=0\nif len(s)>25:d=-[p*len(list(k))for p,k in groupby(i<j for i,j in zip(t,t[1:]))][0]-2;s,b,r=s[:d],s[d+1:],b[:ord((s*2)[d])-97]\nprint(-(d<-26)or s+sorted(set(b)-set(r))[0])'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s201592589', 's421863716', 's463499030', 's597613034', 's646900432', 's828164397', 's928401442', 's332835320'] | [3832.0, 3768.0, 3772.0, 2940.0, 3772.0, 3768.0, 2940.0, 3768.0] | [26.0, 25.0, 25.0, 17.0, 25.0, 25.0, 17.0, 25.0] | [274, 324, 324, 327, 274, 325, 320, 257] |
p03393 | u403301154 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nalphabet = ["abcdefghijklmnopqrstuvwxyz"]\nif s == str(alphabet[::-1]):\n print(-1)\nelse:\n if len(set(s))<26:\n for ele in alphabet:\n if ele not in s:\n print(s+ele)\n break\n else:\n suf=[s[-1]]\n for i in range(len(s)-1, 0, -1):\n if s[i]<s[i-1]:\n suf.append(s[i-1])\n else:\n last = i-1\n break\n suf.sort()\n for i in range(len(suf)):\n if s[last]<suf[i]:\n print(s[:last]+suf[i])\n break', 's = input()\nfrom string import ascii_lowercase\na = ascii_lowercase\nif s == a[::-1]:\n print(-1)\nelse:\n if len(set(s))<26:\n for ele in a:\n if ele not in s:\n print(s+ele)\n break\n else:\n suf=[s[-1]]\n for i in range(25, 0, -1):\n if s[i]<s[i-1]:\n suf.append(s[i-1])\n else:\n last = i-1\n break\n suf.sort()\n for i in range(len(suf)):\n if s[last]<suf[i]:\n print(s[:last]+suf[i])\n break'] | ['Runtime Error', 'Accepted'] | ['s762006383', 's219700973'] | [3064.0, 3892.0] | [17.0, 25.0] | [474, 462] |
p03393 | u404676457 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 sys\ns = input() + chr(96)\n\nif len(s) != 26:\n sets = set(s)\n for i in range(ord('a'), ord('z') + 1):\n if chr(i) not in sets:\n print(s[:j] + chr(i))\n sys.exit(0)\nj = 26\nfor j in range(26, 1, -1):\n if s[j - 1] > s[j]:\n continue\n sets = set(list(s[:j]))\n for i in range(ord(s[j]) + 1, ord('z') + 1):\n if chr(i) not in sets:\n print(s[:j] + chr(i))\n sys.exit(0)\nprint(-1)", "import sys\ns = input() + chr(96)\n\nfor j in range(len(s) - 1, -1, -1):\n sets = set(list(s[:j]))\n for i in range(ord(s[j]) + 1, ord('z') + 1):\n if chr(i) not in sets:\n print(s[:j] + chr(i))\n sys.exit(0)\nprint(-1)"] | ['Runtime Error', 'Accepted'] | ['s827501007', 's229148694'] | [3064.0, 3060.0] | [18.0, 18.0] | [452, 245] |
p03393 | u442877951 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nalp = "abcdefghijklmnopqrstuvwxyz"\ns = len(S)\nfor i in range(s):\n alp = alp.replace(S[i],\'\')\nif alp != \'\':\n print(S+alp[0])\nelse:\n if S == "zyxwvutsrqponmlkjihgfedcba":\n S = "-1"\n else:\n for j in range(s-1,0,-1):\n if S[j] > S[j-1]:\n alp = "abcdefghijklmnopqrstuvwxyz"\n for k in range(len(alp)-1):\n if alp[k] == S[j-1]:\n S = S[:j-1]+alp[k+1]\n print(S)\n exit()\nprint(S)', 'S = str(input())\nalp = "abcdefghijklmnopqrstuvwxyz"\ns = len(S)\nfor i in range(s):\n alp = alp.replace(S[i],\'\')\nif alp != \'\':\n print(S+alp[0])\n exit()\nelse:\n if S == "zyxwvutsrqponmlkjihgfedcba":\n S = "-1"\n else:\n for j in range(s-1,0,-1):\n if S[j] > S[j-1]:\n alp = list(S[j-1:])\n alp = sorted(alp)\n for k in range(len(alp)+1):\n if alp[k] == S[j-1]:\n S = S[:j-1]+alp[k+1]\n print(S)\n exit()\nprint(S)'] | ['Wrong Answer', 'Accepted'] | ['s208478103', 's388013578'] | [3064.0, 3064.0] | [17.0, 18.0] | [455, 475] |
p03393 | u454524105 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nans = list(s)\nalpha = [chr(i) for i in range(97, 97+26)]\nif len(s) == 26 and s == "".join(alpha): print(-1)\nelse:\n for i in range(len(s)):\n if alpha[i] == ans[i]:\n if i == len(s) - 1:\n ans.append(alpha[i+1])\n else: continue\n else:\n ans = alpha[:i]\n ans[-1] = alpha[i]\n break\n print("".join(ans))', '# coding: utf-8\n# Your code here!\n \nS=list(input())\n \n \nS=list(map(lambda x : ord(x)-97,S))\n \nalpha=[0]*26\nfor s in S:\n alpha[s]=1\n \nif len(S)!=26:\n for i in range(26):\n if alpha[i] == 0:\n S.append(i)\n ans=S[:]\n ans=list(map(lambda x :chr(x+97), ans))\n print("".join(ans))\n exit()\nelse:\n for i in range(26)[::-1]:\n if alpha[S[i]:].count(0)>0:\n for j in range(S[i],26):\n if alpha[j]==0:\n ans=S[:i]+[j]\n ans=list(map(lambda x :chr(x+97), ans))\n print("".join(ans))\n exit()\n else:\n alpha[S[i]]=0\n \nprint(-1)'] | ['Runtime Error', 'Accepted'] | ['s699936101', 's046465469'] | [3064.0, 3064.0] | [17.0, 18.0] | [397, 702] |
p03393 | u474423089 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nif len(S)<26:\n raise TypeError:\n print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])\nelse:\n tmp = [S[25]]\n for i in range(25):\n tmp.append(S[24-i])\n if S[24-i] < S[25-i]:\n print(S[:26-len(tmp)]+sorted(tmp)[1])\n exit()\n print(-1)', 'S=input()\nif len(S)<26:\n raise TypeError\n print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])\nelse:\n tmp = [S[25]]\n for i in range(25):\n tmp.append(S[24-i])\n if S[24-i] < S[25-i]:\n print(S[:26-len(tmp)]+sorted(tmp)[1])\n exit()\n print(-1)', 'S=input()\nif len(S)<26:\n print(S+sorted(list({chr(i+97) for i in range(26)}-set(S)))[0])\nelse:\n tmp = [S[25]]\n for i in range(25):\n tmp.append(S[24-i])\n if S[24-i] < S[25-i]:\n tmp =sorted(tmp)\n print(S[:26-len(tmp)]+tmp[tmp.index(S[24-i])+1])\n exit()\n print(-1)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s371609750', 's981784665', 's946747330'] | [2940.0, 3064.0, 3064.0] | [17.0, 17.0, 18.0] | [301, 300, 320] |
p03393 | u488884575 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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\nabc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\nfor a in abc:\n if a not in abc:\n print(s+a)\n exit()\nprint(-1)\n\n", "s = input()\n\nabc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\nif s == ''.join(abc)[::-1]:\n print(-1)\n exit()\nif len(s) <26:\n for a in abc:\n if a not in abc:\n print(s+a)\n exit()\ni = 25\nwhile s[i-1] > s[i]:\n i -= 1\n #print(s[i-1], s[i])\n#print(s[i-1], s[i])\ntt = s[i-1]\nss = list(s[i-1:])\nss.sort()\nprint(s[:i-1]+ss[ss.index(tt)+1])\n", "s = input()\n\nabc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\nprint(len(abc))\n\nfor a in abc:\n if a not in abc:\n print(s+a)\n exit()\nprint(-1)\n\n", "s = input()\n\nabc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\nif s == ''.join(abc)[::-1]:\n print(-1)\n exit()\nif len(s) != 26:\n for a in abc:\n if a not in abc:\n print(s+a)\n exit()\ni = 25\nwhile s[i-1] > s[i]:\n i -= 1\n #print(s[i-1], s[i])\n#print(s[i-1], s[i])\ntt = s[i-1]\nss = list(s[i-1:])\nss.sort()\nprint(s[:i-1]+ss[ss.index(tt)+1])\n", "s = input()\n\nabclist = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\nabcstr = ''.join(abclist)\nif s == abcstr[::-1]:\n print(-1)\n exit()\nif len(s) != 26:\n for a in abclist:\n if a not in s:\n print(s+a)\n exit()\n\nelse:\n i = 25\n while s[i-1] > s[i]:\n i -= 1\n #print(s[i-1], s[i])\n #print(s[i-1], s[i])\n tt = s[i-1]\n ss = list(s[i-1:])\n ss.sort()\n print(s[:i-1]+ss[ss.index(tt)+1])\n"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s317454631', 's542784516', 's574687463', 's835419502', 's500417775'] | [9044.0, 9096.0, 9116.0, 9084.0, 9096.0] | [29.0, 27.0, 27.0, 27.0, 28.0] | [206, 439, 223, 441, 509] |
p03393 | u502731482 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nif len(s) < 26:\n print(s + chr(ord(s[-1]) + 1))\nelse:\n i = len(s) - 1\n while i != 0 and s[i - 1] > s[i]:\n i -= 1\n if i == 0:\n print(-1)\n else:\n print(s[: i - 1] + chr(ord(s[i - 1]) + 1))\n', 's = input()\n\ndef set_char(data, c):\n for i in range(26):\n ret = chr(ord("a") + i)\n if ret not in data and ret > c:\n return ret\n\nif len(s) < 26:\n data = set(s)\n for i in range(26):\n c = set_char(data, "")\n print(s + c)\nelse:\n i = len(s) - 1\n while i != 0 and s[i - 1] > s[i]:\n i -= 1\n if i == 0:\n print(-1)\n else:\n data = set(s[: i - 1])\n c = set_char(data, s[i - 1])\n print(s[: i - 1] + c)\n'] | ['Wrong Answer', 'Accepted'] | ['s373565380', 's210009438'] | [2940.0, 3064.0] | [17.0, 17.0] | [235, 481] |
p03393 | u518064858 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nn=len(s)\ncha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nif n<26:\n for i in range(26):\n if s.count(cha[i])==0:\n print(s+cha[i])\nelse:\n for j in range(n-1,0,-1):\n if s[j]>s[j-1]:\n memo=j-1\n break\n if j==1:\n print(-1)\n exit()\n s2=s[:j]\n for i in range(26):\n if s2.count(cha[i])==0:\n memo2=cha[i]\n break\n print(s[:j-1]+memo2)\n', 's=input()\nn=len(s)\ncha=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nif n<26:\n for i in range(26):\n if s.count(cha[i])==0:\n print(s+cha[i])\n exit()\nelse:\n for j in range(n-1,0,-1):\n if s[j]>s[j-1]:\n memo=j-1\n break\n if j==1:\n print(-1)\n exit()\n s2=s[:j]\n for i in range(26):\n if s2.count(cha[i])==0 and cha[i]>s[memo]:\n memo2=cha[i]\n break\n print(s[:j-1]+memo2)\n'] | ['Wrong Answer', 'Accepted'] | ['s507823614', 's323540653'] | [3064.0, 3064.0] | [17.0, 18.0] | [515, 553] |
p03393 | u536034761 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['\nS = input()\nL = list(map(ord, S))\nif len(S) == 26:\n if S == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n pre = set()\n for i, l in enumerate(L[::-1]):\n if pre:\n if min(pre) > l:\n print(reversed(reversed(S)[i + 1 :]) + chr(min(pre)))\n break\n pre.add(l)\nelse:\n for _ in range(ord("a"), ord("z") + 1):\n if not (i in L):\n break\n print(S + chr(i))', 'S = input()\nif len(S) == 26:\n done = set()\n for i, s in enumerate(S[::-1]):\n s = ord(s)\n if done:\n if max(done) < s:\n done.add(s)\n if i == 25:\n print(-1)\n elif i != 25:\n l = 30\n for d in done:\n if l > abs(d - s) and s < d:\n x = d\n l = d - s\n print(S[: -(i + 1)] + chr(x))\n break\n else:\n print(chr(ord(S[0]) + 1))\n else:\n done.add(s)\nelse:\n for i in range(ord("a"), ord("z") + 1):\n if not (chr(i) in S):\n print(S + chr(i))\n break'] | ['Runtime Error', 'Accepted'] | ['s136180881', 's526482367'] | [8948.0, 9128.0] | [26.0, 30.0] | [472, 720] |
p03393 | u543954314 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['alp = "abcdefghijklmnopqrstuvwxyz"\ns = input()\nif len(s) < 26:\n for x in alp:\n if x not in s:\n print(s+x)\nelif s == alp[::-1]:\n print(-1)\nelse:\n for i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i] < s[j]:\n print(s[:i]+s[j])\n exit()', 'alp = "abcdefghijklmnopqrstuvwxyz"\ns = input()\nif len(s) < 26:\n for x in alp:\n if x not in s:\n print(s+x)\n break\nelif s == alp[::-1]:\n print(-1)\nelse:\n for i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i] < s[j]:\n print(s[:i]+s[j])\n exit()'] | ['Wrong Answer', 'Accepted'] | ['s088090423', 's122509067'] | [3064.0, 3064.0] | [17.0, 18.0] | [273, 285] |
p03393 | u557494880 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['N = int(input())\nans = []\nn = N//2\nif N == 3:\n ans = [2,3,63]\nelif 4 <= N <= 15000:\n for i in range(1,n):\n ans.append(2*i)\n x = 30000 - 2*i\n ans.append(x)\n if N % 2 == 1:\n ans.append(30000)\n ans.append(3)\n ans.append(9)\nelse:\n for i in range(1,15000):\n ans.append(2*i)\n x = N - 14999\n for j in range(x-1):\n y = 6*j + 3\n ans.append(y)\n if x % 2 == 1:\n ans.append(30000)\n else:\n ans.append(6*x - 3)\nprint(*ans)\n \n', 'S = input()\nL = [i for i in range(97,123)]\nn = len(S)\nfor i in range(n):\n L.remove(ord(S[i]))\nif n <= 25:\n X = L[0]\n ans = S + X\nelse:\n T = []\n x = S[-1]\n T.append(x)\n for i in range(2,27):\n y = S[-i]\n if y > x:\n x = y\n T.append(y)\n else:\n break\n m = 26 - len(T)\n if m != 0:\n ans = S[0]\n for i in range(1,m-1):\n ans += S[i]\n for t in T:\n if t > S[m-1]:\n ans += t\n break\n else:\n ans = -1\nprint(ans)', 'N = int(input())\nans = []\nn = N//2\nif N == 3:\n ans = [2,3,63]\nelif 4 <= N <= 15000:\n for i in range(1,n):\n ans.append(2*i)\n x = 30000 - 2*i\n ans.append(x)\n if N % 2 == 0:\n ans.append(30000)\n ans.append(3)\n ans.append(9)\nelse:\n for i in range(1,15000):\n ans.append(2*i)\n x = N - 14999\n for j in range(x):\n y = 6*x + 3\n if y <= 30000:\n ans.append(y)\n if N == 20000:\n ans.append(30000)\nprint(*ans)\n \n', 'S = input()\nL = [i for i in range(97,123)]\nn = len(S)\nfor i in range(n):\n L.remove(ord(S[i]))\nif n <= 25:\n X = L[0]\n ans = S + chr(X)d\nelse:\n T = []\n x = S[-1]\n T.append(x)\n for i in range(2,27):\n y = S[-i]\n if y > x:\n x = y\n T.append(y)\n else:\n break\n m = 26 - len(T)\n if m != 0:\n ans = S[0]\n for i in range(1,m-1):\n ans += S[i]\n for t in T:\n if t > S[m-1]:\n ans += t\n break\n else:\n ans = -1\nprint(ans)\n', 'S = input()\nL = [i for i in range(97,123)]\nn = len(S)\nfor i in range(n):\n L.remove(ord(S[i]))\nif n <= 25:\n X = L[0]\n ans = S + chr(X)\nelse:\n T = []\n x = S[-1]\n T.append(x)\n for i in range(2,27):\n y = S[-i]\n if y > x:\n x = y\n T.append(y)\n else:\n break\n m = 26 - len(T)\n if m != 0:\n ans = S[0]\n for i in range(1,m-1):\n ans += S[i]\n for t in T:\n if t > S[m-1]:\n ans += t\n break\n else:\n ans = -1\n print(ans)\n', "S = input()\nL = [i for i in range(97,123)]\nn = len(S)\nfor i in range(n):\n L.remove(ord(S[i]))\nif n <= 25:\n X = L[0]\n ans = S + ord(X)\nelse:\n A = []\n B = []\n p = 0\n d,e = -1,-1\n for i in range(n):\n j = ord(s[i])\n if ord(j) > p:\n d = i\n A.append(j)\n B = []\n else:\n if len(B) == 0:\n e = i\n B.append(j)\n A = []\n if d < e:\n if S[e-1] == 'z':\n if e == 1:\n ans = -1\n else:\n ans = S[0]\n for i in range(1,e-2):\n ans += S[i]\n ans += B[-1]\n else:\n ans = S[0]\n for i in range(1,n-2):\n ans += S[i]\n ans += S[n]\nprint(ans)", 'S = input()\nL = [i for i in range(97,123)]\nn = len(S)\nfor i in range(n):\n L.remove(ord(S[i]))\nif n <= 25:\n X = L[0]\n ans = S + chr(X)\nelse:\n T = []\n x = S[-1]\n T.append(x)\n for i in range(2,27):\n y = S[-i]\n if y > x:\n x = y\n T.append(y)\n else:\n break\n m = 26 - len(T)\n if m > 1:\n ans = S[0]\n for i in range(1,m-1):\n ans += S[i]\n for t in T:\n if t > S[m-1]:\n ans += t\n break\n elif m == 0:\n ans = -1\n else:\n for t in T:\n if t > S[m-1]:\n ans = t\n break\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s036814198', 's248157228', 's378267219', 's574483440', 's833794091', 's859557027', 's400779632'] | [3064.0, 3064.0, 3064.0, 2940.0, 3064.0, 3064.0, 3064.0] | [17.0, 17.0, 18.0, 17.0, 17.0, 18.0, 17.0] | [507, 561, 494, 568, 571, 780, 675] |
p03393 | u572144347 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nfrom collections import defaultdict \nif len(s)<26:\n d=defaultdict(int)\n for c in s:\n d[c]+=1\n for bb in b:\n if d[bb]==0:\n print(s+bb)\n exit() \nN=len(s)\nfor first in range(N-1,0,-1):\n mn=s[first]\n for i in range(first-1,-1, -1):\n if s[i]<mn:\n print(s[:i]+mn)\n exit()\nprint(-1)\n \n', 's=input()\nb="abcdefghijklmnopqrstuvwxyz"\nfrom collections import defaultdict \nif len(s)<26:\n d=defaultdict(int)\n for c in s:\n d[c]+=1\n for bb in b:\n if d[bb]==0:\n print(s+bb)\n exit() \nN=len(s)\nlst=[]\nfor first in range(N-1,0,-1):\n mn=s[first]\n for i in range(first-1,-1, -1):\n if s[i]<mn:\n lst.append(s[:i]+mn)\n #print(s[:i]+mn)\n #exit()\nif lst:\n print(sorted(lst)[0])\n exit()\nprint(-1)\n \n'] | ['Runtime Error', 'Accepted'] | ['s215100975', 's153608168'] | [3316.0, 3316.0] | [20.0, 23.0] | [325, 433] |
p03393 | u574050882 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 f(s, i, d):\n if len(s) == i:\n d.sort()\n return d[0]\n if len(d) == 0:\n return "_"\n d.remove(s[i])\n r = f(s, i+1, d)\n if r == "_":\n d.sort()\n for i in d:\n if s[i] < i:\n return i\n d.append(s[i])\n return "_"\n return "".join(s[i], r)\n\ndef main():\n d = list("abcdefghijklmnopqrstuvwxyz")\n t = input()\n r = f(t, 0, d)\n print(r)\n \nmain()', 'def f(s, i, d):\n if len(d) == 0:\n return "-1"\n if len(s) == i:\n d.sort()\n return d[0]\n d.remove(s[i])\n r = f(s, i+1, d)\n if r == "-1":\n d.sort()\n for j in d:\n if s[i] < j:\n return j\n d.append(s[i])\n return "-1"\n return "".join([s[i], r])\n\ndef main():\n d = list("abcdefghijklmnopqrstuvwxyz")\n t = input()\n r = f(t, 0, d)\n print(r)\n\nmain()\n'] | ['Runtime Error', 'Accepted'] | ['s110391736', 's405060562'] | [3080.0, 3064.0] | [19.0, 17.0] | [377, 381] |
p03393 | u593567568 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nL = len(S)\n\nif L != 26:\n \n USED = [False] * 26\n for s in S:\n USED[ord(s) - 97] = True\n \n for i in range(26)[::-1]:\n if not USED[i]:\n S.append(chr(97+i))\n break\n \n print("".join(S))\nelse:\n print("a")', 'S = list(input())\nL = len(S)\n\nif L != 26:\n \n USED = [False] * 26\n for s in S:\n USED[ord(s) - 97] = True\n \n for i in range(26):\n if not USED[i]:\n S.append(chr(97+i))\n break\n \n print("".join(S))\nelse:\n \n prev = -1\n k = -1\n USED = []\n for i in range(26)[::-1]:\n d = ord(S[i]) - 97\n if prev < d:\n prev = d\n USED.append(S[i])\n else:\n k = i\n break\n \n if k == -1:\n print(-1)\n else: \n nxt = min([s for s in USED if s > S[k]])\n S = S[:k] + [nxt]\n print("".join(S))\n'] | ['Wrong Answer', 'Accepted'] | ['s388435737', 's575910004'] | [9080.0, 9040.0] | [26.0, 28.0] | [311, 622] |
p03393 | u597455618 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nalphabet = "abcdefghijklmnopqrstuvwxyz"\nans = -1\nfor i in range(len(s)):\n t = s[:~i]\n dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)\n if dif:\n ans = t + min(dif)\n break\nprint(ans)', 's = input()+chr(ord("a")-1)\nans = -1\nfor i in range(len(s)):\n t = s[:~i]\n dif = set(map(chr,range(ord(s[~i])+1,123))) - set(t)\n if dif:\n ans = t + min(dif)\n break\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s795507408', 's851367316'] | [8920.0, 9120.0] | [30.0, 28.0] | [220, 196] |
p03393 | u616217092 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 functools\nimport math\nfrom itertools import combinations\nfrom sys import stdin\n\n\ndef main():\n N = int(stdin.readline().rstrip())\n ham = combinations(range(1, 30001), 100)\n for x in ham:\n if functools.reduce(math.gcd, x) == 1:\n for y in x:\n xx = list(x)\n xx.remove(y)\n if functools.reduce(math.gcd, [y, sum(xx)]) != 1:\n break\n else:\n print(' '.join([str(i) for i in x]))\n return\n\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin\nfrom string import ascii_lowercase\n\n\ndef main():\n word = stdin.readline().rstrip()\n if word == ascii_lowercase[::-1]:\n print(-1)\n return\n\n spam = sorted(list(set(ascii_lowercase) - set(word)))\n if 1 <= len(spam):\n print(word + spam[0])\n\n rword = word[::-1]\n tmp = []\n for x in rword:\n if len(tmp) != 0 and x < tmp[-1]:\n print(word[:-len(tmp) - 1] + tmp[0])\n break\n tmp.append(x)\n\n\nif __name__ == '__main__':\n main()\n", "from sys import stdin\nfrom string import ascii_lowercase\nfrom bisect import bisect_left\n\n\ndef main():\n word = stdin.readline().rstrip()\n if word == ascii_lowercase[::-1]:\n print(-1)\n return\n\n spam = sorted(list(set(ascii_lowercase) - set(word)))\n if 1 <= len(spam):\n print(word + spam[0])\n return\n\n rword = word[::-1]\n tmp = []\n for x in rword:\n if len(tmp) != 0 and x < sorted(tmp)[-1]:\n idx = bisect_left(tmp, x)\n print(word[:-len(tmp) - 1] + sorted(tmp)[idx])\n return\n tmp.append(x)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s094203955', 's810026159', 's563745668'] | [3828.0, 3832.0, 3960.0] | [113.0, 28.0, 37.0] | [557, 519, 622] |
p03393 | u629350026 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nt=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nif len(s)!=26:\n for i in range(26):\n if t[i] not in s:\n s.append(t[i])\n break\n print("".join(s))\nelse:\n if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n a=[]\n for i in range(26):\n a.append(s[25-i])\n for j in a:\n if s<s[:25-i]+j:\n print(s[:25-i]+j)\n exit()', 's=str(input())\nt=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]\nif len(s)!=26:\n s=list(s)\n for i in range(26):\n if t[i] not in s:\n s.append(t[i])\n break\n print("".join(s))\nelse:\n if "".join(s)=="zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n a=[]\n for i in range(26):\n a.append(s[25-i])\n for j in a:\n if s<s[:25-i]+j:\n print(s[:25-i]+j)\n exit()'] | ['Runtime Error', 'Accepted'] | ['s619006547', 's758607809'] | [9068.0, 9116.0] | [28.0, 30.0] | [454, 466] |
p03393 | u652656291 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\na = []\nb = ["a","b","c","d","e","f","g","h","i","j","k","l","m""n","o","p","q","r","s","t","u","v","w","x","y","z"]\nfor s in S:\n if s not in a:\n a.append(s)\na.sort()\nif len(a) == 0:\n print(-1)\nelse:\n for i in range(len(a)):\n if a[i] != b[i]:\n print(S+a[i])\n exit()\n ', "import sys\ninput = sys.stdin.readline\n\nS = input()\n\nalphabets = set(chr(ord('a')+x) for x in range(26))\n\ndef F(S,alphabets):\n if len(S) == 0:\n return -1\n T = F(S[1:],alphabets-set([S[0]]))\n if T == -1:\n larger = [x for x in alphabets if x > S[0]]\n if not larger:\n return -1\n return min(larger)\n return S[0] + T\n\nanswer = F(S,alphabets)\nprint(answer)\n"] | ['Wrong Answer', 'Accepted'] | ['s554488870', 's050678817'] | [9056.0, 9084.0] | [28.0, 29.0] | [306, 401] |
p03393 | u653807637 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['# encoding:utf-8\n \nimport fractions\n \ndef check(l):\n\tl = list(map(int, l.split()))\n \n\tif max(l) >= 30001:\n\t\treturn False\n\ttmp = l[0]\n \n\tfor i in range(len(l) - 1):\n\t\ttmp = fractions.gcd(tmp, l[i+1])\n\tif tmp != 1:\n\t\treturn False \n \n\tfor i in range(len(l)):\n\t\tif fractions.gcd(l[i], sum(l) - l[i]) == 1:\n\t\t\treturn False\n \n\treturn True\n \n \ndef main(n):\n\tif n == 3:\n\t\treturn "2 5 63"\n\tif n <= 5003:\n\t\tsub = [i * 3 for i in range(1, 10001) if i % 2 == 1]\n\t\tif n % 2 == 0:\n\t\t\ts = "2 4 " + " ".join([str(x) for x in sub[0:(n-2)]])\n\t\t\treturn(s)\n\t\telse:\n\t\t\ts = "2 4 6 " + " ".join([str(x) for x in sub[0:(n-3)]])\n\t\t\treturn(s)\n\telse:\n\t\tsub = [i * 3 for i in range(1, 10001) if i % 2 == 1]\n\t\tif n % 2 == 0:\n\t\t\ts = " ".join([str(i) for i in range(1, 30000) if i % 2 == 0 and i % 3 != 0][0:(n-5000)]) + " " + " ".join([str(x) for x in sub])\n\t\t\treturn(s)\n\t\telse:\n\t\t\ts = " ".join([str(i) for i in range(1, 30000) if i % 2 == 0 and i % 3 != 0][0:(n-5001)]) + " 6 " + " ".join([str(x) for x in sub])\n\t\t\treturn(s)\nif __name__ == \'__main__\':\n\tn = int(input())\n\tprint(main(n))\n\t\n\t', '# encoding:utf-8\n\n\ndef main(s):\n\talphabet = "abcdefghijklmnopqrstuvwxyz"\n\td = {alphabet[i]:i for i in range(26)}\n\tif s == "zyxwvutsrqponmlkjihgfedcba":\n\t\tprint("-1")\n\telif len(s) < 26:\n\t\tfor i in range(26):\n\t\t\tif alphabet[i] not in s:\n\t\t\t\tprint(s + alphabet[i])\n\t\t\t\tbreak\n\telse:\n\t\ttail = [d[s[25]]]\n\t\tfor i in range(0, 25):\n\t\t\tif d[s[24 - i]] >= max(tail):\n\t\t\t\ttail.append(d[s[24 - i]])\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\ttmp = min([x for x in tail if x >= d[s[24-i]]])\n\t\t\t\tprint(s[0:(24-i)] + alphabet[tmp])\n\t\t\t\tbreak\n\n\nif __name__ == \'__main__\':\n\t#s = input()\n\tmain("abc")\n\tmain("adc")\n\tmain("zyawvutsrqponmlkjihgfedcbx")\n\tmain("abcdefghijklmnopqrstuvwzyx")', '# encoding:utf-8\n\nimport fractions\n\ndef check(l):\n\tl = list(map(int, l.split()))\n\tprint(len(l), len([x for x in l if x % 2 == 0]), len([x for x in l if x % 2 == 1]))\n\tif max(l) >= 30001:\n\t\tprint("max >= 30001")\n\t\treturn False\n\n\tif len(set(l)) != len(l):\n\t\tprint("not unique")\n\t\treturn False\n\n\ttmp = l[0]\n\n\n\tfor i in range(len(l) - 1):\n\t\ttmp = fractions.gcd(tmp, l[i+1])\n\tif tmp != 1:\n\t\tprint("gcd is 1")\n\t\treturn False \n\n\tfor i in range(len(l)):\n\t\tif fractions.gcd(l[i], sum(l) - l[i]) == 1:\n\t\t\tprint("not special")\n\t\t\treturn False\n\n\treturn True\n\n\ndef main(n):\n\tif n == 3:\n\t\treturn "2 5 63"\n\n\tsub1 = [str(i * 3) for i in range(1, 10001) if i % 2 == 1]\n\tsub2 = [str(i) for i in range(1, 30000) if i % 2 == 0 and i % 3 != 0]\n\tsub3 = [str(i) for i in range(1, 30001) if i % 6 == 0]\n\tif n <= 5003:\n\t\tif n % 2 == 0:\n\t\t\ts = "2 4 " + " ".join([str(x) for x in sub1[0:(n-2)]])\n\t\t\treturn(s)\n\t\telse:\n\t\t\ts = "2 4 6 " + " ".join([str(x) for x in sub1[0:(n-3)]])\n\t\t\treturn(s)\n\telif n <= 15000:\n\t\tif n % 2 == 0:\n\t\t\ts = " ".join(sub2[0:(n-5000)]) + " " + " ".join(sub1)\n\t\t\treturn(s)\n\t\telse:\n\t\t\ts = " ".join(sub2[0:(n-5001)]) + " 6 " + " ".join(sub1)\n\t\t\treturn(s)\n\telse:\n\t\ts = " ".join(sub2) + " " + " ".join(sub1) + " " + " ".join(sub3[0:(n-15000)]) \n\t\treturn(s)\n\nif __name__ == \'__main__\':\n\tn = int(input())\n\t#print(check(main(n)))\n\t#print(main(20000))\n\tprint(main(n))\n\t#print(check("2 4 3 20001"))\n\t\n\t\n\t\n\t', '# encoding:utf-8\n\n\ndef main(s):\n\talphabet = "abcdefghijklmnopqrstuvwxyz"\n\td = {alphabet[i]:i for i in range(26)}\n\tif s == "zyxwvutsrqponmlkjihgfedcba":\n\t\tprint("-1")\n\telif len(s) < 26:\n\t\tfor i in range(26):\n\t\t\tif alphabet[i] not in s:\n\t\t\t\tprint(s + alphabet[i])\n\t\t\t\tbreak\n\telse:\n\t\ttail = [d[s[25]]]\n\t\tfor i in range(0, 25):\n\t\t\tif d[s[24 - i]] >= max(tail):\n\t\t\t\ttail.append(d[s[24 - i]])\n\t\t\t\tcontinue\n\t\t\telse:\n\t\t\t\ttmp = min([x for x in tail if x >= d[s[24-i]]])\n\t\t\t\tprint(s[0:(24-i)] + alphabet[tmp])\n\t\t\t\tbreak\n\n\nif __name__ == \'__main__\':\n\ts = input()\n\tmain(s)'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s851045170', 's897458224', 's943289951', 's573631610'] | [5688.0, 3064.0, 5588.0, 3064.0] | [84.0, 17.0, 46.0, 17.0] | [1117, 650, 1460, 560] |
p03393 | u677523557 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string\n\nS = input()\n\nabc = [chr(i) for i in range(97, 97+26)]\n\nif len(S) < 26:\n for s in S:\n abc.remove(s)\n add = abc[0]\n print('wahaha')\n print(S + add)\nelif S == ''.join(sorted(abc, reverse=True)):\n print(-1)\nelse:\n N = len(S)\n for i in range(1, N):\n now = S[N-i]\n fow = S[N-i+1:]\n fows = sorted(list(fow))\n for f in fows:\n if now < f:\n now = f\n break\n if now != S[N-i]:\n ans = S[:N-i] + now\n break\n print(ans)\n\n", "import string\n\nS = input()\n\nabc = [chr(i) for i in range(97, 97+26)]\n\nif len(S) < 26:\n for s in S:\n abc.remove(s)\n add = abc[0]\n print(S + add)\nelif S == ''.join(sorted(abc, reverse=True)):\n print(-1)\nelse:\n N = len(S)\n for i in range(1, N):\n now = S[N-i-1]\n fow = S[N-i:]\n fows = sorted(list(fow))\n for f in fows:\n if now < f:\n now = f\n break\n if now != S[N-i-1]:\n ans = S[:N-i-1] + now\n break\n print(ans)\n\n"] | ['Runtime Error', 'Accepted'] | ['s821540078', 's823086442'] | [3828.0, 3892.0] | [24.0, 26.0] | [550, 534] |
p03393 | u679325651 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 = [ord(i)-97 for i in str(input())]\nappeared = [False for i in range(26)]\nfor s in S:\n appeared[s] = True\nworst = False\nif len(S)<26:\n for i in range(len(appeared)):\n if appeared[i] == False:\n break\n S.append(i)\n \nelse:\n prev = -1\n for i in [25-k for k in range(26)]:\n if S[i] < prev:\n break\n prev = S[i]\n if i == 0:\n worst=True\n else:\n string = S[i+1:]\n for j in range(len(string)):\n if string[j] < S[i]:\n string[j] = 100\n S = S[:i]+[min(string)]\n ', 'S = [ord(i)-97 for i in str(input())]\nappeared = [False for i in range(26)]\n\nif len(S)<26:\n alp="".join([chr(i) for i in range(97,97+26)])\n s = "".join([chr(i+97) for i in S])\n for i in alp:\n if i not in s:\n print(s+i)\n exit()\n """\n for s in S:\n appeared[s] = True\n for i in range(len(appeared)):\n if appeared[i] == False:\n break\n S.append(i)\n print("".join([chr(i+97) for i in S]))\n exit()\n """\n \nelse:\n s = "".join([chr(i+97) for i in S])\n if s=="".join([chr(i) for i in range(97,97+26)][::-1]):\n print(-1)\n exit()\n \n prev = -1\n for i in [25-k for k in range(26)]:\n if S[i] < prev:\n break\n prev = S[i]\n for i in range(24,-1,-1):\n for j in range(25,i,-1):\n if S[i]<S[j]:\n S = S[:i]+[S[j]]\n print("".join([chr(i+97) for i in S]))\n exit()\n """\n string = S[i+1:]\n for j in range(len(string)):\n if string[j] < S[i]:\n string[j] = 100\n S = S[:i]+[min(string)]\n """\n'] | ['Wrong Answer', 'Accepted'] | ['s617168935', 's846912016'] | [3064.0, 3064.0] | [17.0, 18.0] | [575, 1096] |
p03393 | u688375653 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['alpha=list("abcdefghijklmnopqrstuvwxyz")\nalpha_dict={a:i for i,a in enumerate(alpha)}\nalpha = set(alpha)\n\nstring = input()\n\ncan_use_str = alpha - set(list(string))\n\nif string == "zyxwvutsrqponmlkjihgfedcba":\n print(1)\n\nelif len(can_use_str)==0:\n string_len=len(string)-1\n for i in range(1,string_len):\n if string[string_len-i] < string[string_len-i-1]:\n break\n can = sorted(list(string[string_len - i-1:]))[0]\n print(string[:string_len - i-2]+can)\n\nelse:\n\n print(string)', 'import copy\nalpha=list("abcdefghijklmnopqrstuvwxyz")\nalpha_dict={a:i for i,a in enumerate(alpha)}\nalpha = set(alpha)\n\nstring = input()\n\ncan_use_str = alpha - set(list(string))\n\nif string == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n\nelif len(can_use_str)==0:\n k = 0\n for i in reversed(range(25)):\n if string[i] < string[i + 1]:\n k = i\n break\n last = sorted(string[k:])\n for i in last:\n if string[k] < i:\n print(string[:k] + i)\n break\n\nelse:\n string+=sorted(list(can_use_str))[0]\n print(string)'] | ['Wrong Answer', 'Accepted'] | ['s263549645', 's697832900'] | [3064.0, 3444.0] | [17.0, 22.0] | [548, 571] |
p03393 | u750651325 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\nal = "abcdefghijklmnopqrstuvwxyz"\n\nimport string\ns = v()\n\nif s == \'zyxwvutsrqponmlkjihgfedcba\':\n print(-1)\n exit()\n\nlis =list(string.ascii_lowercase)\nnlis = [0]*26\n\nfor i in s:\n t = lis.index(i)\n nlis[t] += 1\n\nif sum(nlis) != 26:\n for i in range(26):\n if nlis[i] == 0:\n print(s+lis[i])\n break\nelse:\n for i in range(25, -1, -1):\n for j in lis:\n if s[i] < j and j not in s[:i]:\n print(s[:i] + j)\n exit()\nprint(lis)', 'import re\nimport sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\nimport functools\ndef v(): return input()\ndef k(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef X(): return list(input())\ndef L(): return list(input().split())\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nmod = 10**9+7\ncnt = 0\nans = 0\ninf = float("inf")\nal = "abcdefghijklmnopqrstuvwxyz"\n\nimport string\ns = v()\n\nif s == \'zyxwvutsrqponmlkjihgfedcba\':\n print(-1)\n exit()\n\nlis =list(string.ascii_lowercase)\nnlis = [0]*26\n\nfor i in s:\n t = lis.index(i)\n nlis[t] += 1\n\nif sum(nlis) != 26:\n for i in range(26):\n if nlis[i] == 0:\n print(s+lis[i])\n break\nelse:\n for i in range(25, -1, -1):\n for j in lis:\n if s[i] < j and j not in s[:i]:\n print(s[:i] + j)\n exit()\n'] | ['Wrong Answer', 'Accepted'] | ['s845656577', 's165485969'] | [10204.0, 10528.0] | [41.0, 40.0] | [1037, 1027] |
p03393 | u754022296 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nif len(s)<26:\n for i in al:\n if i not in s:\n print(s+i)\n break\nelse:\n if s == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n k = []\n for i in range(25, 0, -1):\n k.append(s[i])\n if s[i-1] < s[i]:\n for j in sorted(k):\n if j > s[i-1]:\n print(s[:i-1] + j)\n exit()', 'al = "abcdefghijklmnopqrstuvwxyz"\ns = input()\nif len(s)<26:\n for i in al:\n if i not in s:\n print(s+i)\n break\nelse:\n if s == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n else:\n k = []\n for i in range(25, 0, -1):\n k.append(s[i])\n if s[i-1] < s[i]:\n for j in sorted(k):\n if j > s[i-1]:\n print(s[:i-1] + j)\n exit()'] | ['Runtime Error', 'Accepted'] | ['s814282318', 's592395906'] | [3064.0, 3064.0] | [22.0, 17.0] | [346, 380] |
p03393 | u761989513 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\na = list("abcdefghijklmnopqrstuvwxyz")\nelif len(s) != 26:\n nokori = set(a) - set(s)\n nokori = sorted(nokori, key=a.index)\n print(s + nokori[0])\nelse:\n for i in range(2, 27):\n if s[-i] <= s[-i + 1]:\n break\n if i == 26:\n print(-1)\n else:\n s_ = sorted(s[-i + 1:])\n for j in s_:\n if j > s[-i]:\n break\n print(s[:-i] + j)', 's=input()\na=list("abcdefghijklmnopqrstuvwxyz")\nif len(s)!=26:nokori=sorted(set(a)-set(s),key=a.index);print(s+nokori[0])\nelse:\n for i in range(2,27):\n if s[-i]<s[-i+1]:\n break\n if i==26:\n print(-1)\n exit()\n t=sorted(s[-i+1:])\n for j in t:\n if j>s[-i]:break\n print(s[:-i]+j)'] | ['Runtime Error', 'Accepted'] | ['s788639160', 's962933763'] | [2940.0, 3064.0] | [17.0, 17.0] | [417, 283] |
p03393 | u785205215 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 math\nimport itertools\nfrom heapq import heapify, heappop, heappush\nfrom sys import stdin, stdout, setrecursionlimit\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import defaultdict, deque\n\n\n\n\n# inf = float("inf")\n\n\n\ndef LM(t, r): return list(map(t, r))\ndef R(): return stdin.readline()\ndef RS(): return R().split()\ndef I(): return int(R())\ndef F(): return float(R())\ndef LI(): return LM(int,RS())\ndef LF(): return LM(float,RS())\ndef ONE_SL(): return list(input())\ndef ONE_IL(): return LM(int, ONE_SL())\ndef ALL_IL(): return LM(int,stdin)\n\n##### tools #####\ndef ap(f): return f.append\ndef pll(li): print(\'\\n\'.join(LM(str,li)))\ndef pljoin(li, s): print(s.join(li))\n\n\n\n##### main #####\ndef main():\n\n\tS = R()\n\t\n\tif S == \'zyxwvutsrqponmlkjihgfedcba\':\n\t\tprint(-1)\n\t\texit()\n\n\tset_al = set([chr(i) for i in range(97,123)])\n\tset_s = set(S)\n\n\tif len(S) != len(set_s):\n\t\tprint("-1")\n\n\tavailables = sorted(list(set_al - set_s), reverse = True)\n\n\tif availables:\n\t\tprint(S+str(availables[-1]))\n\telse:\n\t\tf = False\n\t\tfor i in range(len(S))[::-1]:\n\t\t\tchr_n = ord(S[i])\n\n\t\t\twhile chr_n <= 122:\n\t\t\t\tif chr(chr_n) not in S:\n\t\t\t\t\tS += chr(chr_n)\n\t\t\t\t\tf = True\n\t\t\t\t\tbreak\n\t\t\t\tchr_n += 1\n\n\t\t\tif f:\n\t\t\t\tbreak\n\t\t\tS = S[:-1]\n\n\t\tprint(S)\n\n\nif __name__ == \'__main__\':\n main()', 'import math\nimport itertools\nfrom heapq import heapify, heappop, heappush\nfrom sys import stdin, stdout, setrecursionlimit\nfrom bisect import bisect, bisect_left, bisect_right\nfrom collections import defaultdict, deque\n\n\n\n\n# inf = float("inf")\n\n\n\ndef LM(t, r): return list(map(t, r))\ndef R(): return stdin.readline()\ndef RS(): return R().split()\ndef I(): return int(R())\ndef F(): return float(R())\ndef LI(): return LM(int,RS())\ndef LF(): return LM(float,RS())\ndef ONE_SL(): return list(input())\ndef ONE_IL(): return LM(int, ONE_SL())\ndef ALL_IL(): return LM(int,stdin)\n\n##### tools #####\ndef ap(f): return f.append\ndef pll(li): print(\'\\n\'.join(LM(str,li)))\ndef pljoin(li, s): print(s.join(li))\n\n\n\n##### main #####\ndef main():\n\n\tS = input()\n\t\n\tif S == \'zyxwvutsrqponmlkjihgfedcba\':\n\t\tprint(-1)\n\t\texit()\n\n\tset_al = set([chr(i) for i in range(97,123)])\n\tset_s = set(S)\n\n\tif len(S) != len(set_s):\n\t\tprint("-1")\n\n\tavailables = sorted(list(set_al - set_s), reverse = True)\n\n\tif availables:\n\t\tprint(S+str(availables[-1]))\n\telse:\n\t\tf = False\n\t\tfor i in range(len(S))[::-1]:\n\t\t\tchr_n = ord(S[i])\n\n\t\t\twhile chr_n <= 122:\n\t\t\t\tif chr(chr_n) not in S:\n\t\t\t\t\tS = S[:-1]\n\t\t\t\t\tS += chr(chr_n)\n\t\t\t\t\tf = True\n\t\t\t\t\tbreak\n\t\t\t\tchr_n += 1\n\n\t\t\tif f:\n\t\t\t\tbreak\n\t\t\tS = S[:-1]\n\n\t\tprint(S)\n\n\nif __name__ == \'__main__\':\n main()'] | ['Wrong Answer', 'Accepted'] | ['s364428521', 's656159665'] | [3316.0, 3572.0] | [22.0, 59.0] | [1349, 1369] |
p03393 | u813098295 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 string\n\nalp = string.ascii_lowercase\n\ndef main():\n s = input()\n if s == alp[::-1]:\n print(-1)\n return\n for i, ss in enumerate( s[::-1] ):\n if s[-(i)] > ss:\n print ( s[:(-i-1)] + s[-1] )\n break\n\nmain()\n\n', "import string\n\nalp = string.ascii_lowercase\n\ndef main():\n s = input()\n if len(s) < 26:\n for i in alp:\n if i not in s:\n print (s + i)\n return\n if s == alp[::-1]:\n print(-1)\n return\n L = len(s)\n tmp = []\n tt = ''\n for i, ss in enumerate( s ):\n tmp += [ s[L-i-1] ]\n if s[L-i-1] > s[L-i-2]:\n ans = s[:L-i-2]\n tt = s[L-i-2] \n break\n tmp.sort()\n for i in tmp:\n if i > tt:\n print (ans + i)\n break\nmain()\n\n"] | ['Wrong Answer', 'Accepted'] | ['s594493134', 's892774320'] | [3768.0, 3832.0] | [24.0, 24.0] | [261, 563] |
p03393 | u814986259 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['abc="abcdefghijklmnopqrstuvwxyz"\nimport collections\ntable=collections.defaultdict(int)\nfor i in range(26):\n table[abc[i]]=i\ntable2=collections.defaultdict(int)\ns=input()\nfor i in reversed(range(len(s)+1)):\n k=0\n if i < len(s):\n k=table[s[i]]\n for j in range(k+1,26):\n if abc[j] in s[:i]:\n continue\n else:\n print(s[:i]+abc[j])\n print(i,j)\n exit(0)\nprint(-1)', 'abc="abcdefghijklmnopqrstuvwxyz"\nimport collections\ntable=collections.defaultdict(int)\nfor i in range(26):\n table[abc[i]]=i\ntable2=collections.defaultdict(int)\ns=input()\nfor i in reversed(range(len(s)+1)):\n k=0\n if i < len(s):\n k=table[s[i]]+1\n for j in range(k,26):\n if abc[j] in s[:i]:\n continue\n else:\n print(s[:i]+abc[j])\n exit(0)\nprint(-1)'] | ['Wrong Answer', 'Accepted'] | ['s312464358', 's006878479'] | [3316.0, 3956.0] | [21.0, 51.0] | [389, 372] |
p03393 | u856232850 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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\nans = s\nansa = s\na = 'abcdefghijklmnopqrstuvwxyz'\na = [a[i] for i in range(26)]\nif len(s)<26:\n for i in a:\n if ans.count(i) == 0:\n ans += i\n break\nelse:\n b = 26\n for i in range(1,26):\n if a.index(s[i]) > a.index(s[i-1]):\n b = i\n if b == 26:\n print(-1)\n else:\n s = s[:b]\n for j in a:\n if a.index(j) > a.index(s[b-1]) and j not in s:\n s = s[:b-1]+j\n break\n print(s)\n", "s = input()\n\nans = s\nansa = s\na = 'abcdefghijklmnopqrstuvwxyz'\na = [a[i] for i in range(26)]\nif len(s)<26:\n for i in a:\n if ans.count(i) == 0:\n ans += i\n break\n print(ans)\nelse:\n b = 26\n for i in range(1,26):\n if a.index(s[i]) > a.index(s[i-1]):\n b = i\n if b == 26:\n print(-1)\n else:\n s = s[:b]\n for j in a:\n if a.index(j) > a.index(s[b-1]) and j not in s:\n s = s[:b-1]+j\n break\n print(s)\n"] | ['Wrong Answer', 'Accepted'] | ['s205154310', 's560782415'] | [3064.0, 3064.0] | [17.0, 17.0] | [508, 523] |
p03393 | u860002137 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 sys\nfrom collections import deque\nfrom collections import Counter\ns = deque(map(str, input().rstrip()))\n\nif "".join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n sys.exit()\n\ns = [ord(x) for x in s]\n\nif len(s) == 26:\n maxlen = True\n s = s[::-1]\n x = s[0]\n for i, w in enumerate(s):\n if x > w:\n break\n\n s = s[::-1]\n s = s[:-i - 1]\n\ncan_use = set(range(97, 123)) - set(s)\nif maxlen:\n s = s + [min(can_use) + 1]\nelse:\n s = s + [min(can_use)]\n\ns = [chr(x) for x in s]\n\nprint("".join(s))', 'import sys\nfrom collections import deque\nfrom collections import Counter\ns = deque(map(str, input().rstrip()))\n\nif "".join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n sys.exit()\n\ns = [ord(x) for x in s]\n\nif len(s) == 26:\n maxlen = True\n s = s[::-1]\n x = s[0]\n for i, w in enumerate(s):\n if x > w:\n break\n\n s = s[::-1]\n s = s[:-i - 1]\n\ncan_use = set(range(97, 123)) - set(s)\nif maxlen:\n can_use = can_use - {min(can_use)}\ns = s + [min(can_use)]\n\ns = [chr(x) for x in s]\n\nprint("".join(s))', 'import sys\ns = deque(map(str, input().rstrip()))\n\nif "".join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n sys.exit()\n\ns = [ord(x) for x in s]\n\nif len(s) < 26:\n can_use = set(range(97, 123)) - set(s)\n s = s + [min(can_use)]\n\nelse:\n add = []\n cnt = 0\n while s:\n cnt += 1\n q = s.pop()\n add.append(q)\n if q == 122:\n break\n add = [x for x in add if x > s[-1]]\n \n if cnt != 1:\n s[-1] = min(add)\n\ns = [chr(x) for x in s]\n\nprint("".join(s))', 'import sys\nfrom collections import deque\ns = deque(map(str, input().rstrip()))\n\n\nif "".join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n sys.exit()\n\n\ns = [ord(x) for x in s]\n\n\nif len(s) < 26:\n can_use = set(range(97, 123)) - set(s)\n s = s + [min(can_use)]\n\n\nelse:\n add = []\n s = s[::-1]\n prev = s[0]\n add.append(prev)\n\n \n if prev == 122:\n s[1] = 122\n s = s[::-1][:-1]\n\n \n \n else:\n for i in range(1, len(s)):\n if prev > s[i]:\n add = [x for x in add if x > s[i]]\n s[i] = (min(add))\n s = s[::-1][:-i]\n break\n prev = s[i]\n add.append(prev)\n\n\ns = [chr(x) for x in s]\n\nprint("".join(s))'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s145865621', 's374233049', 's931208898', 's849215848'] | [3316.0, 3316.0, 3192.0, 3316.0] | [21.0, 21.0, 17.0, 21.0] | [538, 536, 511, 1179] |
p03393 | u861141787 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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\nif len(s) > 26:\n a = [0 for _ in range(26)]\n\n for i in range(len(s)):\n a[ord(s[i]) - ord("a")] += 1\n\n ans = s\n for i in range(26):\n if a[i] == 0:\n ans += chr(i+ord("a"))\n break\n\n print(ans)\n exit()\n\n\nfor i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i]<s[j]:\n print(s[:i]+s[j])\n exit()\n\nprint(-1)', 's = input()\n\nif len(s) > 26:\n a = [0 for _ in range(26)]\n\n for i in range(len(s)):\n a[ord(s[i]) - ord("a")] += 1\n\n ans = s\n for i in range(26):\n if a[i] == 0:\n ans += chr(i+ord("a"))\n break\n\n print(ans) \n\n\nfor i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i]<s[j]:\n print(s[:i]+s[j])\n exit()\n\nprint(-1)', 's = input()\n\nif len(s) < 26:\n a = [0 for _ in range(26)]\n\n for i in range(len(s)):\n a[ord(s[i]) - ord("a")] += 1\n\n ans = s\n for i in range(26):\n if a[i] == 0:\n ans += chr(i+ord("a"))\n break\n\n print(ans)\n exit()\n\n\nfor i in range(24,-1,-1):\n for j in range(25,i,-1):\n if s[i]<s[j]:\n print(s[:i]+s[j])\n exit()\n\nprint(-1)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s358628447', 's953824544', 's216481181'] | [3064.0, 3064.0, 3064.0] | [18.0, 18.0, 17.0] | [403, 393, 403] |
p03393 | u867069435 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['j = input()\nlis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))\nabs = ""\nfor h in j:\n lis.remove(h)\nif not lis:\n ans = "-1"\nelse:\n ans = "{}{}".format(j, lis[0])\ntmp = "zz"\nfor i in range(len(j)-1, -1, -1):\n if j[i] != "z":\n\n if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):\n\n tmp = j[:i]+chr(ord(j[i])+1)\nif tmp == "zz" and ans == "-1":\n print("-1")\nelif tmp == "zz":\n print(ans)\nelse:\n print(tmp)', 'j = input()\nlis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))\nabs = ""\nfor h in j:\n lis.remove(h)\nif not lis:\n ans = "-1"\nelse:\n ans = "{}{}".format(j, lis[0])\ntmp = "zz"\nfor i in range(len(j)-1, -1, -1):\n if j[i] != "z":\n\n if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):\n print(j[:i] + chr(ord(j[i]) + 1))\n tmp = j[:i]+chr(ord(j[i])+1)\nprint(max(ans, tmp))', 'j = input()\nlis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))\nabs = ""\nfor h in j:\n lis.remove(h)\nif not lis:\n ans = "-1"\nelse:\n ans = "{}{}".format(j, lis[0])\ntmp = "zz"\nfor i in range(len(j)-1, -1, -1):\n if j[i] != "z":\n\n if tmp > j[:i]+chr(ord(j[i])+1) > j and len(j[:i]+chr(ord(j[i])+1)) == len(set(j[:i]+chr(ord(j[i])+1))):\n print(j[:i] + chr(ord(j[i]) + 1))\n tmp = j[:i]+chr(ord(j[i])+1)\nprint(min(ans, tmp))', 'j = input()\nlis = sorted(list("qwertyuiopasdfghjklzxcvbnm"))\nabs = ""\nfor h in j:\n lis.remove(h)\nif not lis:\n ans = "-1"\nelse:\n ans = "{}{}".format(j, lis[0])\ntmp = "zz"\nfor i in range(len(j)):\n try:\n if tmp > j[:i] + sorted(filter(lambda x: x > j[i], j[i+1:]))[0]:\n tmp = j[:i] + sorted(filter(lambda x: x > j[i], j[i+1:]))[0]\n except:\n pass\nif tmp == "zz" and ans == "-1":\n print("-1")\nelif tmp == "zz":\n print(ans)\nelif ans == "-1":\n print(tmp)\nelse:\n print(min(ans, tmp))'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s056205350', 's453307178', 's581053926', 's937638658'] | [3188.0, 3064.0, 3064.0, 3064.0] | [18.0, 18.0, 17.0, 18.0] | [490, 454, 454, 527] |
p03393 | u871841829 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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# 1 <= |S| <= 26\n# lowercase\n\nimport sys\nimport copy\n\ndef next_permutation(a):\n for i in reversed(range(len(a) - 1)):\n if a[i] < a[i + 1]:\n break\n else:\n return False\n\n j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])\n a[i], a[j] = a[j], a[i]\n a[i + 1:] = reversed(a[i + 1:])\n return True\n\nif len(S) == 26:\n sl = list(S)\n if next_permutation(sl):\n np = "".join(sl)\n for b in range(0, 26):\n if np[b] != S[b]:\n print(np[:b+1])\n exit()\n\n else:\n print(-1)\n exit()', 'S = input()\n\n# 1 <= |S| <= 26\n# lowercase\n\nimport sys\nimport copy\n\ndef next_permutation(a):\n for i in reversed(range(len(a) - 1)):\n if a[i] < a[i + 1]:\n break\n else:\n return False\n\n j = next(j for j in reversed(range(i + 1, len(a))) if a[i] < a[j])\n a[i], a[j] = a[j], a[i]\n a[i + 1:] = reversed(a[i + 1:])\n return True\n\nif len(S) == 26:\n sl = list(S)\n if next_permutation(sl):\n np = "".join(sl)\n for b in range(0, 26):\n if np[b] != S[b]:\n print(np[:b+1])\n exit()\n\n else:\n print(-1)\n exit()\nelse:\n hist = set(S)\n for c in range(0, 27):\n cand = chr(c+ord(\'a\'))\n if cand not in hist:\n print(S+cand)\n sys.exit()'] | ['Wrong Answer', 'Accepted'] | ['s823143151', 's652474454'] | [9252.0, 9216.0] | [31.0, 32.0] | [611, 771] |
p03393 | u905582793 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nn=len(s)\nls=[0]*26\n\nfor i in range(n):\n ls[ord(s[i])-97]=i+1\nif n<26:\n for i in range(26):\n if ls[i]==0:\n x=i\n break\n print(s+chr(x+97))\nelse:\n for i in range(24,-1,-1):\n if ls[i+1]>ls[i]:\n ', 'from bisect import bisect\ns=input()\nn=len(s)\nls=[0]*26\nif s == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\nif n<26:\n for i in range(n):\n ls[ord(s[i])-97]=i+1\n for i in range(26):\n if ls[i]==0:\n x=i\n break\n print(s+chr(x+97))\nelse:\n for i in range(n):\n ls[i] = ord(s[i])-97\n if ls[25]>ls[24]:\n print(s[:24]+s[25])\n else:\n tmp = []\n for i in range(24,-1,-1):\n tmp.append(ls[i+1])\n if ls[i+1]>ls[i]:\n tmps = sorted(tmp)\n x = bisect(tmps,ls[i])\n print(s[:i]+chr(tmps[x]+97))\n break'] | ['Runtime Error', 'Accepted'] | ['s169310954', 's049333970'] | [2940.0, 3064.0] | [17.0, 18.0] | [225, 556] |
p03393 | u919633157 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['# 2019/08/12\n\ns=input()\nif s==\'zyxwvutsrqponmlkjihgfedcba\':\n print(-1)\n exit()\n\nst=set(s)\n"""\nif len(s)<26:\n for i in range(97,97+26+1):\n if chr(i) in st:continue\n print(s+chr(i))\n exit()\n"""\ns=list(s)\nres=[s.pop()]\n\ndef solve(s):\n for _ in range(len(s)):\n tmp=s.pop()\n if tmp>res[-1]:\n res.append(tmp)\n res.sort()\n else: \n for e in res:\n if e<tmp:continue\n s.append(e)\n return s\n\nprint(\'\'.join(solve(s)))', "# 2019/08/12\n\ns=input()\nif s=='zyxwvutsrqponmlkjihgfedcba':\n print(-1)\n exit()\n\nst=set(s)\n\nif len(s)<26:\n for i in range(97,97+26+1):\n if chr(i) in st:continue\n print(s+chr(i))\n exit()\n\ns=list(s)\nres=[s.pop()]\n\ndef solve(s):\n for _ in range(len(s)):\n tmp=s.pop()\n if tmp>res[-1]:\n res.append(tmp)\n res.sort()\n else: \n for e in res:\n if e<tmp:continue\n s.append(e)\n return s\n\nprint(''.join(solve(s)))"] | ['Runtime Error', 'Accepted'] | ['s055604704', 's221247647'] | [3064.0, 3064.0] | [20.0, 18.0] | [548, 542] |
p03393 | u941753895 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n\n \n l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\n s=S()\n if s=='atcoder':\n exit()\n\n if s=='zyxwvutsrqponmlkjihgfedcba':\n return -1\n\n if len(s)!=26:\n for x in s:\n l.remove(x)\n return s+l[0]\n\n else:\n for i in range(1,len(s)):\n x=s[-i]\n for j in range(len(s)-i)[::-1]:\n if x>s[j]:\n return s[:j]+x\n\nprint(main())\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n\n \n l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\n s=S()\n if s=='atcoder':\n exit()\n\n if s=='zyxwvutsrqponmlkjihgfedcba':\n return -1\n\n if len(s)!=26:\n for x in s:\n l.remove(x)\n return s+l[0]\n\n else:\n x=s[-1]\n for i in range(len(s)-1)[::-1]:\n if x>s[i]:\n return s[:i]\n\nprint(main())\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n\n \n l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\n s=S()\n if s=='atcoder':\n exit()\n\n if s=='zyxwvutsrqponmlkjihgfedcba':\n return -1\n\n if len(s)!=26:\n for x in s:\n l.remove(x)\n return s+l[0]+l[0]\n\n else:\n x=s[-1]\n for i in range(len(s)-1)[::-1]:\n if x>s[i]:\n return s[:i]+x\n\nprint(main())\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n\n \n l=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\n s=S()\n if s=='atcoder':\n exit()\n\n if s=='zyxwvutsrqponmlkjihgfedcba':\n return -1\n\n if len(s)!=26:\n for x in s:\n l.remove(x)\n return s+l[0]\n\n else:\n x=s[-1]\n for i in range(len(s)-1)[::-1]:\n if x>s[i]:\n return s[:i]+x\n\nprint(main())\n", "import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\n\nl=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']\n\ndef main():\n s=S()\n if s=='zyxwvutsrqponmlkjihgfedcba':\n return -1\n\n for x in s:\n if l.count(x)==0:\n return -1\n l.remove(x)\n\n if len(l)>0:\n return ''.join(s)+l[0]\n\n nakama=[]\n for i in range(len(s))[::-1]:\n nakama.sort()\n b=s[i]\n for a in nakama:\n if a>b:\n return s[:i]+a\n nakama.append(b)\n\n# main()\nprint(main())\n"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s274186930', 's332418366', 's691410473', 's957384252', 's813979917'] | [5792.0, 6736.0, 6220.0, 5588.0, 6480.0] | [47.0, 61.0, 55.0, 50.0, 59.0] | [723, 683, 690, 685, 967] |
p03393 | u945418216 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ["ss = input()\nss =list(map(ord, ss))\nprint(ss)\ndic = [i for i in range(97,123)]\nfor s in ss:\n dic.remove(s)\nif len(ss)<26:\n ss.append(min(dic))\nelse:\n last = ss[-1]\n for s in ss[::-1]:\n if s < last:\n ss = ss[:ss.index(s)] + [last]\n break\n else:\n ss = -1\nif ss == -1:\n print(ss)\nelse:\n print(''.join(list(map(chr,ss))))", "ss = input()\nss =list(map(ord, ss))\ndic = [i for i in range(97,123)]\nprint(dic)\nfor s in ss:\n dic.remove(s)\nprint(dic)\nif len(ss)<26:\n ss.append(min(dic))\nelse:\n for s in ss[::-1]:\n if len(dic)>0 and s < max(dic):\n ss[ss.index(s)] = max(dic)\n break\n dic.append(ss.pop(ss.index(s)))\n else:\n ss = -1\nprint(ss if ss == -1 else ''.join(list(map(chr,ss))))", "import bisect\nss = input()\nss =list(map(ord, ss))\ndic = [i for i in range(97,123)]\n# print(dic)\nfor s in ss:\n dic.remove(s)\n# print(dic)\nif len(ss)<26:\n ss.append(min(dic))\nelse:\n for s in ss[::-1]:\n if len(dic)>0 and s < max(dic):\n ss[ss.index(s)] = dic[bisect.bisect_right(dic,s)]\n break\n dic.append(ss.pop(ss.index(s)))\n dic = sorted(dic)\n else:\n ss = -1\nprint(ss if ss == -1 else ''.join(list(map(chr,ss))))"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s939463796', 's985411008', 's252569916'] | [3064.0, 3064.0, 3064.0] | [18.0, 18.0, 17.0] | [374, 406, 473] |
p03393 | u948524308 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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()\nN=len(s)\nalpha="abcdefghijklmnopqrstuvwxyz"\na=[0]*26\nfor i in range(N):\n for j in range(26):\n if s[i]==alpha[j]:\n a[j]+=1\n break\n\nif s=="zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\nc=0\nlastidx=-1\nwhile True:\n\n\n for j in range(lastidx+1,26):\n if a[j]==0 :\n print(s[:c]+alpha[j])\n exit()\n lastidx=alpha.index(s[-1+c])\n a[lastidx] -= 1\n c-=1', 's=input()\nN=len(s)\nalpha="abcdefghijklmnopqrstuvwxyz"\na=[0]*26\nfor i in range(N):\n for j in range(26):\n if s[i]==alpha[j]:\n a[j]+=1\n break\n\nif s=="zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\nc=0\nlastidx=-1\nwhile True:\n for j in range(lastidx+1,26):\n if a[j]==0 :\n print(s[:N+c]+alpha[j])\n exit()\n lastidx=alpha.index(s[-1+c])\n a[lastidx] -= 1\n c-=1\n'] | ['Wrong Answer', 'Accepted'] | ['s163545670', 's126831483'] | [3064.0, 3064.0] | [17.0, 17.0] | [431, 432] |
p03393 | u962330718 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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())\nm=list('abcdefghijklmnopqrstuvwxyz')[::-1]\n\nif len(S)<26:\n for i in m[::-1]\n if i not in S:\n S.append(i)\n break\n print(''.join(S))\nelse:\n x=S[-1]\n for i in range(24,-1,-1):\n if x>S[i]:\n y=m.index(S[i])\n S=S[:i]\n for j in range(y-1,-1,-1):\n if m[j] not in S:\n S.append(m[j])\n break\n break\n else:\n x=S[i]\n \n if i==0:\n print(-1)\n exit()\n print(''.join(S))", "S=list(input())\nm=list('abcdefghijklmnopqrstuvwxyz')[::-1]\n\nif len(S)<26:\n for i in m[::-1]:\n if i not in S:\n S.append(i)\n break\n print(''.join(S))\nelse:\n x=S[-1]\n for i in range(25)[::-1]:\n if x>S[i]:\n y=m.index(S[i])\n S=S[:i]\n for j in range(y)[::-1]:\n if m[j] not in S:\n S.append(m[j])\n break\n break\n else:\n x=S[i]\n \n if i==0:\n print(-1)\n exit()\n print(''.join(S))"] | ['Runtime Error', 'Accepted'] | ['s075673094', 's446425020'] | [8912.0, 9132.0] | [21.0, 29.0] | [568, 569] |
p03393 | u977661421 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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}. | ['# -*- coding: utf-8 -*-\nimport copy\ns = list(input())\n\nif \'\'.join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\n\nif len(s) == 26:\n for i in range(26):\n if s[i] == \'z\':\n tmp = i\n break\n ans = s[:tmp]\n ans.append(min(s[tmp:]))\n print(\'\'.join(ans))\n exit()\n\n\nt = copy.deepcopy(s)\n#print(t)\n\nfor i in reversed(range(0, len(s))):\n #print(t[i])\n if t[i] != \'z\' and len(set(s)) < 26:\n j = 1\n while True:\n if not chr(ord(\'a\') + j) in s:\n t[i] = chr(ord(\'a\') + j)\n break\n else:\n j += 1\n break\nans1 = \'\'.join(t)\n\nfor i in range(26):\n if not chr(ord(\'a\') + i) in s:\n s.append(chr(ord(\'a\') + i))\n break\nans2 = \'\'.join(s)\nprint(min(ans1, ans2))\n', '# -*- coding: utf-8 -*-\nimport copy\ns = list(input())\n\nif \'\'.join(s) == "zyxwvutsrqponmlkjihgfedcba":\n print(-1)\n exit()\n\nif len(s) == 26:\n for i in reversed(range(0, 26)):\n #for j in range(1, ord(\'z\') - ord(s[i])):\n for j in range(ord(s[i]) + 1, ord(\'z\') + 1):\n if not chr(j) in s[:i]:\n s[i] = chr(j)\n print(\'\'.join(s[:i + 1]))\n exit()\n\nfor i in range(26):\n if not chr(ord(\'a\') + i) in s:\n s.append(chr(ord(\'a\') + i))\n break\nans2 = \'\'.join(s)\nprint(ans2)\n'] | ['Wrong Answer', 'Accepted'] | ['s195664724', 's475688773'] | [3700.0, 3444.0] | [29.0, 22.0] | [802, 552] |
p03393 | u994988729 | 2,000 | 262,144 | Gotou just received a dictionary. However, he doesn't recognize the language used in the dictionary. He did some analysis on the dictionary and realizes that the dictionary contains all possible **diverse** words in lexicographical order. A word is called **diverse** if and only if it is a nonempty string of English lowercase letters and all letters in the word are distinct. For example, `atcoder`, `zscoder` and `agc` are diverse words while `gotou` and `connect` aren't diverse words. Given a diverse word S, determine the next word that appears after S in the dictionary, i.e. the lexicographically smallest diverse word that is lexicographically larger than S, or determine that it doesn't exist. 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\nif len(c) < 26:\n for i in "abcdefghijklmnopqrstuvwxyz":\n if not i in s:\n ans = s + i\n break\n\nelse:\n tmp = ""\n ss = list(s)\n for i in range(len(ss)):\n if i == 0:\n tmp += ss.pop()\n continue\n\n if ss[-1] > tmp[-1]:\n tmp += ss.pop()\n else:\n ss.pop()\n ans = "".join(ss) + min(tmp)\n break\n else:\n ans = -1\n\nprint(ans)\n', 's = input()\nalp = "abcdefghijklmnopqrstuvwxyz"\n\nif len(s) < 26:\n for i in alp:\n if not i in s:\n ans = s + i\n break\n\nelse:\n tmp = []\n ss = list(s)\n for i in range(len(ss)):\n if i == 0:\n tmp.append(ss.pop())\n continue\n\n if alp.index(ss[-1]) > alp.index(tmp[-1]):\n tmp.append(ss.pop())\n continue\n else:\n remove = ss.pop()\n tmp.sort()\n for j in tmp:\n if j > remove:\n renew = j\n break\n ans = "".join(ss) + renew\n break\n else:\n ans = -1\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s761647958', 's397500371'] | [3060.0, 3064.0] | [17.0, 17.0] | [462, 667] |
p03395 | u729133443 | 2,000 | 262,144 | Aoki is playing with a sequence of numbers a_{1}, a_{2}, ..., a_{N}. Every second, he performs the following operation : * Choose a positive integer k. For each element of the sequence v, Aoki may choose to replace v with its remainder when divided by k, or do nothing with v. The cost of this operation is 2^{k} (regardless of how many elements he changes). Aoki wants to turn the sequence into b_{1}, b_{2}, ..., b_{N} (the order of the elements is important). Determine if it is possible for Aoki to perform this task and if yes, find the minimum cost required. | ['n,*a=map(int,open(0).read().split())\na,b=a[:n],a[n:]\nfor a,b in zip(a,b):\n if a==b:continue\n if b>a:\n print(-1)\n exit()\n if a-b<b:\n print(-1)\n exit()\n1/0', "from scipy.sparse.csgraph import floyd_warshall\nn,*a=map(int,open(0).read().split())\na,b=a[:n],a[n:]\nd=[]\nM=max(a)\nfor k in range(M-1,-1,-1):\n s=set(a)\n e=[[0]*(M+1)for _ in range(M+1)]\n for i in range(M+1):e[i][i]=1\n for i in d+list(range(k,0,-1)):\n t=s.copy()\n for x in s:\n e[x][x%i]=1\n t|={x%i}\n s=t\n c=floyd_warshall(e)\n for x,y in zip(a,b):\n if c[x,y]==float('inf'):\n d+=k+1,\n break\nprint(-(len(d)==M)or sum(2**k for k in d))"] | ['Runtime Error', 'Accepted'] | ['s457386562', 's708013373'] | [2940.0, 13852.0] | [18.0, 230.0] | [190, 520] |
p03403 | u077291787 | 2,000 | 262,144 | There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled. | ['# ARC093C - Traveling Plan\ndef main():\n N = int(input())\n A = list(map(int, input().rstrip().split()))\n for i in range(N):\n ans = 0\n cur = 0\n for j in range(N):\n if i == j:\n continue\n ans += max(cur, A[j]) - min(cur, A[j])\n cur = A[j]\n print(ans + abs(cur))\n\n\nif __name__ == "__main__":\n main()', '\n\ndef main():\n N = int(input())\n A = [0] + list(map(int, input().rstrip().split())) + [0]\n S = 0\n for i in range(1, N + 2):\n S += abs(A[i - 1] - A[i])\n\n for i in range(1, N + 1):\n ans = S + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]))\n print(ans)\n\n\nif __name__ == "__main__":\n main()'] | ['Wrong Answer', 'Accepted'] | ['s717743924', 's649675647'] | [14044.0, 14048.0] | [2104.0, 193.0] | [378, 397] |
p03403 | u094191970 | 2,000 | 262,144 | There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled. | ['n=int(input())\na=[0]+list(map(int,input().split()))+[0]\n\nsum=0\nfor i in range(n+1):\n sum+=abs(a[i+1]-a[i])\n\nfor i in range(1,n+1):\n sa=0\n if a[i+1]<a[i-1]<a[i]:\n sa=(a[i-1]-a[i+1])-(a[i]-a[i-1])-(a[i]-a[i+1])\n elif a[i]<a[i-1]<a[i+1]:\n sa=(a[i+1]-a[i-1])-(a[i-1]-a[i])-(a[i+1]-a[i])\n print(sum+sa)', 'n=int(input())\na=[0]+list(map(int,input().split()))+[0]\n\nsum_dist=0\nfor i in range(1,n+2):\n sum_dist+=abs(a[i]-a[i-1])\n\nfor i in range(1,n+1):\n t_dist=sum_dist\n t_dist-=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])\n t_dist+=abs(a[i+1]-a[i-1])\n print(t_dist)'] | ['Wrong Answer', 'Accepted'] | ['s898171437', 's766037237'] | [14048.0, 14048.0] | [216.0, 236.0] | [308, 250] |
p03403 | u131464432 | 2,000 | 262,144 | There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis. You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0. However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned. For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled. | ['N = int(input())\nA = list(map(int,input().split()))\nnow = 0\ndis = 0\nfor i in A:\n dis += abs(now-i)\n now = i\nans = dis+abs(now)\nB = [0]\nB.extend(A)\nB.append(0)\nprint(B)\nfor i in range(1,N+1):\n if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:\n print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))\n else:\n print(ans)', 'N = int(input())\nA = list(map(int,input().split()))\nnow = 0\ndis = 0\nfor i in A:\n dis += abs(now-i)\n now = i\nans = dis+abs(now)\nB = [0]\nB.extend(A)\nB.append(0)\nfor i in range(1,N+1):\n if B[i-1] < B[i] > B[i+1] or B[i-1] > B[i] < B[i+1]:\n print(ans - 2*min(abs(B[i-1]-B[i]),abs(B[i]-B[i+1])))\n else:\n print(ans)'] | ['Wrong Answer', 'Accepted'] | ['s812894949', 's489079862'] | [20424.0, 20444.0] | [172.0, 163.0] | [344, 335] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.