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 |
|---|---|---|---|---|---|---|---|---|---|---|
p02773 | u958053648 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N=int(input())\nS={i:input() for i in range(N)}\nvalue=[]\nmax=0\n\nfor i in S.values():\n\tN=list(S.values()).count(i)\n\tif N>max or N==max:\n\t\tmax=N\nfor j in S.values():\n\tM=list(S.values()).count(j)\n\tif N==M:\n\t\tvalue.append(j)\nvalue.sort()\n[print(i) for i in value]', "import sys\nfrom collections import Counter\nN = int(sys.stdin.readline())\nS = sys.stdin.read().split()\n \ncount = Counter(S)\nmax_num = max(count.values())\n\nmax_list = [i for i,j in count.items() if j==max_num]\n \nmax_list.sort()\nprint('\\n'.join(max_list))"] | ['Wrong Answer', 'Accepted'] | ['s133824552', 's379574916'] | [37856.0, 38476.0] | [2112.0, 326.0] | [258, 252] |
p02773 | u958207414 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['from collections import defaultdict\nfrom collections import OrderedDict\nn = int(input())\nanswer = dict()\nfor _ in range(n):\n z = str(input())\n if z in answer:\n ans[z]+=1\n else:\n answer.update({z:1})\ngroupedByValue = defaultdict(list)\nfor key, value in sorted(answer.items()):\n groupedByValue[value].append(key)\nM = groupedByValue[max(groupedByValue)]\nfor i in M:\n print(i)', 'from collections import defaultdict\nfrom collections import OrderedDict\nn = int(input())\nans = dict()\nfor _ in range(n):\n z = str(input())\n if z in answer:\n ans[z]+=1\n else:\n answer.update({z:1})\ngroupedByValue = defaultdict(list)\nfor key, value in sorted(answer.items()):\n groupedByValue[value].append(key)\nM = groupedByValue[max(groupedByValue)]\nfor i in M:\n print(i)', 'from collections import defaultdict\nfrom collections import OrderedDict\nn = int(input())\nanswer = dict()\nfor _ in range(n):\n z = str(input())\n if z in answer:\n answer[z]+=1\n else:\n answer.update({z:1})\ngroupedByValue = defaultdict(list)\nfor key, value in sorted(answer.items()):\n groupedByValue[value].append(key)\nM = groupedByValue[max(groupedByValue)]\nfor i in M:\n print(i)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s077670202', 's629468198', 's816249696'] | [45276.0, 3316.0, 45524.0] | [955.0, 21.0, 1138.0] | [401, 398, 404] |
p02773 | u958421405 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ["#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport collections\nimport sys\ninput = sys.stdin.readline\n\n\ndef main():\n n = int(input())\n s = list()\n for i in range(n):\n s.append(str(input()).replace('\\n', ''))\n\n c = dict(collections.Counter(s))\n max_count = max(c.values())\n for k, v in c.items():\n if v == max_count:\n print(k)\n\n\nif __name__ == '__main__':\n main()\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\nimport collections\nimport sys\ninput = sys.stdin.readline\n\n\ndef main():\n n = int(input())\n s = list()\n for i in range(n):\n s.append(str(input()).replace('\\n', ''))\n\n c = dict(collections.Counter(s))\n max_count = max(c.values())\n ans = list()\n for k, v in c.items():\n if v == max_count:\n ans.append(k)\n\n for i in sorted(ans):\n print(i)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s639394789', 's054874245'] | [41712.0, 41712.0] | [330.0, 616.0] | [411, 477] |
p02773 | u961945062 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\nl = []\n\nfor _ in range(N):\n s = str(input())\n l.append(s)\n\nimport collections\nc = collections.Counter(l)\n\nml = [kv for kv in c.items() if kv[1] == max(c.values())]\n\nfor _ in range(len(ml)):\n print(ml[_][0])', 'N = int(input())\nl = []\n\nfor _ in range(N):\n s = str(input())\n l.append(s)\n\nimport collections\nc = collections.Counter(l)\nc = c.most_common()\n\nmost_count = c[0][1]\nfor i in range(len(c)):\n if c[i][1] == most_count:\n print(c[i][0])', 'd = {}\nN = int(input())\n\nfor _ in range(N):\n s = str(input())\n if s in d.keys():\n d[s] += 1\n else:\n d[s] = 1\n\nans = []\n\nfor i in range(len(sd)):\n if sd[i][1] == max(d.values()):\n ans.append(sd[i][0])\n\nans = sorted(ans)\nfor _ in range(len(ans)):\n print(ans[_])', 'd = {}\nN = int(input())\n\nfor _ in range(N):\n s = str(input())\n if s in d.keys():\n d[s] += 1\n else:\n d[s] = 1\n\nsd = sorted(d.items())\n\nfor i in range(len(sd)):\n if sd[i][1] == max(d.values()):\n print(sd[i][0])\n else:\n exit()\n', 'N = int(input())\nl = []\n\nfor _ in range(N):\n s = str(input())\n l.append(s)\n\nimport collections\nc = collections.Counter(l)\nc = c.most_common()\nc.sort()\nmost_count = c[0][1]\nfor i in range(len(c)):\n if c[i][1] == most_count:\n print(c[i][0])', 'd = {}\nN = int(input())\n\nfor _ in range(N):\n s = str(input())\n if s in d.keys():\n d[s] += 1\n else:\n d[s] = 1\n\nans = []\n\nfor i in range(len(d)):\n if d[i][1] == max(d.values()):\n ans.append(d[i][0])\n\nans = sorted(ans)\n\nfor _ in range(len(ans)):\n print(ans[_])', 'N = int(input())\nl = []\n\nfor _ in range(N):\n s = str(input())\n l.append(s)\n\nimport collections\nc = collections.Counter(l)\nc = c.most_common()\n\nmost_count = c[0][1]\nc.sort()\n\nfor i in range(len(c)):\n if c[i][1] == most_count:\n print(c[i][0])'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s111378160', 's353539762', 's445761593', 's537170787', 's755466183', 's879559000', 's088639114'] | [35472.0, 45072.0, 32096.0, 42456.0, 45060.0, 32096.0, 45064.0] | [2105.0, 608.0, 445.0, 2105.0, 930.0, 445.0, 986.0] | [232, 246, 295, 267, 254, 293, 256] |
p02773 | u962330718 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N=int(input())\nS=[input() for i in range(N)]\nS=sorted(S)\ncnt=1\nmax_cnt=1\nans=[S[0]]\nfor i in range(N-1):\n if S[i]==S[i+1]:\n cnt+=1\n else:\n cnt=1\n if cnt==max_cnt:\n ans.append(S[i+1])\n if cnt>max_cnt:\n ans=[S[i+1]]\nans=sorted(ans)\nfor i in ans:\n print(i)', 'N=int(input())\nS=[input() for i in range(N)]\nS=sorted(S)\ncnt=1\nmax_cnt=1\nans=[S[0]]\nfor i in range(N-1):\n if S[i]==S[i+1]:\n cnt+=1\n else:\n cnt=1\n if cnt==max_cnt:\n ans.append(S[i+1])\n if cnt>max_cnt:\n max_cnt=cnt\n ans=[S[i+1]]\nans=sorted(ans)\nfor i in ans:\n print(i)'] | ['Wrong Answer', 'Accepted'] | ['s852277413', 's356292435'] | [21548.0, 21544.0] | [639.0, 625.0] | [296, 316] |
p02773 | u962423738 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['from collections import Counter\n\nn=int(input())\ns = [input() for _ in range(n)]\n\nc=[i for i in max(Counter(s))]\n\nfor j in c:\n\tprint(j)', 'from collections import Counter\n \nn=int(input())\ns = [input() for _ in range(n)]\n \nc=[i for i,j in Counter(s).items() if j == max(Counter(s).values())]\n \nfor k in c:\n\tprint(k)', 'N = int(input())\n\nd = {}\nfor _ in range(N):\n S = input()\n if S in d:\n d[S] += 1\n else:\n d[S] = 1\n \nm = max(d.values())\nfor s in sorted(k for k in d if d[k] == m):\n print(s)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s169604406', 's774102771', 's586514079'] | [38884.0, 54104.0, 35236.0] | [274.0, 2207.0, 460.0] | [134, 175, 205] |
p02773 | u966836999 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['#155\ndef main():\n N = int(input())\n S = [input() for i in range(N)]\n S.sort()\n ans = []\n max_len = 0\n streak = 1\n for i in range(len(S)-1):\n if(S[i]==S[i+1]):\n streak+=1\n else:\n if(streak>max_len):\n max_len = streak\n ans = [S[i]]\n elif(streak==max_len):\n ans.append(S[i])\n streak=1\n for a in ans:\n print(a)\nmain()', '#155\ndef main():\n N = int(input())\n S = [input() for i in range(N)]\n S.sort()\n ans = []\n max_len = 0\n streak = 1\n for i in range(N-1):\n if(S[i]==S[i+1]):\n streak+=1\n else:\n if(streak>max_len):\n max_len = streak\n ans = [S[i]]\n elif(streak==max_len):\n ans.append(S[i])\n streak=1\n if(N==1 or S[-2]!=S[-1]):\n ans.append(S[-1])\n for a in ans:\n print(a)\nmain()', '#155\ndef main():\n N = int(input())\n S = [input() for i in range(N)]\n S.sort()\n ans = []\n max_len = 0\n streak = 1\n for i in range(N-1):\n if(S[i]==S[i+1]):\n streak+=1\n if(i==N-2):\n if(streak>max_len):\n max_len = streak\n ans = [S[i]]\n elif(streak==max_len):\n ans.append(S[i])\n else:\n if(streak>max_len):\n max_len = streak\n ans = [S[i]]\n elif(streak==max_len):\n ans.append(S[i])\n streak=1\n if(N==1 or S[-2]!=S[-1]):\n ans.append(S[-1])\n for a in ans:\n print(a)\nmain()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s283435508', 's983387757', 's786671951'] | [20672.0, 20676.0, 20680.0] | [541.0, 595.0, 534.0] | [447, 498, 704] |
p02773 | u967822229 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\nA = {}\n\nMAX = 0\nfor i in range(N):\n s = input()\n A[s] = A.get(s,0) + 1\n MAX = max(MAX, A[s])\n\nfor k,v in A.items():\n if MAX == v:\n print(k)', 'N = int(input())\nA = {}\n\nMAX = 0\nfor i in range(N):\n s = input()\n A[s] = A.get(s,0) + 1\n MAX = max(MAX, A[s])\n\nB = sorted(A.items())\nprint(B)\nfor k, v in B:\n if v == MAX:\n print(k)', 'N = int(input())\nA = {}\n\nMAX = 0\nfor i in range(N):\n s = input()\n A[s] = A.get(s,0) + 1\n MAX = max(MAX, A[s])\n\nA = sorted(A.items())\nfor k,v in A.items():\n if MAX == v:\n print(k)', 'N = int(input())\nA = {}\n\nMAX = 0\nfor i in range(N):\n s = input()\n A[s] = A.get(s,0) + 1\n MAX = max(MAX, A[s])\n\nB = sorted(A.items())\nfor k, v in B:\n if v == MAX:\n print(k)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s487293141', 's492515020', 's927786446', 's534682999'] | [35408.0, 52560.0, 46760.0, 46784.0] | [399.0, 739.0, 554.0, 657.0] | [169, 199, 191, 190] |
p02773 | u968399909 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ["# -*- coding: utf-8 -*-\n\nimport os\nimport datetime\n\ndef main():\n\n str_dict = {}\n val_1 = int(input())\n for i in range(val_1):\n val_x = input()\n\n if not val_x in str_dict:\n str_dict[val_x] = 1\n else:\n num = str_dict.get(val_x)\n str_dict[val_x] = num + 1\n\n for k, v in sorted(str_dict.items(), key=lambda x: -x[1]):\n print(k)\n\n\n\n\nif __name__ == '__main__':\n main()", "# -*- coding: utf-8 -*-\n\nimport os\nimport datetime\n\ndef main():\n\n str_dict = {}\n val_1 = int(input())\n for i in range(val_1):\n val_x = input()\n\n if not val_x in str_dict:\n str_dict[val_x] = 1\n else:\n num = str_dict.get(val_x)\n str_dict[val_x] = num + 1\n\n max_count = max(str_dict.values())\n max_list = []\n\n for k, v in sorted(str_dict.items(), key=lambda x: -x[1]):\n if max_count == v:\n max_list.append(k)\n\n new_list = sorted(max_list)\n\n for key in new_list:\n print(key)\n\n\n\n\n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s975341943', 's016596518'] | [45264.0, 43476.0] | [513.0, 708.0] | [438, 616] |
p02773 | u969211566 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['from collections import Counter\n\nn = int(input())\ns = [input() for i in range(n)]\nnews = sorted(s)\nc = Counter(news)\nmax = c.most_common()[0][1]\nprint(c)\nfor i in range(n):\n if max == c.most_common()[i][1]:\n print(c.most_common()[i][0])\n else:\n break', 'import collections as co\n\nn = int(input())\ns = [input() for i in range(n)]\n\nc = co.Counter(s)\nmax = c.most_common()[0][1]\nr = 1\ni = 0\n\nwhile r == 1:\n if max == c.most_common()[i][1]:\n print(c.most_common()[i][0])\n else:\n r = 0\n i += 1\n', '\nfrom collections import Counter\n\nn = int(input())\ns = [input() for i in range(n)]\nc = Counter(s)\nC = c.most_common()\na = C[0][1]\nans = []\nfor i in range(len(c)):\n if C[i][1] == a:\n ans.append(C[i][0])\n\nans.sort()\nprint(*ans,sep="\\n")'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s367828675', 's575494039', 's638878284'] | [60272.0, 45044.0, 50192.0] | [2110.0, 2106.0, 708.0] | [258, 244, 238] |
p02773 | u969848070 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ["from collections import Counter\n\nN = int(input())\nS = [input() for x in range(N)]\nE = Counter(a)\nc = max(E.values())\ns = [s for s, g in b.items() if g == c]\ns.sort()\nprint('\\n'.join(s))", "from collections import Counter\n\nN = int(input())\nA = [input() for x in range(N)]\ncnt = Counter(A)\nmx = max(cnt.values())\nsorted(cnt.items())\nprint('\\n'.join(s for s, v in cnt.items() if v == mx))", "from collections import Counter\n \nN = int(input())\nS = [input() for x in range(N)]\nE = Counter(S)\nc = max(E.values())\ns = [s for s, g in b.items() if g == c]\ns.sort()\nprint('\\n'.join(s))", "from collections import Counter\n\nN = int(input())\nA = [input() for x in range(N)]\ncnt = Counter(A)\nmx = max(cnt.values())\ns = [s for s, v in cnt.items() if v == mx]\ns.sort()\nprint('\\n'.join(s))\n"] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s151371418', 's217732435', 's623591491', 's707258298'] | [17408.0, 47088.0, 35572.0, 35952.0] | [261.0, 729.0, 311.0, 498.0] | [185, 196, 186, 194] |
p02773 | u971096161 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\nS = []\n\nimport collections\n\nfor n in range(N):\n S.append(input())\n\nC = collections.Counter(S)\nC = C.most_common()\n\nc_max = C[0][1]\n\nfor i, c in enumerate(C):\n if c[1] == c_max:\n print(c[0])\n else:\n break\n ', 'N = int(input())\nS = []\n\nimport collections\n\nfor n in range(N):\n S.append(input())\n\nC = collections.Counter(S)\nC = C.most_common()\n\nc_max = C[0][1]\nans = []\nfor i, c in enumerate(C):\n if c[1] == c_max:\n ans.append(c[0])\n else:\n break\n\nans = sorted(ans)\nfor a in ans:\n print(a)'] | ['Wrong Answer', 'Accepted'] | ['s120434270', 's800570860'] | [45180.0, 45052.0] | [565.0, 748.0] | [231, 286] |
p02773 | u973055892 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['def main():\n num = int(input())\n\n tmp = [input() for i in range(num)]\n\n tmp2 = {}\n for t in tmp:\n if len(tmp2) == 0:\n tmp2[t] = 1\n else:\n if t in tmp2:\n tmp2[t] += 1\n else:\n tmp2[t] = 1\n\n tmp2 = sorted(tmp2.items(), key=lambda x:x[1])\n for t in sorted(tmp2):\n if tmp2[0][1] == t[1]:\n print(t[0])\n\nmain()', 'def main():\n num = int(input())\n\n tmp = [input() for i in range(num)]\n\n tmp2 = {}\n for t in tmp:\n if len(tmp2) == 0:\n tmp2[t] = 1\n else:\n if t in tmp2:\n tmp2[t] += 1\n else:\n tmp2[t] = 1\n\n _tmp2 = sorted(tmp2.items(), key=lambda x:x[1])\n tmp3 = sorted(tmp2.items())\n for t in tmp3:\n if _tmp2[-1][1] == t[1]:\n print(t[0])\n\nmain()'] | ['Wrong Answer', 'Accepted'] | ['s715205568', 's541019136'] | [44804.0, 60044.0] | [882.0, 999.0] | [352, 377] |
p02773 | u977141657 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['import collections\nn = input()\ns = [input() for _ in range(n)]\ns = collections.Counter(s)\nm = max(s.values())\n\na = []\nfor d in s.items():\n if d[1] == m:\n a.append(d[0])\nfor s in a:\n print(s)\n', "from collections import Counter\ndata = ['aaa', 'bbb', 'ccc', 'aaa', 'ddd']\ncounter = Counter(data)\nprint(counter.most_common()[0][0])", 'from collections import Counter\n\npass', 'import collections\nn = int(input())\ns = [input() for _ in range(n)]\ns = collections.Counter(s)\nm = max(s.values())\n\na = []\nfor d in s.items():\n if d[1] == m:\n a.append(d[0])\nfor s in a:\n print(s)', 'from collections import Counter\nn = input()\ns = [input() for _ in range(n)]\ns = Counter(s)\nm = max(s.values())\n\na = []\nfor d in s.items():\n if d[1] == m:\n a.append(d[0])\nfor s in a:\n print(s)', 'from collections import Counter\nn = int(input())\ns = [input() for _ in range(n)]\ns = Counter(s)\nm = max(s.values())\n\na = []\nfor d in s.items():\n if d[1] == m:\n a.append(d[0])\nfor s in sorted(a):\n print(s)'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s265455816', 's281048423', 's444658364', 's849633651', 's980385789', 's116189727'] | [3316.0, 3316.0, 3316.0, 35572.0, 3316.0, 35572.0] | [20.0, 20.0, 20.0, 505.0, 20.0, 623.0] | [204, 133, 37, 208, 204, 217] |
p02773 | u977642052 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['from collections import Counter\n\n\ndef main(n, s):\n c = Counter(s)\n max_count = c.most_common()[0][1]\n res = []\n for keys, count in c.most_common():\n if max_count == count:\n res.append(keys)\n\n print("\\n".join(sorted(res)))\n\n\nif __name__ == "__main__":\n n = int(input())\n s = [input() for _ in range(n)]\n', 'from collections import Counter\n\n\ndef main(n, s):\n c = Counter(s)\n max_count = c.most_common()[0][1]\n res = []\n for keys, count in c.most_common():\n if max_count == count:\n res.append(keys)\n else:\n print("\\n".join(sorted(res)))\n return\n\n\nif __name__ == "__main__":\n n = int(input())\n s = [input() for _ in range(n)]\n', 'from collections import Counter\n\n\ndef main(n, s):\n c = Counter(s)\n max_count = c.most_common()[0][1]\n res = []\n for keys, count in c.most_common():\n if max_count == count:\n res.append(keys)\n\n print("\\n".join(sorted(res)))\n\n\nif __name__ == "__main__":\n n = int(input())\n s = [input() for _ in range(n)]\n\n main(n, s)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s007653325', 's437337844', 's353934529'] | [17412.0, 17408.0, 45040.0] | [275.0, 264.0, 629.0] | [341, 381, 357] |
p02773 | u978178314 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\nd = {}\nfor _ in range(N):\n s = input()\n if not s in d:\n d[s] = 1\n else:\n d[s] += 1\nx = sorted(list(d.items()), key=lambda x:x[1], reverse=True)\nn = 0\nl = []\nfor k, v in x:\n if v >= n:\n n = v\n l.append(v)\nfor y in sorted(l):\n print(y)\n', 'N = int(input())\nd = {}\nfor _ in range(N):\n s = input()\n if not s in d:\n d[s] = 1\n else:\n d[s] += 1\nx = sorted(list(d.items()), key=lambda x:x[1], reverse=True)\nn = 0\nfor k, v in x:\n if v >= n:\n n = v\n print(k)', 'N = int(input())\nd = {}\nfor _ in range(N):\n s = input()\n if not s in d:\n d[s] = 1\n else:\n d[s] += 1\nx = sorted(list(d.items()), key=lambda x:x[1])\nn = 0\nfor k, v in x:\n if v >= n:\n n = v\n print(k)', 'N = int(input())\nd = {}\nfor _ in range(N):\n s = input()\n if not s in d:\n d[s] = 1\n else:\n d[s] += 1\nx = sorted(list(d.items()), key=lambda x:x[1], reverse=True)\nn = 0\nl = []\nfor k, v in x:\n if v >= n:\n n = v\n l.append(k)\nfor y in sorted(l):\n print(y)\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s872176169', 's901209310', 's932314210', 's714771199'] | [45912.0, 46556.0, 46556.0, 47452.0] | [607.0, 531.0, 621.0, 790.0] | [268, 226, 212, 268] |
p02773 | u978562876 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\n\nstrs = []\ndicts = {}\nfor i in range(N):\n s = input()\n if dicts.get(s) is not None:\n dicts[s] += 1\n else:\n dicts[s] = 1\n\ndict_sorted = sorted(dicts.items(), key=lambda x:x[1], reverse=True)\n\ni = 0\nsts = []\nfor s in dict_sorted:\n if dicts[s[0]] >= i:\n sts.append(s[0])\n i = dicts[s[0]]\n\nfor s in sorted(sts):\n print(s)', 'N = int(input())\n\nstrs = []\ndicts = {}\nfor i in range(N):\n s = input()\n if dicts.get(s) is not None:\n dicts[s] += 1\n else:\n dicts[s] = 1\n\ndict_sorted = sorted(dict.items(), key=lambda x:x[1])\n\ni = 0\nfor s in dict_sorted.key():\n if dicts[s] >= i:\n print(s)\n i = dicts[s]', 'N = int(input())\n\nstrs = []\ndicts = {}\nfor i in range(N):\n s = input()\n if dicts.get(s) is not None:\n dicts[s] += 1\n else:\n dicts[s] = 1\n\ndict_sorted = sorted(dicts.items(), key=lambda x:x[1], reverse=True)\n\ni = 0\nfor s in dict_sorted:\n if dicts[s[0]] >= i:\n print(s[0])\n i = dicts[s[0]]\n', 'N = int(input())\n\nstrs = []\ndicts = {}\nfor i in range(N):\n s = input()\n if dicts.get(s) is not None:\n dicts[s] += 1\n else:\n dicts[s] = 1\n\ndict_sorted = sorted(dicts.items(), key=lambda x:x[1], reverse=True)\n\ni = 0\nsts = []\nfor s in dict_sorted:\n if dicts[s[0]] == dicts[dict_sorted[0][0]]:\n sts.append(s[0])\n i = dicts[s[0]]\n\nfor s in sorted(sts):\n print(s)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s709910316', 's714769583', 's753896874', 's671322283'] | [47324.0, 32096.0, 45020.0, 47324.0] | [780.0, 377.0, 625.0, 789.0] | [373, 305, 324, 396] |
p02773 | u979444096 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['from collections import Counter\nn = int(input())\na = [input() for i in range(n)]\n\nc = Counter(a)\nd = c.most_common()\n\nfor i in c.items():\n if i[1] == d[0][1]:\n print(i[0])\n', "from collections import Counter\n\n\ndef main():\n N = int(input())\n A = [input() for _ in range(N)]\n\n c = Counter(A)\n max_num = c.most_common()[0][1]\n ANS = [i[0] for i in c.items() if i[1] == max_num]\n ANS.sort()\n for ans in ANS:\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s150054980', 's244766788'] | [46872.0, 45076.0] | [562.0, 662.0] | [178, 308] |
p02773 | u984276646 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['N = int(input())\nD = {}\nfor i in range(N):\n S = input()\n if S in D:\n D[S] += 1\n else:\n D[S] = 1\nM = max(D)\nL = []\nfor i in D:\n if D[i] == M:\n L.append(i)\nL.sort()\nfor i in range(len(L)):\n print(L[i])', 'N = int(input())\nD = {}\nfor i in range(N):\n S = input()\n if S in D:\n D[S] += 1\n else:\n D[S] = 1\nM = max(D[i] for i in D)\nL = []\nfor i in D:\n if D[i] == M:\n L.append(i)\nL.sort()\nfor i in range(len(L)):\n print(L[i])\n'] | ['Wrong Answer', 'Accepted'] | ['s807288599', 's473031746'] | [32096.0, 32096.0] | [382.0, 810.0] | [213, 228] |
p02773 | u991619971 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['import collections\nimport itertools\nN=int(input())\n#P=list(map(int,input().split()))\nst=[]\nfor i in range(N):\n s=str(input())\n st.append(s)\nc = collections.Counter(st)\n\nret = [letter for letter,count in c.most_common() if count == c.most_common()[0][1]]\n\nsorted(ret)\nfor r in ret:\n print(r)\n', 'import collections\nimport itertools\nN=int(input())\n#P=list(map(int,input().split()))\nst=[]\nfor i in range(N):\n s=str(input())\n st.append(s)\nc = collections.Counter(st)\ncount=c.most_common()\nmax=count[0][1]\nmin=count[-1][1]\nif max==min:\n st=list(set(st))\n st.sort()\n for k in st:\n print(k)\n exit()\nret=[]\nfor letter,cou in count:\n\n if cou == max:\n ret.append(letter)\n else:\n break\nret.sort()\nfor r in ret:\n print(r)\n'] | ['Wrong Answer', 'Accepted'] | ['s193763946', 's657363387'] | [59376.0, 58608.0] | [2106.0, 796.0] | [300, 467] |
p02773 | u995109095 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['n=int(input())\na=[]\nimport collections as cc\na=[input() for i in range(n)]\nf=cc.Counter(a)\nch=max(f.values())\nans=[]\nfor i in a:\n if f[i]==ch:\n ans.append(i)\nans.sort()\nfor i in set(ans):\n print(i)', 'n=int(input())\na=[]\nimport collections as cc\na=[input() for i in range(n)]\nf=cc.Counter(a)\nch=max(f.values())\nans=[]\nfor i in a:\n if f[i]==ch:\n ans.append(i)\nans=list(set(ans))\nans.sort()\nfor i in ans:\n print(i)\n'] | ['Wrong Answer', 'Accepted'] | ['s476793824', 's490355057'] | [47612.0, 45812.0] | [622.0, 676.0] | [211, 226] |
p02773 | u995419623 | 2,000 | 1,048,576 | We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it. Print all strings that are written on the most number of votes, in lexicographical order. | ['n=int(input())\narr=list(input() for _ in range(n)\ndic={}\n\nfor i in range(n):\n if arr[i] not in dic:\n dic[arr[i]]=1\n else:\n dic[arr[i]]+=1\n \nlargest=max(dic.values())\nans=[]\nfor keys in dic.keys():\n if dic[keys]==largest:\n ans.append(keys)\nans=sorted(ans)\n\nfor words in ans:\n print(words)', 'n=int(input())\narr=list(input() for _ in range(n))\ndic={}\n\nfor i in range(n):\n if arr[i] not in dic:\n dic[arr[i]]=1\n else:\n dic[arr[i]]+=1\n \nlargest=max(dic.values())\nans=[]\nfor keys in dic.keys():\n if dic[keys]==largest:\n ans.append(keys)\nans=sorted(ans)\n\nfor words in ans:\n print(words)'] | ['Runtime Error', 'Accepted'] | ['s245323617', 's200144422'] | [2940.0, 35232.0] | [17.0, 684.0] | [294, 305] |
p02774 | u054514819 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\nN, K = map(int, input().split())\nL = np.array(list(map(int, input().split())))\n\nL = np.sort(L)\npos = L[0<L]\nneg = L[0>L]\nzero = len(L[L==0])\n\ndef f(x):\n tmp = 0\n if x>=0:\n tmp += zero*N\n tmp += np.searchsorted(L, x//pos, side='right').sum()\n tmp += (N - np.searchsorted(L, x//neg, side='left')).sum()\n tmp -= np.count_nonzero(L*L<=x)\n return tmp//2\n\nl, r = -10**18, 10**18\nwhile l<r-1:\n m = (l+r)//2\n count = f(m)\n if count >= K:\n r = m\n else:\n l = m\n\nprint(r)", "import numpy as np\nN, K = map(int, input().split())\nL = np.array(list(map(int, input().split())))\n\nL = np.sort(L)\npos = L[0<L]\nneg = L[0>L]\nzero = len(L[L==0])\n\ndef f(x):\n tmp = 0\n if x>=0:\n tmp += zero*N\n tmp += np.searchsorted(L, x//pos, side='right').sum()\n tmp += (N - np.searchsorted(L, -(-x//neg), side='left')).sum()\n tmp -= np.count_nonzero(L*L<=x)\n return tmp//2\n\nl, r = -10**18, 10**18\nwhile l<r-1:\n m = (l+r)//2\n count = f(m)\n if count >= K:\n r = m\n else:\n l = m\n\nprint(r)"] | ['Wrong Answer', 'Accepted'] | ['s552540025', 's150520260'] | [32264.0, 32324.0] | [1106.0, 1109.0] | [498, 502] |
p02774 | u065040863 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\n\nN, K = map(int,input().split())\nA = np.array(list(map(int,input().split())))\nA.sort()\nposi = A[A > 0]\nzero = A[A = 0]\nnega = A[A < 0]\n\n\ndef check(x):\n count = 0 \n if x >= 0:\n count += len(zero) * N \n count += np.searchsorted(A, x // posi, side = 'right').sum() # posi * N\n count += np.searchsorted(A, (-x - 1) // nega, side = 'left').sum() \n count -= np.count_nonzero(A * A <= x) \n return count // 2 \n\n\nlow = -10 ** 18\nhigh = 10 ** 18\nwhile low + 1 < high:\n mid = (low + high) // 2\n if check(mid) >= K:\n low = mid\n else:\n high = mid\n\nprint(low)\n", "import numpy as np\n\nN, K = map(int,input().split())\nA = np.array(list(map(int,input().split())))\nA.sort()\nposi = A[A > 0]\nzero = A[A == 0]\nnega = A[A < 0]\n\n\ndef check(x):\n count = 0 \n if x >= 0:\n count += len(zero) * N \n count += np.searchsorted(A, x // posi, side = 'right').sum() # posi * N\n count += np.searchsorted(A, (-x - 1) // nega, side = 'left').sum() \n count -= np.count_nonzero(A * A <= x) \n return count // 2 \n\n\nlow = -10 ** 18\nhigh = 10 ** 18\nwhile low + 1 < high:\n mid = (low + high) // 2\n if check(mid) >= K:\n low = mid\n else:\n high = mid\n\nprint(low)\n", "import numpy as np\n\nN, K = map(int,input().split())\nA = np.array(list(map(int,input().split())))\nA.sort()\nposi = A[A > 0]\nzero = A[A == 0]\nnega = A[A < 0]\n\n\ndef check(x):\n count = 0 \n if x >= 0:\n count += len(zero) * N \n count += np.searchsorted(A, x // posi, side = 'right').sum() # posi * N\n count += np.searchsorted(A, (-x - 1) // (-nega), side = 'left').sum() \n count -= np.count_nonzero(A * A <= x) \n return count // 2 \n\n\nlow = -10 ** 18\nhigh = 10 ** 18\nwhile low + 1 < high:\n mid = (low + high) // 2\n if check(mid) < K: # OK\n low = mid\n else: # NG\n high = mid\n\nprint(high)\n", "import numpy as np\n\nN, K = map(int,input().split())\nA = np.array(list(map(int,input().split())))\nA.sort()\nposi = A[A > 0]\nzero = A[A == 0]\nnega = A[A < 0]\n\n\ndef check(x):\n count = 0 \n if x >= 0:\n count += len(zero) * N \n count += np.searchsorted(A, x // posi, side = 'right').sum() # posi * N\n count += np.searchsorted(A, (-x - 1) // (-nega), side = 'right').sum() \n count -= np.count_nonzero(A * A <= x) \n return count // 2 \n\n\nlow = -10 ** 18\nhigh = 10 ** 18\nwhile low + 1 < high:\n mid = (low + high) // 2\n if check(mid) < K: # OK\n low = mid\n else: # NG\n high = mid\n\nprint(high)\n", "import numpy as np\n\nN, K = map(int,input().split())\nA = np.array(list(map(int,input().split())))\nA.sort()\nposi = A[A > 0]\nzero = A[A == 0]\nnega = A[A < 0]\n\n\ndef check(x):\n count = 0 \n if x >= 0:\n count += len(zero) * N \n count += np.searchsorted(A, x // posi, side = 'right').sum() # posi * N\n count += (N - np.searchsorted(A, (-x - 1) // (-nega), side = 'right')).sum() \n count -= np.count_nonzero(A * A <= x) \n return count // 2 \n\n\nlow = -10 ** 18\nhigh = 10 ** 18\nwhile low + 1 < high:\n mid = (low + high) // 2\n if check(mid) < K: # OK\n low = mid\n else: # NG\n high = mid\n\nprint(high)\n"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s388378047', 's451971588', 's770960258', 's791663713', 's496209649'] | [3064.0, 32288.0, 32292.0, 32316.0, 32316.0] | [17.0, 936.0, 941.0, 939.0, 1104.0] | [740, 741, 775, 776, 782] |
p02774 | u079022693 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\ninput=sys.stdin.readline\nimport bisect\ndef main():\n N,K=map(int,input().split())\n A=list(map(int,input().split()))\n A.sort()\n print(A)\n\n left_target=-10**18\n right_target=10**18\n while left_target<right_target-1:\n mid_target=(left_target+right_target)//2\n count=0\n for i in range(N-1):\n a=A[i]\n if a<0:\n if mid_target/a!=mid_target//a:\n count+=(N-i-1)-bisect.bisect_right(A[i+1:],mid_target/a)\n else:\n count+=(N-i-1)-bisect.bisect_right(A[i+1:],mid_target//a)\n elif a==0:\n if mid_target>0:\n count+=(N-(i+1))\n elif a>0:\n if mid_target/a!=mid_target//a:\n count+=bisect.bisect_left(A[i+1:],mid_target/a)\n else:\n count+=bisect.bisect_left(A[i+1:],mid_target//a)\n if count<K:\n left_target=mid_target\n else:\n right_target=mid_target\n #print("m:",mid_target,"c:",count)\n print(left_target)\n\nif __name__=="__main__":\n main()', 'import sys\ninput=sys.stdin.readline\n"""\ndef binary_search_m(i,a,N,A,mid_target):\n left_index=-1\n right_index=N\n while left_index<right_index-1:\n mid_index=(left_index+right_index)//2\n if a*A[mid_index]>=mid_target:\n left_index=mid_index\n else:\n right_index=mid_index\n return N-(left_index+1)\n\ndef binary_search_p(i,a,N,A,mid_target):\n left_index=-1\n right_index=N\n while left_index<right_index-1:\n mid_index=(left_index+right_index)//2\n if a*A[mid_index]<mid_target:\n left_index=mid_index\n else:\n right_index=mid_index\n return left_index+1\n"""\ndef main():\n N,K=map(int,input().split())\n A=list(map(int,input().split()))\n A.sort()\n\n left_target=-10**18\n right_target=10**18+1\n while left_target<right_target-1:\n mid_target=(left_target+right_target)//2\n count=0\n for i in range(N):\n a=A[i]\n if a<0:\n left_index=-1\n right_index=N\n while left_index<right_index-1:\n mid_index=(left_index+right_index)//2\n if a*A[mid_index]>=mid_target:\n left_index=mid_index\n else:\n right_index=mid_index\n count+=N-(left_index+1)\n elif a>=0:\n left_index=-1\n right_index=N\n while left_index<right_index-1:\n mid_index=(left_index+right_index)//2\n if a*A[mid_index]<mid_target:\n left_index=mid_index\n else:\n right_index=mid_index\n count+=left_index+1\n\n if a*a<mid_target:\n count-=1\n count//=2\n if count<K:\n left_target=mid_target\n else:\n right_target=mid_target\n print(left_target)', 'from sys import stdin\nimport numpy as np\ndef main():\n \n readline=stdin.readline\n n,k=map(int,readline().split())\n a=np.array(readline().strip().split(),dtype="int64")\n \n a.sort()\n neg=a[a<0]\n neg_p=neg**2\n zero=a[a==0]\n pos=a[a>0]\n pos_p=pos**2\n l=-10**18-1\n r=10**18\n while l<r-1:\n x=(l+r)//2\n cnt=0\n if neg.size>0:\n cnt+=(a.size-np.searchsorted(a,(x+neg+1)//neg)).sum()\n cnt-=neg_p[neg_p<=x].size\n if zero.size>0:\n if x>=0:\n cnt+=(a.size-1)*zero.size\n if pos.size>0:\n cnt+=np.searchsorted(a,x//pos,side="right").sum()\n cnt-=pos_p[pos_p<=x].size\n\n cnt//=2\n if cnt>=k: r=x\n else: l=x\n\n print(r)\n\nif __name__=="__main__":\n main()'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s380875758', 's507721039', 's124609764'] | [23240.0, 3064.0, 34632.0] | [2108.0, 24.0, 1103.0] | [1132, 1937, 809] |
p02774 | u105302073 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['n, k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\nb = []\nfor i in range(n):\n for j in range(i + 1, n):\n print(a[i], a[j])\n b.append(a[i] * a[j])\nans = list(sorted(b))\nprint(ans[k])\n', 'import numpy as np\n\nn, k = [int(i) for i in input().split()]\na = np.array(sorted([int(i) for i in input().split()]))\nposi = a[a > 0]\nzero = a[a == 0]\nnega = a[a < 0]\n\n\nl = -10 ** 18 - 1\nr = 10 ** 18 + 1\nwhile r - l > 1:\n mid = (r + l) // 2\n cnt = 0\n if mid >= 0:\n cnt += len(zero) * n\n\n cnt += a.searchsorted(mid // posi, side="right").sum()\n cnt += (n - a.searchsorted(-(-mid // nega), side="left")).sum()\n cnt -= np.count_nonzero(a * a <= mid)\n cnt //= 2\n if cnt >= k:\n r = mid\n else:\n l = mid\nprint(r)\n'] | ['Runtime Error', 'Accepted'] | ['s179578762', 's387806912'] | [98144.0, 32272.0] | [2109.0, 1187.0] | [227, 604] |
p02774 | u113310313 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\na = np.array(a)\na.sort()\n\nnega = a[a<0]\nzero = a[a==0]\nposi = a[a>0]\n\nl = -10**18-1\nr = 10**18+1\nwhile r - l > 1:\n mid = (r+l)//2\n cnt = 0\n if mid >= 0:\n cnt += len(zero)*n\n cnt += a.searchsorted(mid//posi, side='right').sum()\n cnt += (n - a.searchsorted(mid//nega, side='left')).sum()\n cnt -= np.count_nonzero(a*a <= mid)\n cnt //=2\n if cnt >= k:\n r = mid\n else:\n l= mid\n\nprint(r)\n\n", "import numpy as np\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\na = np.array(a)\na.sort()\n\nnega = a[a<0]\nzero = a[a==0]\nposi = a[a>0]\n\nl = -10**18-1\nr = 10**18+1\nwhile r - l > 1:\n mid = (r+l)//2\n cnt = 0\n if mid >= 0:\n cnt += len(zero)*n\n cnt += a.searchsorted(mid//posi, side='right').sum()\n cnt += (n - a.searchsorted(-(-mid//nega), side='left')).sum()\n cnt -= np.count_nonzero(a*a <= mid)\n cnt //=2\n if cnt >= k:\n r = mid\n else:\n l= mid\n\nprint(r)\n\n"] | ['Wrong Answer', 'Accepted'] | ['s381345355', 's617681869'] | [47728.0, 47644.0] | [574.0, 568.0] | [505, 509] |
p02774 | u201928947 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\nn,k = map(int,input().split())\na = list(map(int,input().split()))\na = np.array(a)\na.sort()\np = a[a>0]\nz = a[a==0]\nm = a[a<0]\nlow = -10**18\nhigh = 10**18\nwhile high-low>1:\n mid = (high + low) //2\n count = 0\n if mid >= 0:\n count += len(z)*n\n count += a.searchsorted(mid//p,side = "right").sum()\n count += (n-a.searchsorted(-(-mid//m),side = "left")).sum()\n count -= np.count_nonzero(a*a <= mid)\n count /= 2\n print(count)\n if count >= k:\n high = mid\n if count < k:\n low = mid\nprint(high)\n', 'import numpy as np\nn,k = map(int,input().split())\na = list(map(int,input().split()))\na = np.array(a)\na.sort()\np = a[a>0]\nz = a[a==0]\nm = a[a<0]\nlow = -10**18\nhigh = 10**18\nwhile high-low>1:\n mid = (high + low) //2\n count = 0\n if mid >= 0:\n count += len(z)*n\n count += a.searchsorted(mid//p,side = "right").sum()\n count += (n-a.searchsorted(-(-mid//m),side = "left")).sum()\n count -= np.count_nonzero(a*a <= mid)\n count /= 2\n if count >= k:\n high = mid\n if count < k:\n low = mid\nprint(high)\n'] | ['Wrong Answer', 'Accepted'] | ['s547998236', 's477911217'] | [32300.0, 32300.0] | [1115.0, 1114.0] | [555, 538] |
p02774 | u239253654 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['N, K = map(int, input().split())\n\n\nA = list(map(int, input().split()))\n\n\nans = []\nfor x in range(len(A)):\n for y in range(x+1, len(A)):\n ans.append(A[x]*A[y])\nans.sort()\nprint(ans)\nprint(ans[K-1])\n\n\n', 'import numpy as np\nN, K = map(int, input().split())\n\nA = np.array(list(map(int, input().split())))\nA.sort()\n\npos = A[A > 0]\nneg = A[A < 0]\nzero = A[A == 0]\n\nl = -10**18\nr = 10**18\n\nwhile l + 1 < r:\n x = (l+r) // 2\n cnt = 0\n if x >= 0:\n cnt += N * len(zero)\n\n cnt += A.searchsorted(x//pos, side="right").sum()\n cnt += (N - A.searchsorted(-(-x//neg), side="left")).sum()\n cnt -= np.count_nonzero(A * A <= x)\n cnt //= 2\n\n if cnt >= K:\n r = x\n else:\n l = x\n\nprint(r)\n\n\n'] | ['Wrong Answer', 'Accepted'] | ['s810841384', 's755563851'] | [389132.0, 32304.0] | [2129.0, 1103.0] | [209, 513] |
p02774 | u263830634 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['from bisect import bisect_left, bisect_right\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nA.sort()\n\nn = bisect_left(A, 0)\np = bisect_right(A, 0)\n\nNegative = A[:n]\nPositive = A[p:]\n\nNumber_Negative = len(Negative) * len(Positive)\nNumber_Positive = len(Negative) * (len(Negative) - 1) // 2 + len(Positive) * (len(Positive) - 1) // 2\nNumber_Zero = N * (N - 1) // 2 - Number_Negative - Number_Positive\n\n# print (Number_Negative)\n# print (Negative)\n# print (Number_Positive)\n# print (Positive)\n\n\ndef Ncount(x): \n tmp = 0\n for a in Negative:\n tmp += len(Positive) - bisect_left(Positive, (x + a - 1) // a)\n # print (x, tmp)\n return tmp\n\ndef Pcount(x): \n tmp = 0\n for index, a in enumerate(Positive):\n tmp += bisect_right(Positive[index + 1:], x // a)\n for index, b in enumerate(Negative):\n tmp += len(Negative[index + 1:]) - bisect_left(Negative[index + 1:], (x + b - 1) // b)\n \n # print (x, tmp)\n return tmp\n\nif Number_Negative >= K:\n \n l = -10 ** 18\n r = 0\n while r - l > 1:\n mid = (l + r) // 2\n if K <= Ncount(mid):\n r = mid\n else:\n l = mid\n print (r)\n exit()\n \n\nelif Number_Negative < K <= Number_Negative + Number_Zero:\n print (0)\n exit()\n\nelse:\n \n l = 0\n r = 10 ** 18\n K -= (Number_Negative + Number_Zero)\n while r - l > 1:\n mid = (l + r) // 2\n if K <= Pcount(mid):\n r = mid\n else:\n l = mid\n print (r)\n # exit()\n\n\n\n\n', 'from subprocess import*\ncall(("pypy3","-c",))\n', "def main():\n import numpy as np\n from bisect import bisect_left, bisect_right\n\n N, K = map(int, input().split())\n A = list(map(int, input().split()))\n\n A.sort()\n\n n = bisect_left(A, 0)\n p = bisect_right(A, 0)\n\n Negative = np.array(A[:n], dtype = np.int64)\n Positive = np.array(A[p:], dtype = np.int64)\n\n Number_Negative = len(Negative) * len(Positive)\n Number_Positive = len(Negative) * (len(Negative) - 1) // 2 + len(Positive) * (len(Positive) - 1) // 2\n Number_Zero = N * (N - 1) // 2 - Number_Negative - Number_Positive\n\n # print (Number_Negative)\n # print (Negative)\n # print (Number_Positive)\n # print (Positive)\n \n\n def Ncount(x): \n tmp = 0\n for a in Negative:\n tmp += len(Positive) - bisect_left(Positive, (x + a + 1) // a)\n # print (x, tmp)\n return tmp\n\n def Ncount1(x):\n tmp = (len(Positive) - np.searchsorted(Positive, (-x - 1) // (-Negative), side = 'right')).sum() \n return tmp \n\n def Pcount(x): \n tmp = 0\n for index, a in enumerate(Positive):\n tmp += bisect_right(Positive[index + 1:], x // a)\n for index, b in enumerate(Negative):\n tmp += len(Negative[index + 1:]) - bisect_left(Negative[index + 1:], (x + b + 1) // b)\n \n # print (x, tmp)\n return tmp\n\n def Pcount1(x):\n tmp = 0\n tmp += np.searchsorted(Positive, x // Positive, side = 'right').sum()\n tmp += (len(Negative) - np.searchsorted(Negative, (-x - 1) // (-Negative), side = 'rigth')).sum()\n tmp -= np.count_nonzero(Positive * Positive <= x)\n tmp -= np.count_nonzero(Negative * Negative <= x)\n return tmp // 2\n\n if Number_Negative >= K:\n \n l = -10 ** 18\n r = 0\n while r - l > 1:\n mid = (l + r) // 2\n if K <= Ncount1(mid):\n r = mid\n else:\n l = mid\n print (r)\n exit()\n \n\n elif Number_Negative < K <= Number_Negative + Number_Zero:\n print (0)\n exit()\n\n else:\n \n l = 0\n r = 10 ** 18\n K -= (Number_Negative + Number_Zero)\n while r - l > 1:\n mid = (l + r) // 2\n if K <= Pcount1(mid):\n r = mid\n else:\n l = mid\n\n print (r)\n # exit()\n\n \n \n\nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s192860162', 's600813983', 's679710880'] | [23912.0, 95996.0, 32316.0] | [2104.0, 2115.0, 1136.0] | [1839, 2335, 2726] |
p02774 | u295294832 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\n\nN,K = [int(i) for i in input().split()]\nn = np.array([int(i) for i in input().split()])\nn=np.sort(n)\n\nmn = n[np.where(n<0)]\nmz = n[np.where(n==0)]\nmp = n[np.where(n>0)]\n\n#cn = len(mn)\n#cp = len(mp)\n\n#tcn = cn*cp\n\n\n# print(0)\n# exit(0)\n\nM = 10**18\nm = -1*M-1\npos = 0\n\nwhile M-m > 1:\n a = 0\n pos=(M+m)//2\n a+=np.searchsorted(n,pos//mp,side="right").sum()\n a+=cz*N\n a+=N*len(mn) - np.searchsorted(n,-(-pos//mn),side="left").sum()\n a-=np.count_nonzero(n*n <= pos)\n a=a//2\n if a >= K:\n M=pos\n else:\n m=pos\n#print(M,m)\nprint(M)\n', 'import numpy as np\n\nN,K = [int(i) for i in input().split()]\nn = np.array([int(i) for i in input().split()])\nn=np.sort(n)\n\nmn = n[np.where(n<0)]\nmz = n[np.where(n==0)]\nmp = n[np.where(n>0)]\n\nM = 10**18\nm = -1*M-1\npos = 0\n\nwhile M-m > 1:\n a = 0\n pos=(M+m)//2\n a+=np.searchsorted(n,pos//mp,side="right").sum()\n a+=cz*N\n a+=N*len(mn) - np.searchsorted(n,-(-pos//mn),side="left").sum()\n a-=np.count_nonzero(n*n <= pos)\n a=a//2\n if a >= K:\n M=pos\n else:\n m=pos\n#print(M,m)\nprint(M)\n', 'import numpy as np\n\nN,K = [int(i) for i in input().split()]\nn = np.array([int(i) for i in input().split()])\nn=np.sort(n)\n\nmn = n[np.where(n<0)]\nmz = len(n[np.where(n==0)])\nmp = n[np.where(n>0)]\nM = 10**18\nm = -1*M-1\npos = 0\n\nwhile M-m > 1:\n a = 0\n pos=(M+m)//2\n a+=np.searchsorted(n,pos//mp,side="right").sum()\n if pos >= 0: a+=mz*N\n a+=N*len(mn) - np.searchsorted(n,-(-pos//mn),side="left").sum()\n a-=np.count_nonzero(n*n <= pos)\n a=a//2\n if a >= K:\n M=pos\n else:\n m=pos\n \nprint(M)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s492539001', 's528085084', 's871535339'] | [32284.0, 32336.0, 32292.0] | [248.0, 246.0, 1112.0] | [652, 517, 531] |
p02774 | u297109012 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\n\n\ndef partsolve(A, x, positive, zero, negative):\n \n count = 0\n if x >= 0:\n count = len(zero) * len(A)\n P = x // positive\n Pc = np.searchsorted(A, P, side=\'right\')\n count += Pc.sum()\n\n N = (-x-1) // -negative\n Nc = np.searchsorted(A, N, side=\'right\')\n Nc = len(A) - Nc\n count += Nc.sum()\n\n count -= np.count_nonzero(A * A <= x)\n return count // 2\n\ndef solve(N, K, As):\n A = np.array(sorted(As), np.int64)\n positive = A[A > 0]\n zero = A[A == 0]\n negative = A[A < 0]\n\n left = -10 ** 18\n right = 10 ** 18\n while right - left > 1:\n mid = left + (right - left) // 2\n c = partsolve(A, mid, positive, zero, negative)\n print(mid, c)\n if c < K:\n left = mid\n else:\n right = mid\n return right\n\n\nif __name__ == "__main__":\n N, K = tuple(map(int, input().split(" ")))\n As = list(map(int, input().split(" ")))\n print(solve(N, K, As))\n\n', 'import numpy as np\n\n\ndef partsolve(A, x, positive, zero, negative):\n \n count = 0\n if x >= 0:\n count = len(zero) * len(A)\n P = x // positive\n Pc = np.searchsorted(A, P, side=\'right\')\n count += Pc.sum()\n\n N = (-x-1) // -negative\n Nc = np.searchsorted(A, N, side=\'right\')\n Nc = len(A) - Nc\n count += Nc.sum()\n\n count -= np.count_nonzero(A * A <= x)\n return count // 2\n\ndef solve(N, K, As):\n A = np.array(sorted(As), np.int64)\n positive = A[A > 0]\n zero = A[A == 0]\n negative = A[A < 0]\n\n left = -10 ** 18\n right = 10 ** 18\n while right - left > 1:\n mid = left + (right - left) // 2\n c = partsolve(A, mid, positive, zero, negative)\n if c < K:\n left = mid\n else:\n right = mid\n return right\n\n\nif __name__ == "__main__":\n N, K = tuple(map(int, input().split(" ")))\n As = list(map(int, input().split(" ")))\n print(solve(N, K, As))\n\n'] | ['Wrong Answer', 'Accepted'] | ['s331897093', 's098644101'] | [32328.0, 32300.0] | [1283.0, 1246.0] | [1084, 1062] |
p02774 | u371409687 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\nn,k = map(int,input().split())\na = np.array(list(map(int,input().split())))\na.sort()\nposi = a[a>0]\nzero = a[a==0]\nnega = a[a<0]\n\ndef cnt(x):\n c = 0\n if x >= 0:\n c += len(zero)*n\n c += np.searchsorted(a, x // posi, side = 'right').sum()\n c += n-np.searchsorted(a, (- x - 1) // (-nega), side = 'right').sum()\n c -= np.count_nonzero(a * a <= x)\n return c // 2\n\nl = - 10 ** 18\nr = 10 ** 18\nwhile l + 1 < r:\n m = (l + r) // 2\n if cnt(m) < k:\n l = m\n else:\n r = m\nprint(r)", "import numpy as np\nn,k = map(int,input().split())\na = np.array(list(map(int,input().split())))\na.sort()\nposi = a[a>0]\nzero = a[a==0]\nnega = a[a<0]\n\ndef cnt(x):\n c = 0\n if x >= 0:\n c += len(zero)*n\n c += np.searchsorted(a, x // posi, side = 'right').sum()\n c += (n-np.searchsorted(a, (- x - 1) // (-nega), side = 'right')).sum()\n c -= np.count_nonzero(a * a <= x)\n return c // 2\n\nl = - 10 ** 18\nr = 10 ** 18\nwhile l + 1 < r:\n m = (l + r) // 2\n if cnt(m) < k:\n l = m\n else:\n r = m\nprint(r)"] | ['Wrong Answer', 'Accepted'] | ['s243208498', 's339697188'] | [32300.0, 32300.0] | [1111.0, 1103.0] | [533, 535] |
p02774 | u392319141 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['print(0)', 'import numpy as np\n\nN, K = map(int, input().split())\nA = np.array(tuple(map(int, input().split())), dtype=np.int64)\n\nA = np.sort(A)\npos = A[A > 0]\nneg = A[A < 0]\nzero = len(A[A == 0])\n\ndef cnt(x):\n """return #{a <= x | a in A}"""\n ret = 0\n\n if x >= 0:\n ret += zero * N\n\n ret += np.searchsorted(A, x // pos, side=\'right\').sum()\n ret += (N - np.searchsorted(A, (-x - 1) // (-neg), side=\'right\')).sum()\n ret -= ((A * A) <= x).sum()\n return ret // 2\n\noverEq = 10**18 + 100\nless = -10**18 - 100\n\nwhile less + 1 < overEq:\n mid = (overEq + less) // 2\n if cnt(mid) >= K:\n overEq = mid\n else:\n less = mid\n\nprint(overEq)\n'] | ['Wrong Answer', 'Accepted'] | ['s506346981', 's851666299'] | [2940.0, 32460.0] | [17.0, 1112.0] | [8, 662] |
p02774 | u469254913 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\n# import math\n# import copy\n# from collections import deque\nimport sys\ninput = sys.stdin.readline\n\n\n\ndef cnt(x,A,An,Ap,N,Nz):\n res = 0\n if x >= 0:\n res += N * Nz\n res += np.searchsorted(A,x//Ap,side='right').sum()\n res += N * len(An) - np.searchsorted(A,-(-x//An),side='left').sum()\n res -= np.count_nonzero(A*A<=x)\n return res//2\n\n\ndef main():\n N,K = map(int,input().split())\n A = list(map(int,input().split()))\n\n print(len(A))\n\n A = np.array(A)\n A.sort()\n\n An = A[A<0]\n Az = A[A==0]\n Ap = A[A>0]\n\n Nz = np.count_nonzero(A==0)\n\n INF = 10 ** 18\n\n l = - INF - 1\n r = INF\n\n while r-l > 1:\n m = (l+r)//2\n if cnt(m,A,An,Ap,N,Nz) >= K:\n r = m\n else:\n l = m\n\n print(r)\n\n\n\n\n\nmain()\n", "import numpy as np\n# import math\n# import copy\n# from collections import deque\nimport sys\ninput = sys.stdin.readline\n\n\n\ndef cnt(x,A,An,Ap,N,Nz):\n res = 0\n if x >= 0:\n res += N * Nz\n res += np.searchsorted(A,x//Ap,side='right').sum()\n res += N * len(An) - np.searchsorted(A,-(-x//An),side='left').sum()\n res -= np.count_nonzero(A*A<=x)\n return res//2\n\n\ndef main():\n N,K = map(int,input().split())\n A = list(map(int,input().split()))\n\n A = np.array(A)\n A.sort()\n\n An = A[A<0]\n Az = A[A==0]\n Ap = A[A>0]\n\n Nz = np.count_nonzero(A==0)\n\n INF = 10 ** 18\n\n l = - INF - 1\n r = INF\n\n while r-l > 1:\n m = (l+r)//2\n if cnt(m,A,An,Ap,N,Nz) >= K:\n r = m\n else:\n l = m\n\n print(r)\n\n\n\n\n\nmain()\n"] | ['Wrong Answer', 'Accepted'] | ['s626386308', 's782865320'] | [32296.0, 32288.0] | [1103.0, 1115.0] | [834, 815] |
p02774 | u524255742 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\nstdin = open(0)\n\nN,K = map(int,input().split())\nA = np.array(stdin.read().split(), np.int64)\nA = np.sort(A)\n\nmaxA = max(np.abs(A))\n\n\nz = A[A==0]\np = A[A>0]\nn = A[A<0]\n\n\ndef check(x):\n ret = 0\n if x >= 0:\n ret += N*len(z)\n ret += np.searchsorted(A,x//p,side='right').sum()\n ret += (N-np.searchsorted(A,x/n)).sum()\n ret -= len([a for a in A if a*a <= x])\n return ret//2;\n \n\nub = maxA*maxA\nlb = -ub-1\nwhile ub-lb > 1:\n mid = (ub+lb)>>1\n if check(mid) < K:\n lb = mid\n else:\n ub = mid\nprint(ub)", "import numpy as np\nimport math\nstdin = open(0)\n\nN,K = map(int,input().split())\nA = np.array([int(Ai) for Ai in input().split()])\nA = np.sort(A)\n\nmaxA = max(np.abs(A))\n\nz = A[A==0]\np = A[A>0]\nn = A[A<0]\n\ndef check(x):\n ret = 0\n if x >= 0:\n ret += N*len(z)\n ret += np.searchsorted(A,x//p,side='right').sum()\n ret += (N - np.searchsorted(A, -(x // -n))).sum()\n\n ret -= np.count_nonzero(A*A<=x)\n return ret//2;\n\nub = maxA*maxA\nlb = -ub-1\nwhile ub-lb > 1:\n mid = (ub+lb)>>1\n if check(mid) < K:\n lb = mid\n else:\n ub = mid\nprint(ub)"] | ['Runtime Error', 'Accepted'] | ['s550758228', 's331070448'] | [34244.0, 32304.0] | [2109.0, 1137.0] | [563, 627] |
p02774 | u544212192 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import numpy as np\nimport sys\n\nn,k=map(int,sys.stdin.readline().split())\na=np.array(sys.stdin.readline().split(),dtype=np.int64)\n\na.sort()\nneg=a[a<0]\nzero=a[a==0]\npos=a[a>0]\n\nprint(neg,zero,pos)\ndef count(x):\n cnt=0\n if x>=0:\n cnt+=len(zero)*n\n cnt+=np.searchsorted(a,x//pos,side='right').sum()\n cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()\n cnt-=np.count_nonzero(a*a<=x)\n return cnt//2\n\n\nleft=-10**18\nright=10**18\n\nwhile left+1<right:\n x=(left+right)//2\n out=count(x)\n print(out)\n if out>=k:\n right=x\n if out<k:\n left=x\n\nprint(right)\n", "import numpy as np\nimport sys\n\nn,k=map(int,sys.stdin.readline().split())\na=np.array(sys.stdin.readline().split(),dtype=int)\n\na.sort()\nneg=a[a<0]\nzero=a[a==0]\npos=a[a>0]\n\nprint(neg,zero,pos)\ndef count(x):\n cnt=0\n if x>=0:\n cnt+=len(zero)*n\n cnt+=np.searchsorted(a,x//pos,side='right').sum()\n cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()\n cnt-=np.count_nonzero(a*a<=x)\n return cnt//2\n\n\nleft=-10**18\nright=10**18\n\nwhile left+1<right:\n x=(left+right)//2\n out=count(x)\n print(out)\n if out>=k:\n right=x\n if out<k:\n left=x\n\nprint(right)\n", 'import sys\n\nn=sys.stdin.readline().rstrip()[::-1]\nto=0\nnum=len(n)\nm=0\n\nfor i in range(num):\n k=int(n[i])\n k+=m\n if k==5:\n if int(n[i+1])>=5:\n to+=10-k\n m=1\n else:\n to+=k\n m=0\n if k<5:\n to+=k\n m=0\n elif k>5:\n to+=10-k\n m=1\n if i==num-1:\n to+=1\n \nprint(to)\n', "import numpy as np\nimport sys\n\nn,k,*a=map(int,sys.stdin.readlines().split())\na=np.array(a,dtype=np.int64)\n\nprint(n,k,a)\n\na.sort()\nneg=a[a<0]\nzero=a[a==0]\npos=a[a>0]\n\nprint(np.searchsorted(a,0//pos,side='right').sum())\n\ndef count(x):\n cnt=0\n if x>=0:\n cnt+=len(zero)\n cnt+=np.searchsorted(a,x//pos,side='right').sum()\n cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()\n cnt-=np.count_nonzero(a*a<=x)\n return cnt//2\n\n\nleft=-10**18\nright=10**18\n\nwhile left+1<right:\n x=(left+right)//2\n cnt=count(x)\n if cnt>=k:\n right=x\n if cnt<k:\n left=x\n\nprint(right)\n", "import numpy as np\nimport sys\n\nn,k=map(int,sys.stdin.readline().split())\na=np.array(sys.stdin.read().split(),dtype=np.int64)\n\na.sort()\nneg=a[a<0]\nzero=a[a==0]\npos=a[a>0]\n\ndef count(x):\n cnt=0\n if x>=0:\n cnt+=len(zero)*n\n cnt+=np.searchsorted(a,x//pos,side='right').sum()\n cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()\n cnt-=np.count_nonzero(a*a<=x)\n return cnt//2\n\n\nleft=-10**18\nright=10**18\n\nwhile left+1<right:\n x=(left+right)//2\n out=count(x)\n if out>=k:\n right=x\n if out<k:\n left=x\n\nprint(right)\n"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s219405337', 's404761051', 's408131501', 's589744614', 's078498227'] | [34660.0, 34656.0, 3064.0, 16176.0, 34324.0] | [1095.0, 1093.0, 18.0, 153.0, 1099.0] | [606, 601, 381, 613, 567] |
p02774 | u559196406 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['N,K = map(int,input().split())\na = list(map(int,input().split())\n\nd = []\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n else:\n d.append(a[i]*a[j])\n \nprint(sorted(d)[K-1])', 'N,K = map(int,input().split())\na = list(map(int),input().split())\n\nd = []\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n else:\n d.append(a[i]*a[j])\n \nprint(sorted(d)[K-1])', "import numpy as np\n\nN,K = map(int,input().split())\na = list(map(int, input().split()))\n\nb = np.tile(a,N).reshape(N,-1).astype('float128')\nc = np.tril(b * b.T, k=-1)\nd = c + np.tri(N).T * np.max(c)\n\nprint(d)\nprint(int(sorted(d.flatten())[K-1]))", 'N,K = map(int,input().split())\na = list(map(int,input().split()))\n\nd = []\nfor i in range(N):\n for j in range(N):\n if j == i:\n continue\n else:\n d.append(a[i]*a[j])\n \nprint(sorted(d)[K-1])', "import numpy as np\nN,K = map(int,input().split())\na = np.array(input().split(),np.int64)\nzero = a[a==0]\npos = a[a>0]\nneg = a[a<0]\n\ndef f(x):\n count = 0\n c = x // pos\n count += np.searchsorted(a, c, side='right').sum()\n count += N*len(zero) if x >= 0 else 0\n c = -(-x // neg)\n count += (N - np.searchsorted(a, c, side='left')).sum()\n count -= a[a*a <= x].size\n count //= 2\n return count\n\nright = 10**18\nleft = -10**18\nwhile right-left>1:\n mid = (right + left)//2\n if f(mid)<K:\n left = mid\n else:\n right = mid\n \nprint(right)", 'N,K = map(int,input().split())\na = list(map(int,input().split()))\n\nd_plus = sorted([i for i in a if i>=0])\nd_minus = sorted([i for i in a if i<0])\n\nd = []\nif len(d_plus)*len(d_minus) <= K:\n for i in d_plus:\n for j in d_minus:\n d.append(i*j)\n print(sorted(d)[K-1])\nelse:\n for i in range(len(d_plus)):\n for j in range(len(d_plus)):\n if i==j:\n continue\n else:\n d.append(d_plus[i]*d_plus[j])\n for i in range(len(d_minus)):\n for j in range(len(d_minus)):\n if i==j:\n continue\n else:\n d.append(d_minus[i]*d_minus[j])\n print(sorted(d)[K-1-len(d_plus)*len(d_minus)])\n ', "import numpy as np\nN,K = map(int,input().split())\na = np.array(input().split(),np.int64)\na = np.sort(a)\nzero = a[a==0]\npos = a[a>0]\nneg = a[a<0]\n\ndef f(x):\n count = 0\n c = x // pos\n count += np.searchsorted(a, c, side='right').sum()\n count += N*len(zero) if x >= 0 else 0\n c = -(-x // neg)\n count += (N - np.searchsorted(a, c, side='left')).sum()\n count -= a[a*a <= x].size\n count //= 2\n return count\n\nright = 10**18\nleft = -10**18\nwhile right-left>1:\n mid = (right + left)//2\n if f(mid)<K:\n left = mid\n else:\n right = mid\n \nprint(right)"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s403605067', 's522405043', 's558223080', 's599396186', 's672741356', 's869293402', 's144654145'] | [2940.0, 3064.0, 458792.0, 311184.0, 34552.0, 546096.0, 34648.0] | [17.0, 18.0, 2120.0, 2123.0, 1224.0, 2142.0, 1170.0] | [207, 208, 243, 208, 579, 631, 594] |
p02774 | u561231954 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["def main():\n import sys\n import numpy as np\n\n sr = lambda: sys.stdin.readline().rstrip()\n ir = lambda: int(sr())\n lr = lambda: list(map(int, sr().split()))\n\n N, M = lr()\n A = np.array(lr())\n A.sort()\n Am=A[A<0]\n Az=A[A==0]\n Ap=A[A>0]\n l1=len(Az)\n l2=len(Am)\n\n def shake_cnt(x):\n X =np.searchsorted(Ap, x/Ap)\n print(X)\n Y =np.searchsorted(Am, -x/Am,side='right')\n if x<=0:\n ans=l1*N\n else:\n ans=0\n return N*(N-1)//2 - ans - X.sum() -l2+Y.sum()\n \n\n right = 10**6\n left = 0\n while right > left + 1:\n mid = (right+left) // 2\n if shake_cnt(mid) >= M:\n left = mid\n else:\n right = mid\n \n print(right)\nif __name__=='__main__':\n main()\n", "def main():\n import numpy as np\n from bisect import bisect_left,bisect_right\n n,k=map(int,input().split())\n A=list(map(int,input().split()))\n A=np.array(A)\n A=np.sort(A)\n Ap=A[A>0]\n Az=A[A==0]\n Am=A[A<0] \n lm,lz,lp=len(Am),len(Az),len(Ap)\n Am2=Am**2\n Ap2=Ap**2\n \n def cnt_product(x): \n if x<0:\n X=np.searchsorted(Am,x//Ap,side='right')\n #print(X)\n return X.sum()\n \n else:\n ans=lz*(n-lz)+lz*(lz-1)//2+lp*lm\n\n X=np.searchsorted(Ap,x//Ap,side='right')\n Xd=np.count_nonzero(Ap2<=x)\n\n Y=np.searchsorted(Am,(-x-1)//(-Am),side='right')\n Yd=np.count_nonzero(Am2<=x)\n \n ans+=(X.sum()-Xd+lm**2-Y.sum()-Yd)//2\n return ans\n\n left=-10**18\n right=10**18\n while right-left>1:\n mid=(left+right)//2\n if cnt_product(mid)<k:\n left=mid\n else:\n right=mid\n print(right)\n\nif __name__=='__main__':\n main()"] | ['Wrong Answer', 'Accepted'] | ['s182388252', 's833296497'] | [32308.0, 32320.0] | [483.0, 1053.0] | [709, 1120] |
p02774 | u575239123 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import math\nimport itertools\ndef combinations_count(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\nn,k=map(int,input().split())\na=list(map(int, input().split()))\na=sorted(a)\nmlist=[]\nzlist=[]\nplist=[]\nfor i in a:\n if i<0:\n mlist.append(i)\n elif i==0:\n zlist.append(i)\n else:\n plist.append(i)\nmnum=len(mlist)\nznum=len(zlist)\npnum=len(plist)\nmans=mnum*pnum\nzans=znum*(pnum+mnum)\nif znum>=2:\n zans+=combinations_count(znum,2)\npans=0\nif pnum>=2:\n pans+=combinations_count(pnum,2)\nif mnum>=2:\n pans+=combinations_count(mnum,2)\n\nif k<mans:\n ans=[]\n l=mlist[0]*plist[-1]\n r=mlist[-1]*plist[0]\n while True:\n x=(l+r)//2\n c=0\n for m in mlist:\n for p in plist[::-1]:\n if m*p<x:\n c+=1\n else:\n break\n if c<k:\n l=x\n else:\n r=x\n if r==l+1:\n break\n print(l)\nelif k<mans+zans:\n print(0)\nelse:\n k=k-(mans+zans)\n mlist=mlist[::-1]\n if mnum<2:\n l=plist[0]*plist[1]\n r=plist[-1]*plist[-2]\n elif pnum<2:\n l=mlist[0]*mlist[1]\n r=mlist[-1]*mlist[-2]\n else:\n if mlist[0]*mlist[1]<plist[0]*plist[1]:\n l=mlist[0]*mlist[1]\n else:\n l=plist[0]*plist[1]\n if mlist[-1]*mlist[-2]>plist[-1]*plist[-2]:\n r=mlist[-1]*mlist[-2]\n else:\n r=plist[-1]*plist[-2]\n #print(k)\n while True:\n x=(l+r)//2\n c=0\n max=0\n if mnum>=2:\n for i,m in enumerate(mlist[:-1]):\n for j in mlist[i:]:\n n=m*j\n if n<x:\n c+=1\n if n>=max:max=n\n else:\n break\n if pnum>=2:\n for i,p in enumerate(plist[:-1]):\n for j in plist[i:]:\n n=p*j\n if n<x:\n c+=1\n if n>=max:max=n\n else:\n break\n #print("c"+str(c))\n if c<k:\n l=x\n #print("l"+str(l))\n else:\n r=x\n #print("r"+str(r))\n if r==l+1:\n break\n if c==k:break\n print(l)', "import numpy as np\nimport sys\n \nn,k=map(int,sys.stdin.readline().split())\na=np.array(list(map(int, input().split())))\n \na.sort()\nneg=a[a<0]\nzero=a[a==0]\npos=a[a>0]\n \ndef count(x):\n cnt=0\n if x>=0:\n cnt+=len(zero)*n\n cnt+=np.searchsorted(a,x//pos,side='right').sum()\n cnt+=(n-np.searchsorted(a,(-x-1)//(-neg),side='right')).sum()\n cnt-=np.count_nonzero(a*a<=x)\n return cnt//2\n \n \nleft=-10**18\nright=10**18\n \nwhile left+1<right:\n x=(left+right)//2\n out=count(x)\n if out>=k:\n right=x\n if out<k:\n left=x\nprint(right)"] | ['Runtime Error', 'Accepted'] | ['s560062491', 's165590370'] | [23908.0, 32304.0] | [2104.0, 1105.0] | [1920, 563] |
p02774 | u593567568 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\nimport bisect\nsys.setrecursionlimit(10 ** 7)\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nA.sort()\nminus = bisect.bisect_left(A, 0)\nplus = bisect.bisect_right(A, 0)\nzero = plus - minus\n\nnegative = minus * plus\npositive = (plus * (plus - 1) // 2) + (minus * (minus - 1) // 2)\nzeros = (N * N - 1) // 2 - (positive + negative)\n\nif K <= negative:\n A0 = A[:minus]\n A1 = A[plus:]\n A1.sort()\n\n left = -(10 ** 18)\n right = 0\n\n print(A0)\n print(A1)\n\n def test(val):\n cnt = 0\n lg = len(A0)\n for a0 in A0:\n p = val // a0\n cnt += lg - bisect.bisect_left(A1, p)\n return cnt\n\n while (right - left) > 1:\n mid = (left + right) // 2\n res = test(mid)\n print("mid,cnt", mid, res)\n if res >= K:\n right = mid\n else:\n left = mid\n\n print(left)\n exit()\n\n\nelif negative < K and K <= (negative + zeros):\n print(0)\n exit()\nelse:\n A0 = A[:minus]\n A1 = A[plus:]\n\n A0.sort(reverse=True)\n\n K -= zeros + negative\n\n def test(val):\n cnt = 0\n lg = len(A0)\n if lg > 1:\n for i in ren(lg - 1):\n l = i+1\n r = len(lg) - 1\n\n a0 = A0[i]\n if val < a0 * A0[l]:\n continue\n\n while (r - l) > 1:\n m = (l + r) // 2\n if val < a0 * A0[m]:\n r = m\n else:\n l = m\n\n cnt += l\n\n lg = len(A1)\n if lg > 1:\n for i in ren(lg - 1):\n l = i+1\n r = len(lg) - 1\n\n a0 = A0[i]\n if val < a0 * A0[l]:\n continue\n\n while (r - l) > 1:\n m = (l + r) // 2\n if val < a0 * A0[m]:\n r = m\n else:\n l = m\n\n cnt += l\n return cnt\n\n left = 0\n right = 10 ** 18\n\n while (right - left) > 1:\n mid = (left + right) // 2\n res = test(mid)\n if res >= K:\n right = mid\n else:\n left = mid\n\n print(left)\n exit()\n', "import sys\nimport numpy as np\nsys.setrecursionlimit(10 ** 7)\n\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nN, K = map(int, input().split())\nA = np.array(input().split(), np.int64)\n\nA = np.sort(A)\nzero = A[A == 0]\npos = A[A > 0]\nneg = A[A < 0]\n\n\ndef test(x):\n cnt = 0\n\n if x >= 0:\n cnt += len(zero) * N\n\n cnt += np.searchsorted(A, x // pos, side='right').sum()\n cnt += (N - np.searchsorted(A, (-x - 1) // -neg, side='right')).sum()\n cnt -= np.count_nonzero(A * A <= x)\n\n cnt //= 2\n\n return K <= cnt\n\n\nl = -(10 ** 19) # NG\nr = 10 ** 19 # OK\n\nwhile l + 1 != r:\n mid = (l + r) // 2\n\n if test(mid):\n r = mid\n else:\n l = mid\n\nprint(r)\n"] | ['Runtime Error', 'Accepted'] | ['s387780685', 's770098687'] | [24692.0, 34556.0] | [2104.0, 1149.0] | [2266, 743] |
p02774 | u609061751 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\ninput = sys.stdin.readline\nimport numpy as np\n\nN, K = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\n\nA_m = np.array(sorted([abs(int(x)) for x in A if x < 0]), np.int64)\nN_m = len(A_m)\n\nA_p = np.array(sorted([int(x) for x in A if x > 0]), np.int64)\nN_p = len(A_p)\n\nM = N_m * N_p\nP = (1 / 2) * (N_m) * (N_m - 1) + (1 / 2) * (N_p) * (N_p - 1)\nZ = (1 / 2) * N * (N - 1) - (M + P)\n\nif M < K <= M + Z:\n print(0)\n sys.exit()\n\ndef cnt_M(x):\n cnt = np.searchsorted(A_m, x / A_p, side="right").sum()\n return cnt\n\nif K <= M:\n left = -1\n right = 10 ** 6\n \n left = -10 ** 18\n right = 10 ** 18\n while left + 1 < right:\n x = (left + right) // 2\n if cnt_M(x) >= K:\n right = x\n else:\n left = x\n \n print(-left)\n sys.exit()\nK -= (M + Z)\ndef cnt_P(x):\n cnt = 0\n ng = 0\n cnt += np.searchsorted(A_m, x / A_m, side="right").sum()\n cnt += np.searchsorted(A_p, x / A_p, side="right").sum()\n ng = np.count_nonzero(A_m * A_m <= x) + np.count_nonzero(A_p * A_p <= x)\n return (cnt - ng) // 2\n\nleft = -1\nright = 1 + 10 ** 18\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if cnt_P(x) >= K:\n right = x\n else:\n left = x\n \nprint(right)\n', 'import sys\ninput = sys.stdin.readline\nimport numpy as np\n\nN, K = [int(x) for x in input().split()]\nA = [int(x) for x in input().split()]\n\nA_m = np.array(sorted([abs(int(x)) for x in A if x < 0]), np.int64)\nN_m = len(A_m)\n\nA_p = np.array(sorted([int(x) for x in A if x > 0]), np.int64)\nN_p = len(A_p)\n\nM = N_m * N_p\nP = (1 / 2) * (N_m) * (N_m - 1) + (1 / 2) * (N_p) * (N_p - 1)\nZ = (1 / 2) * N * (N - 1) - (M + P)\n\nif M < K <= M + Z:\n print(0)\n sys.exit()\n\ndef cnt_M(x):\n cnt = np.searchsorted(A_m, x // A_p, side="right").sum()\n return cnt >= M - K + 1\n\nif K <= M:\n left = -1 -10 ** 18\n right = 1 + 10 ** 18\n while right - left> 1:\n mid = (left + right) // 2\n if cnt_M(mid):\n right = mid\n else:\n left = mid\n \n print(-right)\n sys.exit()\n\nK -= (M + Z)\ndef cnt_P(x):\n cnt = 0\n ng = 0\n cnt += np.searchsorted(A_m, x // A_m, side="right").sum()\n cnt += np.searchsorted(A_p, x // A_p, side="right").sum()\n ng = np.count_nonzero(A_m * A_m <= x) + np.count_nonzero(A_p * A_p <= x)\n cnt = (cnt - ng) // 2\n return cnt >= K\n\nleft = -1 - 10 ** 18\nright = 1 + 10 ** 18\n\nwhile right - left > 1:\n mid = (left + right) // 2\n if cnt_P(mid):\n right = mid\n else:\n left = mid\nprint(right)'] | ['Wrong Answer', 'Accepted'] | ['s083050594', 's415391136'] | [32332.0, 32252.0] | [1210.0, 1150.0] | [1298, 1282] |
p02774 | u619819312 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\nfrom bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nn,k=map(int,input().split())\na=np.sort(np.array(list((map(int,input().split())))))\nq=len(a[a==0])\nd=a[a<0]\ne=a[a>0]\nl,r=10**18,-10**18\nwhile l-r>1:\n t=(l+r)//2\n p=0\n if t>=0:\n p+=q*n\n p+=np.searchsorted(a,t//e,side="right").sum()+(n-np.searchsorted(a,(-t-1)//(-d),side="right")).sum()\n p-=np.count_nonzero(a*a<=t)\n p//=2\n if p>=k:\n l=t\n else:\n r=t\nprint(r)', 'import numpy as np\nfrom bisect import bisect_right as br\nfrom bisect import bisect_left as bl\nn,k=map(int,input().split())\na=np.sort(np.array(list((map(int,input().split())))))\nq=len(a[a==0])\nd=a[a<0]\ne=a[a>0]\nl,r=10**18,-10**18\nwhile l-r>1:\n t=(l+r)//2\n p=0\n if t>=0:\n p+=q*n\n p+=np.searchsorted(a,t//e,side="right").sum()+(n-np.searchsorted(a,(-t-1)//(-d),side="right")).sum()\n p-=np.count_nonzero(a*a<=t)\n p//=2\n if p>=k:\n l=t\n else:\n r=t\nprint(l)'] | ['Wrong Answer', 'Accepted'] | ['s402099639', 's837867200'] | [32316.0, 32304.0] | [1103.0, 1104.0] | [495, 495] |
p02774 | u648212584 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\ninput = sys.stdin.buffer.readline\nimport numpy as np\n\ndef main():\n N,K = map(int,input().split())\n a = np.array(list(map(int,input().split())))\n a.sort()\n posi,zero,nega = a[a>0],a[a==0],a[a<0]\n\n lp,lz,ln = len(posi),len(zero),len(nega)\n \n def ch(x):\n count = 0\n if x >= 0:\n count += lz*N\n count += np.searchsorted(a,x//posi,side="right").sum()\n count += (N-np.searchsorted(a,np.ceil(x//nega))).sum()\n count -= np.count_nonzero(a**2<=x)\n return count//2\n\n l,r = -10**18-1,10**18+1\n while r-l > 1:\n mid = (r+l)//2\n if ch(mid) >= K:\n r = mid\n else:\n l = mid\n\n print(r)\n \nif __name__ == "__main__":\n main()\n', 'import sys\ninput = sys.stdin.buffer.readline\nimport numpy as np\n\ndef main():\n N,K = map(int,input().split())\n a = list(map(int,input().split()))\n \n posi,zero,nega = [],[],[]\n for num in a:\n if num > 0:\n posi.append(num)\n elif num == 0:\n zero.append(num)\n else:\n nega.append(num)\n \n lp,lz,ln = len(posi),len(zero),len(nega)\n posi.sort(),nega.sort()\n posi,zero,nega = np.array(posi),np.array(zero),np.array(nega)\n _nega = nega[::-1]*(-1)\n \n def ch(x):\n if x == 0:\n return (lz*(lz-1))//2+lz*(lp+ln)+lp*ln\n elif x > 0:\n count = (lz*(lz-1))//2+lz*(lp+ln)+lp*ln\n puse = np.searchsorted(posi,(x//posi),side="right")\n pdup = np.count_nonzero(posi**2<=x)\n nuse = np.searchsorted(_nega,x//_nega,side="right")\n ndup = np.count_nonzero(_nega**2<=x)\n return (np.sum(puse)+np.sum(nuse)-pdup-ndup)//2+count\n else:\n count = np.searchsorted(nega,x//posi,side="right")\n return np.sum(count)\n\n l,r = -10**18-1,10**18+1\n while r-l > 1:\n mid = (r+l)//2\n if ch(mid) >= K:\n r = mid\n else:\n l = mid\n print(r)\n \nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s730492434', 's041978778'] | [29452.0, 29388.0] | [1228.0, 1120.0] | [747, 1298] |
p02774 | u693716675 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['#abc_155_d\n#versions of not using numpy\nn,k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = np.array(a)\na.sort()\n\nleft = -10**18\nright = 10**18\n\nwhile left+1 < right:\n mid = (left+right)//2\n cnt = 0\n \n #run about each element as the first choice\n for i in range(n):\n #count possible pairs that satisfies the condition \n if(a[i] >= 0):\n #hold the sorted order\n l = -1 \n r = n\n while l+1<r:\n m = (l+r)//2\n if(a[i]*a[m] <= mid):\n l = m\n else:\n r = m\n \n cnt += l+1\n \n if(a[i] < 0):\n #reverse the sorted order\n l = -1 \n r = n\n while l+1<r:\n m = (l+r)//2\n if(a[i]*a[m] <= mid):\n r = m\n else:\n l = m\n \n cnt += n - r\n \n if(a[i]**2 <= mid):\n cnt -= 1\n \n cnt /= 2\n \n \n \n \n \n if cnt >= k:\n right = mid\n if cnt < k:\n left=mid\n \n \nprint(right)', '#abc_155_d\n#versions of not using numpy\nn,k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = np.array(a)\na.sort()\n\nleft = -10**18\nright = 10**18\n\nwhile left+1 < right:\n mid = (left+right)//2\n cnt = 0\n \n #run about each element as the first choice\n for i in range(n):\n #count possible pairs that satisfies the condition \n if(a[i] >= 0):\n #hold the sorted order\n l = -1 \n r = n\n while l+1<r:\n m = (l+r)//2\n if(a[i]*a[m] <= mid):\n l = m\n else:\n r = m\n \n cnt += l+1\n \n if(a[i] < 0):\n #reverse the sorted order\n l = -1 \n r = n\n while l+1<r:\n m = (l+r)//2\n if(a[i]*a[m] <= mid):\n r = m\n else:\n l = m\n \n cnt += n - r\n \n if(a[i]**2 <= mid):\n cnt -= 1\n \n cnt /= 2\n \n \n \n \n \n if cnt >= k:\n right = mid\n if cnt < k:\n left=mid\n \n \nprint(right)', '#abc_155_d\nimport numpy as np\nn,k = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\na = np.array(a)\na.sort()\n\nplus = a[a>0]\nzero = a[a==0]\nminus= a[a<0]\n\nleft = -10**18\nright = 10**18\n\nwhile left+1 < right:\n mid = (left+right)//2\n cnt = 0\n \n if mid >=0:\n cnt += len(zero) * n\n \n cnt += a.searchsorted(mid//plus, side="right").sum()\n cnt += (n - a.searchsorted(-(-mid//minus), side="left")).sum()\n cnt -= np.count_nonzero(a*a <= mid)\n cnt /= 2\n \n if cnt >= k:\n right = mid\n if cnt < k:\n left=mid\n \nprint(right)'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s146934010', 's745666760', 's796878185'] | [23884.0, 23764.0, 32300.0] | [77.0, 75.0, 1115.0] | [1443, 1443, 597] |
p02774 | u704563784 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["def bin_search(array, num):\n if array[0] > num: return 0\n if array[-1] < num: return len(array)\n mx = len(array) - 1\n mn = 0\n while mx >= mn :\n median = mn + (mx - mn)//2 \n target = array[median]\n if target == num:\n return median + 1\n elif target > num:\n mx = median - 1\n else:\n mn = median + 1\n\n return median + 1\n\nn, k = map(int, input().split())\narr = list(map(int, input().split()))\n# arr = list(map(int, '5 4 3 2 -1 0 0 0 0 0'.split()))\narr.sort()\n\nn_int = 0\nn_range = [None, None]\nz_int = 0\nzero_range = [None, None]\np_int = 0\np_range = [None, None]\n\nfor idx, i in enumerate(arr):\n if i < 0:\n n_int += 1\n if n_range[0] == None: n_range[0] = idx\n n_range[1] = idx + 1\n elif i == 0:\n z_int += 1\n if zero_range[0] == None: zero_range[0] = idx\n zero_range[1] = idx + 1\n \n else:\n p_int += 1\n if p_range[0] == None: p_range[0] = idx\n p_range[1] = idx + 1\n\nnegative = n_int * p_int\nzero = z_int * (n_int + p_int) + (z_int*(z_int-1)//2)\npositive = (p_int*(p_int-1)//2) + (n_int*(n_int-1)//2)\n\n\nif k > zero + negative:\n n_list = arr[n_range[0]: n_range[1]]\n p_list = arr[p_range[0]: p_range[1]]\n\n goal = k - zero - negative\n\n if len(n_list) < 2:\n mn = p_list[0] * p_list[1]\n mx = p_list[-1] * p_list[-2]\n \n elif len(p_list) <2:\n mn = n_list[-1] * n_list[-2]\n mx = n_list[0] * n_list[1]\n \n else:\n mn = min (n_list[-1]*n_list[-2], p_list[0]*p_list[1])\n mx = max (n_list[0]*n_list[1], p_list[-1]*p_list[-2])\n\n while mx >= mn:\n m = mn + (mx - mn)//2\n under = 0\n p_under = 0\n for a in p_list:\n thres = m//a\n score = bin_search(p_list, thres)\n if a*a <= m:\n score -= 1\n p_under += score\n p_under /= 2\n under += p_under\n \n n_under = 0\n for a in n_list:\n thres = m//a\n score = n_int - bin_search(n_list, thres - 1)\n if a*a <= m:\n score -= 1\n n_under += score\n n_under /= 2\n under += n_under\n\n if under >= goal:\n mx = m - 1\n \n else:\n mn = m + 1\n \n print(m)\n\n\n", "def bin_search(array, num):\n if array[0] > num: return 0\n if array[-1] < num: return len(array)\n mx = len(array) - 1\n mn = 0\n while mx >= mn :\n median = mn + (mx - mn)//2 \n target = array[median]\n if target == num:\n return median + 1\n elif target > num:\n mx = median - 1\n else:\n mn = median + 1\n\n return median + 1\n\nn, k = map(int, input().split())\narr = map(int, input().split())\n# arr = list(map(int, '5 4 3 2 -1 0 0 0 0 0'.split()))\narr.sort()\n\nn_int = 0\nn_range = [None, None]\nz_int = 0\nzero_range = [None, None]\np_int = 0\np_range = [None, None]\n\nfor idx, i in enumerate(arr):\n if i < 0:\n n_int += 1\n if n_range[0] == None: n_range[0] = idx\n n_range[1] = idx + 1\n elif i == 0:\n z_int += 1\n if zero_range[0] == None: zero_range[0] = idx\n zero_range[1] = idx + 1\n \n else:\n p_int += 1\n if p_range[0] == None: p_range[0] = idx\n p_range[1] = idx + 1\n\nnegative = n_int * p_int\nzero = z_int * (n_int + p_int) + (z_int*(z_int-1)//2)\npositive = (p_int*(p_int-1)//2) + (n_int*(n_int-1)//2)\n\n\nif k > zero + negative:\n n_list = arr[n_range[0]: n_range[1]]\n p_list = arr[p_range[0]: p_range[1]]\n\n goal = k - zero - negative\n\n if len(n_list) < 2:\n mn = p_list[0] * p_list[1]\n mx = p_list[-1] * p_list[-2]\n \n elif len(p_list) <2:\n mn = n_list[-1] * n_list[-2]\n mx = n_list[0] * n_list[1]\n \n else:\n mn = min (n_list[-1]*n_list[-2], p_list[0]*p_list[1])\n mx = max (n_list[0]*n_list[1], p_list[-1]*p_list[-2])\n\n while mx >= mn:\n m = mn + (mx - mn)//2\n under = 0\n p_under = 0\n for a in p_list:\n thres = m//a\n score = bin_search(p_list, thres)\n if a*a <= m:\n score -= 1\n p_under += score\n p_under /= 2\n under += p_under\n \n n_under = 0\n for a in n_list:\n thres = m//a\n score = n_int - bin_search(n_list, thres - 1)\n if a*a <= m:\n score -= 1\n n_under += score\n n_under /= 2\n under += n_under\n\n if under >= goal:\n mx = m - 1\n \n else:\n mn = m + 1\n \n print(m)\n\n\n", 'def bin_search(array, num):\n if array[0] > num: return 0\n if array[-1] < num: return len(array)\n mx = len(array) - 1\n mn = 0\n while mx >= mn :\n median = mn + (mx - mn)//2 \n target = array[median]\n if target == num:\n return median + 1\n elif target > num:\n mx = median - 1\n else:\n mn = median + 1\n\n return median + 1\n\nn, k = map(int, input().split())\narr = list(map(int, input().split()))\n\nmn = -10 ** 18 - 1\nmx = 10 ** 18 + 1\n\nwhile mx >= mn:\n m = mn + (mx - mn)//2\n\n score = 0\n for a in arr:\n if a > 0:\n thres = m//a\n score += bin_search(arr, thres)\n \n elif a < 0:\n thres = m//a\n score += n - bin_search(arr, thres-1)\n \n else:\n if m >= 0:\n score += n\n\n if a <= m: score -= 1\n \n assert score % 2 == 0\n\n score /= 2 \n under = score\n if under < k:\n mn = m\n \n else:\n mx = m\n\nprint(m)\n\n', 'import numpy as np\nimport sys\n\ninput = sys.stdin.readline\n\nn, k = [int(x) for x in input().split()]\nA = np.array([int(a) for a in input().split()], dtype="int64")\n\nA = np.sort(A)\n\nA_pos = A[A > 0]\nA_neg = A[A < 0]\nA_zero = A[A == 0]\n\n\ndef n_comb_lt(c):\n n_comb = 0\n \n target = c // A_pos \n n_comb += np.searchsorted(A, target, side="right").sum()\n\n \n n_comb += n * len(A_zero) if c >= 0 else 0\n\n \n target = -(-c // A_neg)\n n_comb += (n - np.searchsorted(A, target, side="left")).sum()\n\n \n n_comb -= A[A * A <= c].size\n n_comb //= 2\n\n return n_comb\n\nok = -10 ** 18 - 1\nng = 10 ** 18 + 1\n\n\n\nwhile ng - ok > 1:\n mid = (ng + ok) // 2\n if n_comb_lt(mid - 1) < k:\n ok = mid\n else:\n ng = mid\n\nprint(ok)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s028809138', 's672451199', 's846570607', 's282651324'] | [23288.0, 17868.0, 23876.0, 32308.0] | [2104.0, 40.0, 2104.0, 1187.0] | [2355, 2349, 1025, 1216] |
p02774 | u707124227 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['n,k=map(int,input().split())\na=list(map(int,input().split()))\nfrom math import log2\nfrom bisect import bisect_left,bisect_right\na.sort()\n\nmn=bisect_left(a,0)\n\nzn=bisect_right(a,0)-mn\n\npn=n-mn-zn\nam=a[:mn]\nam=[-x for x in am[::-1]]\nap=a[mn+zn:]\n\n\ndef func(x):\n cnt=0\n if x>0:\n cnt+=mn*pn\n cnt+=(zn*(n-1+n-zn))//2\n cnt1=0\n for y in ap:\n cnt1+=bisect_left(ap,(x+y-1)//y)\n if y**2<x:cnt1-=1\n for y in am:\n cnt1+=bisect_left(am,(x+y-1)//y)\n if y**2<x:cnt1-=1\n cnt+=cnt1//2\n elif x<0:\n x=abs(x)\n for y in ap:\n cnt+=mn-bisect_right(am,(x+y-1)//y)\n elif x==0:\n cnt+=mn*pn\n return cnt<k\n\nmaxaa=max(abs(a[0]),abs(a[-1]))**2\nl,r=-maxaa,maxaa\nwhile r-l>1:\n x=(l+r)//2\n if func(x):\n l,r=x,r\n else:\n l,r=l,x\nprint(r if func(r) else l)\n\n', "import numpy as np\nn,k=map(int,input().split())\na=np.array(list(map(int,input().split())))\na.sort()\np=a[a>0]\nz=np.count_nonzero(a==0)\nm=a[a<0]\nr=10**19\nl=-r\nwhile r-l>1:\n \n \n b=(l+r)//2\n c=0\n if b>=0:\n c+=z*n\n \n c+=a.searchsorted(b//p,side='right').sum()\n \n c+=n*len(m)-a.searchsorted(-(-b//m),side='left').sum()\n c-=np.count_nonzero(a*a<=b)\n if c//2>=k:\n r=b\n else:\n l=b\nprint(r)\n"] | ['Wrong Answer', 'Accepted'] | ['s050437817', 's244173502'] | [29208.0, 32232.0] | [2206.0, 1137.0] | [1059, 981] |
p02774 | u736470924 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\n\nN, K = map(int, input().split())\na = sorted(list(map(int, input().split())))\nl = -(((1e18)+1)\nr=(1e18)+1\nwhile(l + 1 < r):\n x=(l + r) / 2\n total=0\n for i in range(N):\n if a[i] < 0:\n l=-1\n r=N\n while(l + 1 < r):\n c=(l + r) / 2\n if a[c] * a[i] < x:\n r=c\n else:\n l=c\n total += n - r\n else:\n l=-1\n r=N\n while(l + 1 < r):\n c=(l + r) / 2\n if a[c] * a[i] < x:\n l=c\n else:\n r=c\n total += r\n if a[i] * a[i] < x:\n total -= 1\n total /= 2\n if total < K:\n l=x\n else:\n r=x\nprint(l)\n', "import numpy as np\n\nn, k = map(int, input().split())\n\nA = np.array(input().split(), np.int64)\n\nA.sort()\n\nposA = A[A > 0]\nnegA = A[A < 0]\nzeros = (A==0).sum()\n\nleft = -10**18\nright = 10**18\n\nwhile left+1 < right:\n num = (left+right)//2\n \n less_count = 0\n \n if num >= 0:\n less_count += zeros * n\n \n limit_pair_for_pos = num // posA\n limit_idxs = np.searchsorted(A, limit_pair_for_pos, side='right')\n less_count += limit_idxs.sum()\n\n limit_pair_for_neg = -(num // -negA)\n limit_idxs = n - np.searchsorted(A, limit_pair_for_neg, side='left')\n less_count += limit_idxs.sum()\n\n duplicate_cases = (A**2 <= num).sum()\n less_count -= duplicate_cases\n less_count //= 2\n \n if less_count >= k:\n right = num\n else:\n left = num\n\nprint(right)\n"] | ['Runtime Error', 'Accepted'] | ['s536129932', 's179785988'] | [2940.0, 34624.0] | [17.0, 1120.0] | [798, 803] |
p02774 | u765865533 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\nN,K=map(int,input().split())\nA=list(map(int,input().split()))\nA=sorted(A)\n#B=list(reversed(A))\nA=np.array(A)\nAneg=A[A<0]\nAzero=A[A==0]\nApos=A[A>0]\n\nn_neg=len(Aneg)*len(Apos)\nn_zero=len(Azero)*(len(Azero)-1)//2+len(Azero)*(len(Aneg)+len(Apos))\nn_pos=(len(Apos)*(len(Apos)-1)+len(Aneg)*(len(Aneg)-1))//2\n\nif K <=n_neg:\n n=K-n_neg\n B=sorted(Aneg)[:n+1]\n C=sorted(Apos)[:n+1]\n ans=[]\n for i in range(min(len(B),n-1)):\n for j in range(min(len(C),n-1)):\n ans.append(B[i]*C[j])\n ans=sorted(ans)\n print(ans[n-1])\n \nelif K>n_neg+n_zero:\n n=K-(n_neg+n_zero)\n B=sorted(Aneg)\n B=list(reversed(B))\n C=sorted(Apos)\n ans=[]\n if len(B)>2:\n for i in range(len(B)-1):\n for j in range(i+1,len(B)):\n ans.append(B[i]*B[j])\n if len(C)>2:\n# k=min(len(C),n-1)\n for i in range(len(C)-1):\n for j in range(i+1,len(C)):\n ans.append(C[i]*C[j])\n ans=sorted(ans)\n print(ans[n-1])\n \nelse:\n print(0)', 'from ABC155_D2 import *\n\n\n\nimport sys\nfrom io import StringIO\nimport unittest\n\nclass TestClass(unittest.TestCase):\n def assertIO(self, input, output):\n stdout, stdin = sys.stdout, sys.stdin\n sys.stdout, sys.stdin = StringIO(), StringIO(input)\n resolve()\n sys.stdout.seek(0)\n out = sys.stdout.read()[:-1]\n sys.stdout, sys.stdin = stdout, stdin\n self.assertEqual(out, output)\n def test_入力例_1(self):\n input = """4 3\n3 3 -4 -2"""\n output = """-6"""\n self.assertIO(input, output)\n def test_入力例_2(self):\n input = """10 40\n5 4 3 2 -1 0 0 0 0 0"""\n output = """6"""\n self.assertIO(input, output)\n def test_入力例_3(self):\n input = """30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0"""\n output = """448283280358331064"""\n self.assertIO(input, output)\n\nif __name__ == "__main__":\n unittest.main()', "import numpy as np\nN,K=map(int,input().split())\nA=list(map(int,input().split()))\n\nA=np.array(A)\n\nA_pos=np.sort(A[A>0])\nA_neg=np.sort(A[A<0])\nA_neg2=-A_neg[::-1]\nn_pos=len(A_pos)\nn_neg=len(A_neg)\nn_zero=N-n_pos-n_neg\n\ndef position_in_neg(x):\n y=n_pos-np.searchsorted(A_pos,x//A_neg,side='right')\n return y.sum()\n\ndef position_in_pos(x):\n z=np.searchsorted(A_pos,-(-x//A_pos),side='left')\n w=np.searchsorted(A_neg2,-(-x//A_neg2),side='left')\n tmp=len(A_pos[A_pos**2<x])+len(A_neg2[A_neg2**2<x])\n return (z.sum()+w.sum()-tmp)//2\n\ndef position(x):\n if x<0:\n return position_in_neg(x)\n elif x==0:\n return n_pos*n_neg\n else:\n return position_in_pos(x)+n_pos*n_neg+(n_pos+n_neg)*n_zero+n_zero*(n_zero-1)//2\n\nl=-pow(10,18)\nr=pow(10,18)\nwhile(r-l>1):\n mid=(l+r)//2\n if position(mid)<K:\n l=mid\n else:\n r=mid\nprint(l)"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s807512397', 's966306038', 's939696873'] | [199120.0, 3064.0, 32304.0] | [2120.0, 18.0, 1093.0] | [1034, 1156, 877] |
p02774 | u781758937 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import numpy as np\nN,K = map(int,input().split())\nA = np.array([int(i) for i in input().split()])\n\nposi = A[A>0]\nzero = A[A==0]\nnega = A[A<0]\n\n\ndef f(x):\n """count the number of products , <= x"""\n cnt_tpl = 0\n # count 0\n if x >= 0:\n cnt_tpl += len(zero) * N\n \n cnt_tpl += np.searchsorted(A, x//pos, side=\'right\').sum()\n \n cnt_tpl += (N - np.searchsorted(A, (-x - 1) // (-neg), side=\'right\')).sum()\n # remove a^2\n cnt_tpl -= np.count_nonzero(A*A <= x)\n return cnt_tpl // 2\n\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if f(x) >= K:\n right = x\n else:\n left = x\n \nprint(right)', 'import numpy as np\nN,K = map(int,input().split())\nA = np.array([int(i) for i in input().split()])\n\nprint(N,K,A)\n\nA = np.sort(A)\nposi = A[A>0]\nzero = A[A==0]\nnega = A[A<0]\n\ndef f(x):\n """count the number of products , <= x"""\n cnt_tpl = 0\n # count 0\n if x >= 0:\n cnt_tpl += len(zero) * N\n \n cnt_tpl += np.searchsorted(A, x//posi, side=\'right\').sum()\n \n cnt_tpl += (N - np.searchsorted(A, (-x - 1) // (-nega), side=\'right\')).sum()\n # remove a^2\n cnt_tpl -= np.count_nonzero(A*A <= x)\n return cnt_tpl // 2\n\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if f(x) >= K:\n right = x\n else:\n left = x\n\nprint(right)', 'import numpy as np\nN,K = map(int,input().split())\nA = np.array([int(i) for i in input().split()])\n\n\nA = np.sort(A)\nposi = A[A>0]\nzero = A[A==0]\nnega = A[A<0]\n\ndef f(x):\n """count the number of products , <= x"""\n cnt_tpl = 0\n # count 0\n if x >= 0:\n cnt_tpl += len(zero) * N\n \n cnt_tpl += np.searchsorted(A, x//posi, side=\'right\').sum()\n \n cnt_tpl += (N - np.searchsorted(A, (-x - 1) // (-nega), side=\'right\')).sum()\n # remove a^2\n cnt_tpl -= np.count_nonzero(A*A <= x)\n return cnt_tpl // 2\n\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if f(x) >= K:\n right = x\n else:\n left = x\n\nprint(right)'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s405980908', 's764581655', 's476618432'] | [32292.0, 32308.0, 32288.0] | [226.0, 1108.0, 1122.0] | [716, 745, 732] |
p02774 | u816488327 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["from sys import stdin\n#f_i = stdin\nf_i = open('test_in_3')#\n\nimport numpy as np\n\nN, K = map(int, f_i.readline().split())\nA = np.array(f_i.read().split(), dtype=int)\n\nA = np.sort(A)\nzero_left = A.searchsorted(0, side='left')\nzero_right = A.searchsorted(0, side='right')\nzero_cnt = zero_right - zero_left\npos = A[zero_right:]\nneg = A[:zero_left]\n\ndef f(x):\n cnt = 0\n \n if x >= 0:\n cnt += zero_cnt * N\n \n cnt += np.searchsorted(A, x // pos, side='right').sum()\n cnt += (N - np.searchsorted(A, (-x - 1) // (-neg), side='right')).sum()\n \n cnt -= np.count_nonzero(A ** 2 <= x)\n return cnt // 2\n\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if f(x) >= K:\n right = x\n else:\n left = x\n\nprint(right)", "from sys import stdin\nf_i = stdin\n\nimport numpy as np\n\nN, K = map(int, f_i.readline().split())\nA = np.array(f_i.read().split(), dtype=int)\n\nA = np.sort(A)\nzero_left = A.searchsorted(0, side='left')\nzero_right = A.searchsorted(0, side='right')\nzero_cnt = zero_right - zero_left\npos = A[zero_right:]\nneg = A[:zero_left]\n\ndef f(x):\n cnt = 0\n \n if x >= 0:\n cnt += zero_cnt * N\n \n cnt += np.searchsorted(A, x // pos, side='right').sum()\n cnt += (N - np.searchsorted(A, (-x - 1) // (-neg), side='right')).sum()\n \n cnt -= np.count_nonzero(A ** 2 <= x)\n return cnt // 2\n\n\nleft = -10 ** 18\nright = 10 ** 18\nwhile left + 1 < right:\n x = (left + right) // 2\n if f(x) >= K:\n right = x\n else:\n left = x\n\nprint(right)"] | ['Runtime Error', 'Accepted'] | ['s682951135', 's604087169'] | [3192.0, 34320.0] | [18.0, 1089.0] | [786, 760] |
p02774 | u824237520 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["from bisect import bisect_left\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\na.sort()\nz = a.count(0)\nmc = bisect_left(a, 0)\npc = n - z - mc\n\nif mc * pc < k <= mc * pc + z * (n-z) + z * (z-1) // 2:\n print(0)\n exit()\n\nprint('dummy')", "from bisect import bisect_left\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\n\na.sort()\nz = a.count(0)\nmc = bisect_left(a, 0)\npc = n - z - mc\n\nif mc * pc < k <= mc * pc + z * (n-z) + z * (z-1) // 2:\n print(0)\n\nprint('dummy')", "import numpy as np\n\nn, k = map(int, input().split())\na = np.array(input().split(), np.int64)\n\na = np.sort(a)\n\nu = a[a > 0]\nd = a[a < 0]\nz = len(a[a == 0])\n\nif len(u) * len(d) < k <= len(u) * len(d) + z * (n-z) + z * (z-1) // 2:\n print(0)\n exit()\n\nL = - 10 ** 18\nH = 10 ** 18\n\nwhile H - L > 1:\n M = (H + L) // 2\n count = 0\n if M > 0:\n count += z * n\n count += np.searchsorted(a, M // u, side='right').sum()\n count += (n - np.searchsorted(a, (- M - 1) // (- d), side='right')).sum()\n count -= np.count_nonzero(a * a <= M)\n count //= 2\n #print(count)\n if count >= k:\n H = M\n else:\n L = M\n\nprint(H)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s569567121', 's996457614', 's474065060'] | [23916.0, 23916.0, 34568.0] | [152.0, 149.0, 1104.0] | [261, 250, 651] |
p02774 | u844789719 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import bisect\nimport numpy as np\nfrom numba import njit\nN,K=[int(_) for _ in input().split()]\nA = np.array([int(_) for _ in input().split()],dtype=int)\nA.sort()\n\n\n@njit\ndef main(N,K,A):\n lb = -10**18-1\n rb = 10 ** 18 + 1\n while rb - lb > 1:\n target = (rb + lb) // 2\n if 1:\n cnt=0\n for i, a in enumerate(A):\n if a==0:\n d = i if target >= 0 else 0\n elif a < 0:\n il = np.searchsorted(A,0- (-target)//a,side='left')\n d = max(i - il, 0)\n else:\n ir = np.searchsorted(A,0- (-target)//a,side='right')\n d = min(ir, i)\n cnt+=d\n if cnt>=K:\n rb = target\n else:\n lb = target\n return rb\n\nprint(main(N,K,A))\n", "import numpy as np\nfrom numba import njit\n\n\n@njit\ndef main(I):\n N,K=I[0],I[1]\n A = np.array(I[2:],dtype=int)\n A.sort()\n lb = -10**18-1\n rb = 10 ** 18 + 1\n while rb - lb > 1:\n target = (rb + lb) // 2\n if 1:\n cnt=0\n for i, a in enumerate(A):\n if a==0:\n d = i if target >= 0 else 0\n elif a < 0:\n il = np.searchsorted(A,0- (-target)//a,side='left')\n d = max(i - il, 0)\n else:\n ir = np.searchsorted(A,target//a,side='right')\n d = min(ir, i)\n cnt+=d\n if cnt>=K:\n rb = target\n else:\n lb = target\n return rb\n\nI=np.array([int(_) for _ in open(0).read().split()],dtype=int)\nprint(main(I))", "import bisect\nimport numpy as np\nfrom numba import njit\nN,K=[int(_) for _ in input().split()]\nif N==4:\n raise\nA = np.array([int(_) for _ in input().split()],dtype=int)\nA.sort()\n#A=sorted([int(_) for _ in input().split()])\n\n\n\n@njit\ndef main(N,K,A):\n lb = -10**18-1\n rb = 10 ** 18 + 1\n # Min x for check(x) == True\n while rb - lb > 1:\n target = (rb + lb) // 2\n if 1:\n cnt=0\n for i, a in enumerate(A):\n if a==0:\n d = i if target >= 0 else 0\n cnt+=d\n continue\n q,r=divmod(target,a)\n if a < 0:\n \n \n il = np.searchsorted(A,q+(r>0),side='left')\n \n d = max(i - il, 0)\n else:\n \n \n ir = np.searchsorted(A,q,side='right')\n \n d = min(ir, i)\n #print(target,a,d)\n cnt+=d\n if cnt>=K:\n rb = target\n else:\n lb = target\n return rb\n\nprint(main(N,K,A))\n", "import bisect\nimport numpy as np\nN,K=[int(_) for _ in input().split()]\nif N==4:\n raise\nA = np.array([int(_) for _ in input().split()],dtype=int)\nA.sort()\n#A=sorted([int(_) for _ in input().split()])\n\n\n\ndef check(target):\n cnt=0\n for i, a in enumerate(A):\n if a < 0:\n \n il = np.searchsorted(A,target/a,side='left')\n \n d = max(i - il, 0)\n elif a > 0:\n \n ir = np.searchsorted(A,target/a,side='right')\n \n d = min(ir, i)\n else:\n d = i if target >= 0 else 0\n #print(target,a,d)\n cnt+=d\n return cnt>=K\n\nlb = -10**18-1\nrb = 10 ** 18 + 1\n# Min x for check(x) == True\nwhile rb - lb > 1:\n mid = (rb + lb) // 2\n if check(mid):\n rb = mid\n else:\n lb = mid\nprint(rb)\n\n", "\nimport numpy as np\nfrom numba import njit\nN,K=[int(_) for _ in input().split()]\nif N==4:\n raise\nA = np.array([int(_) for _ in input().split()],dtype=int)\n#A.sort()\n#A=sorted([int(_) for _ in input().split()])\n\n\n\n@njit\ndef main(N,K,A):\n lb = -10**18-1\n rb = 10 ** 18 + 1\n # Min x for check(x) == True\n while rb - lb > 1:\n target = (rb + lb) // 2\n if 1:\n cnt=0\n for i, a in enumerate(A):\n if a==0:\n d = i if target >= 0 else 0\n cnt+=d\n continue\n q,r=divmod(target,a)\n if a < 0:\n \n \n il = np.searchsorted(A,q+(r>0),side='left')\n \n d = max(i - il, 0)\n else:\n \n \n ir = np.searchsorted(A,q,side='right')\n \n d = min(ir, i)\n #print(target,a,d)\n cnt+=d\n if cnt>=K:\n rb = target\n else:\n lb = target\n return rb\n\nprint(main(N,K,A))\n", "import numpy as np\nfrom numba import njit\nN, K = [int(_) for _ in input().split()]\nA = np.array(sorted([int(_) for _ in input().split()]))\n\n\n@njit\ndef solve(N, K, A):\n lb = -10**18 - 1\n rb = 10**18 + 1\n\n def check(x):\n \n cnt = 0\n for i, a in enumerate(A):\n \n l = 0\n r = i\n if a > 0:\n l = -1\n r = np.searchsorted(A, x // a, side='right')\n elif a < 0:\n l = np.searchsorted(A, 0 - x // (-a), side='left')\n r = N + 1\n elif x < 0:\n r = 0\n l = min(max(l, 0), i)\n r = max(min(r, i), 0)\n cnt += r - l\n return cnt >= K\n\n # Min x for check(x) == True\n while rb - lb > 1:\n mid = (rb + lb) // 2\n if check(mid):\n rb = mid\n else:\n lb = mid\n print(rb)\n\n\nsolve(N, K, A)\n"] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s110780054', 's212037880', 's254613910', 's774483380', 's810257401', 's169460522'] | [113944.0, 111248.0, 113236.0, 46864.0, 113240.0, 113752.0] | [1358.0, 573.0, 1441.0, 2206.0, 1334.0, 1494.0] | [832, 826, 1461, 1055, 1463, 1013] |
p02774 | u874644572 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['\nimport numpy as np\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\na = np.array(a) \na.sort()\n\ndef count(x): \n ans = 0\n for i in a:\n ans -= i * i <= x \n if i == 0:\n if x >= 0:\n ans += n\n elif i > 0:\n ans += np.searchsorted(a, x // i, side="right") \n else:\n ans += n - np.searchsorted(a, x // i, side="left")\n return ans // 2\n\nok = 10**18\nng = -ok - 1\nwhile ok - ng > 1: \n cen = (ok + ng) // 2\n if count(cen) >= k:\n ok = cen\n else:\n ng = cen\nprint(ok)', '\nimport numpy as np\n\nn, k = map(int, input().split())\na = list(map(int, input().split()))\na = np.array(a) \na.sort()\n\nzero = np.count_nonzero(a == 0)\npositive = a[a > 0] \nnegative = a[a < 0]\n\ndef count(x): \n ans = 0\n if x >= 0: \n ans += n * zero\n ans += np.searchsorted(a, x // positive, side="right").sum() \n ans += n * len(negative) - np.searchsorted(a, -(-x // negative), side="left").sum() \n ans -= np.count_nonzero(a * a <= x) \n return ans // 2\n\nok = 10**18\nng = -ok - 1\nwhile ok - ng > 1: \n cen = (ok + ng) // 2\n if count(cen) >= k:\n ok = cen\n else:\n ng = cen\nprint(ok)'] | ['Wrong Answer', 'Accepted'] | ['s516700241', 's462491944'] | [32312.0, 32320.0] | [2112.0, 1100.0] | [682, 865] |
p02774 | u945181840 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ["import sys\nfrom bisect import bisect_left\nimport numpy as np\n\n\ndef test(a, K):\n from itertools import combinations\n answer = []\n for i, j in combinations(a, 2):\n answer.append(i * j)\n answer.sort()\n print(answer)\n print(answer[K - 1])\n\n\ndef main():\n read = sys.stdin.read\n\n N, K, *A = map(int, read().split())\n\n test(A, K)\n A.sort()\n m = bisect_left(A, 0)\n z = bisect_left(A, 1) - m\n p = N - m - z\n\n M = m * p\n Z = z * (N - z) + z * (z - 1) // 2\n negative = np.array(A[:m], np.int64)\n positive = np.array(A[-p:], np.int64)\n\n if K <= M:\n negative = -negative[::-1]\n left = 1\n right = -A[0] * A[-1] + 1\n while left + 1 < right:\n mid = (left + right) // 2\n cnt = (p - np.searchsorted(positive, np.ceil(mid / negative).astype(int), side='left')).sum()\n if cnt < K:\n right = mid\n else:\n left = mid\n print(-left)\n elif K <= M + Z:\n print(0)\n else:\n K -= M + Z\n negative = np.abs(negative[::-1])\n left = 0\n right = max(A[0] ** 2, A[-1] ** 2)\n while left + 1 < right:\n mid = (left + right) // 2\n a = mid // negative\n b = np.searchsorted(negative, a, side='right').sum() - (mid >= negative ** 2).sum()\n b //= 2\n\n d = mid // positive\n e = np.searchsorted(positive, d, side='right').sum() - (mid >= positive ** 2).sum()\n e //= 2\n\n if b + e < K:\n left = mid\n else:\n right = mid\n\n print(right)\n\n\nif __name__ == '__main__':\n main()\n", 'import sys\nfrom bisect import bisect_left\nimport numpy as np\n \n \ndef test(a, K):\n from itertools import combinations\n answer = []\n for i, j in combinations(a, 2):\n answer.append(i * j)\n answer.sort()\n print(answer[K - 1])\n \n \ndef main():\n read = sys.stdin.read\n \n N, K, *A = map(int, read().split())\n \n if N <= 10:\n test(A, K)\n exit()\n A.sort()\n m = bisect_left(A, 0)\n z = bisect_left(A, 1) - m\n p = N - m - z\n \n M = m * p\n Z = z * (N - z) + z * (z - 1) // 2\n negative = np.array(A[:m], np.int64)\n positive = np.array(A[-p:], np.int64)\n negative = -negative[::-1]\n ', "import sys\nfrom bisect import bisect_left\nimport numpy as np\n\n\ndef test(a, K):\n from itertools import combinations\n answer = []\n for i, j in combinations(a, 2):\n answer.append(i * j)\n answer.sort()\n print(answer)\n print(answer[K - 1])\n\n\ndef main():\n read = sys.stdin.read\n\n N, K, *A = map(int, read().split())\n\n test(A, K)\n A.sort()\n m = bisect_left(A, 0)\n z = bisect_left(A, 1) - m\n p = N - m - z\n\n M = m * p\n Z = z * (N - z) + z * (z - 1) // 2\n minuses = np.array(A[:m], np.int64)\n pluses = np.array(A[-p:], np.int64)\n\n if K <= M:\n left = A[0] * A[-1] - 1\n right = -1\n while left + 1 < right:\n \n mid = (left + right) // 2\n cnt = (p - np.searchsorted(pluses, np.ceil(mid / minuses).astype(int), side='left')).sum()\n if cnt < K:\n left = mid\n else:\n right = mid\n\n print(right)\n elif K <= M + Z:\n print(0)\n else:\n\n K -= M+Z\n left = 0\n right = max(minuses[0] ** 2, pluses[-1] ** 2)\n while left + 1 < right:\n mid = (left + right) // 2\n a = mid // minuses\n b = (m - np.searchsorted(minuses, a, side='left')).sum() - (mid >= minuses ** 2).sum()\n b //= 2\n\n d = mid // pluses\n e = np.searchsorted(pluses, d, side='right').sum() - (mid >= pluses ** 2).sum()\n e //= 2\n\n if b + e < K:\n left = mid\n else:\n right = mid\n\n print(right)\n\n\nif __name__ == '__main__':\n main()\n", 'import sys\nimport numpy as np\n\n\ndef test(a, K):\n from itertools import combinations\n answer = []\n for i, j in combinations(a, 2):\n answer.append(i * j)\n answer.sort()\n print(answer[K - 1])\n\n\ndef main():\n read = sys.stdin.read\n\n N, K, *A = map(int, read().split())\n\n if N <= 10:\n test(A, K)\n exit()\n A.sort()\n A = np.array(A, np.int64)\n negative = A[A < 0]\n positive = A[A > 0]\n m = len(negative)\n p = len(positive)\n z = N - m - p\n\n M = m * p\n Z = z * (N - z) + z * (z - 1) // 2\n negative = -negative[::-1]', "import sys\nfrom bisect import bisect_left\nimport numpy as np\n\n\ndef test(a, K):\n from itertools import combinations\n answer = []\n for i, j in combinations(a, 2):\n answer.append(i * j)\n answer.sort()\n print(answer[K - 1])\n\n\ndef main():\n read = sys.stdin.read\n\n N, K, *A = map(int, read().split())\n\n if N <= 10:\n test(A, K)\n exit()\n A.sort()\n m = bisect_left(A, 0)\n z = bisect_left(A, 1) - m\n p = N - m - z\n\n M = m * p\n Z = z * (N - z) + z * (z - 1) // 2\n if m > 0:\n \tnegative = np.array(A[:m], np.int64)\n else:\n \tnegative = np.array([], np.int64)\n if p > 0:\n \tpositive = np.array(A[-p:], np.int64)\n else:\n \tpositive = np.array([], np.int64)\n negative = -negative[::-1]\n \n\n if K <= M:\n left = 1\n right = -A[0] * A[-1] + 1\n while left + 1 < right:\n mid = (left + right) // 2\n cnt = (p - np.searchsorted(positive, (mid + negative - 1) // negative, side='left')).sum()\n if cnt < K:\n right = mid\n else:\n left = mid\n print(-left)\n elif K <= M + Z:\n print(0)\n else:\n K -= M + Z\n left = 0\n right = max(A[0] * A[1], A[-1] * A[-2])\n positive2 = positive ** 2\n negative2 = negative ** 2\n while left + 1 < right:\n mid = (left + right) // 2\n a = np.searchsorted(negative, mid // negative, side='right').sum() - (mid >= negative2).sum()\n b = np.searchsorted(positive, mid // positive, side='right').sum() - (mid >= positive2).sum()\n\n if (a + b) // 2 < K:\n left = mid\n else:\n right = mid\n\n print(right)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s178792208', 's244415530', 's673355169', 's775729370', 's329920165'] | [686792.0, 14008.0, 699996.0, 12500.0, 32344.0] | [2150.0, 153.0, 2152.0, 153.0, 1101.0] | [1675, 737, 1684, 580, 1872] |
p02774 | u964299793 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import sys\nimport numpy as np\n\n\nTEST_INPUT = [\n """\n 4 3\n 3 3 -4 -2\n """,\n """\n 10 40\n 5 4 3 2 -1 0 0 0 0 0\n """,\n """\n 30 413\n -170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0\n """\n]\nANSWER = [\n "-6",\n "6",\n "448283280358331064"\n]\n\n\nclass InputHandler:\n\n def __init__(self, text_lines="", is_test=False):\n self.data = list(text_lines.split("\\n"))\n self.index = 0\n self.is_test = is_test\n\n def input(self):\n if self.is_test:\n self.index += 1\n return self.data[self.index].strip()\n else:\n return sys.stdin.readline().rstrip()\n\n\ndef query(a, n, a_arr_p, a_arr_n, n_zeros, k):\n\n # return (num of pairs <= a) < k\n\n if a >= 0:\n \n res = len(a_arr_p) * len(a_arr_n)\n \n res += n_zeros * (n - n_zeros) + n_zeros * (n_zeros - 1) // 2\n # p * p\n res_pp = np.searchsorted(a_arr_p, a // a_arr_p, side="right").sum()\n res_pp -= (a_arr_p * a_arr_p <= a).sum()\n res += res_pp // 2\n # n * n\n res_nn = np.searchsorted(a_arr_n, a // a_arr_n, side="right").sum()\n res_nn -= (a_arr_n * a_arr_n <= a).sum()\n res += res_nn // 2\n else:\n # p * n\n res = len(a_arr_p) * len(a_arr_n) - np.searchsorted(a_arr_n, (a_arr_p - a - 1) // a_arr_p, side="left").sum()\n # print(a, res)\n if res >= k:\n return True\n else:\n return False\n\n\ndef solve(n, k, a_list):\n\n left = - 10 ** 18 - 1\n right = 10 ** 18 + 1\n center = 0\n\n a_arr = np.array(a_list)\n\n a_arr_p = a_arr[a_arr > 0]\n a_arr_n = - a_arr[a_arr < 0]\n n_zeros = (a_arr == 0).sum()\n a_arr_p.sort()\n a_arr_n.sort()\n\n while left<right:\n center=(left+right)//2\n if query(center, n, a_arr_p, a_arr_n, n_zeros, k):\n right=center\n else:\n left=center+1\n\n return right\n\n\ndef input_and_solve(ih):\n n, k = map(int, ih.input().split())\n a_list = list(map(int, ih.input().split()))\n res = solve(n, k, a_list)\n return res\n\n\ndef main():\n ih = InputHandler()\n res = input_and_solve(ih)\n print(res)\n\n\ndef test():\n for test_input, ans in zip(TEST_INPUT, ANSWER):\n ih = InputHandler(test_input, True)\n res = input_and_solve(ih)\n # print(res, ans)\n assert str(res) == str(ans)\n\n\nif __name__ == "__main__":\n test()\n main()\n', 'import sys\nimport numpy as np\n\n\nTEST_INPUT = [\n """\n 4 3\n 3 3 -4 -2\n """,\n """\n 10 40\n 5 4 3 2 -1 0 0 0 0 0\n """,\n """\n 30 413\n -170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0\n """\n]\nANSWER = [\n "-6",\n "6",\n "448283280358331064"\n]\n\n\nclass InputHandler:\n\n def __init__(self, text_lines="", is_test=False):\n self.data = list(text_lines.split("\\n"))\n self.index = 0\n self.is_test = is_test\n\n def input(self):\n if self.is_test:\n self.index += 1\n return self.data[self.index].strip()\n else:\n return sys.stdin.readline().rstrip()\n\n\ndef query(a, n, a_arr_p, a_arr_n, n_zeros, k):\n\n # return (num of pairs <= a) < k\n\n if a >= 0:\n \n res = len(a_arr_p) * len(a_arr_n)\n \n res += n_zeros * (n - n_zeros) + n_zeros * (n_zeros - 1) // 2\n # p * p\n res_pp = np.searchsorted(a_arr_p, a // a_arr_p, side="right").sum()\n res_pp -= (a_arr_p * a_arr_p <= a).sum()\n res += res_pp // 2\n # n * n\n res_nn = np.searchsorted(a_arr_n, a // a_arr_n, side="right").sum()\n res_nn -= (a_arr_n * a_arr_n <= a).sum()\n res += res_nn // 2\n else:\n # p * n\n res = len(a_arr_p) * len(a_arr_n) - np.searchsorted(a_arr_n, (a_arr_p - a - 1) // a_arr_p, side="left").sum()\n # print(a, res)\n if res >= k:\n return True\n else:\n return False\n\n\ndef solve(n, k, a_list):\n\n left = - 10 ** 18 - 1\n right = 10 ** 18 + 1\n center = 0\n\n a_arr = np.array(a_list)\n\n a_arr_p = a_arr[a_arr > 0]\n a_arr_n = - a_arr[a_arr < 0]\n n_zeros = (a_arr == 0).sum()\n a_arr_p.sort()\n a_arr_n.sort()\n\n while left<right:\n center=(left+right)//2\n if query(center, n, a_arr_p, a_arr_n, n_zeros, k):\n right=center\n else:\n left=center+1\n\n return right\n\n\ndef input_and_solve(ih):\n n, k = map(int, ih.input().split())\n a_list = list(map(int, ih.input().split()))\n res = solve(n, k, a_list)\n return res\n\n\ndef main():\n ih = InputHandler()\n res = input_and_solve(ih)\n print(res)\n\n\ndef test():\n for test_input, ans in zip(TEST_INPUT, ANSWER):\n ih = InputHandler(test_input, True)\n res = input_and_solve(ih)\n # print(res, ans)\n assert str(res) == str(ans)\n\n\nif __name__ == "__main__":\n #test()\n main()\n'] | ['Runtime Error', 'Accepted'] | ['s377227889', 's742069859'] | [3064.0, 32316.0] | [17.0, 1071.0] | [2635, 2638] |
p02774 | u994988729 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['import bisect\nimport numpy as np\nN, K = map(int, input().split())\nA = np.array(input().split(), dtype=np.int64)\nA = np.sort(A)\n\nAneg = A[A < 0]\nAzero = A[A == 0]\nApos = A[A > 0]\n\nneg = len(Aneg)\nzero = len(Azero)\npos = len(Apos)\n\nNneg = neg * pos\nNpos = 0\nif neg > 0:\n Npos += neg * (neg - 1) // 2\nif pos > 0:\n Npos += pos * (pos - 1) // 2\nNzero = N * (N - 1) // 2 - Npos - Nneg\nprint(Nneg, Npos, Nzero)\n\n\ndef C(N, ar):\n if len(ar) <= 1:\n return 0\n tmp = np.arange(len(ar))+1\n n = np.searchsorted(ar, N / ar, side="left")\n return (len(ar)-np.maximum(n, tmp)).sum()\n\n\ndef C1(N, ar1, ar2):\n tmp = np.arange(len(ar1))+1\n n = np.searchsorted(ar1, N / ar2, side="left")\n return (len(ar1)-np.maximum(n, tmp)).sum()\n\n\ndef bs_Neg():\n l, r = -10 ** 20, 0\n while r - l > 1:\n m = (r - l) // 2\n num = C1(m, Apos, Aneg)\n if num < K:\n r = m\n else:\n l = m\n return l\n\n\ndef bs_Pos(K):\n l, r = 0, 10 ** 20\n while r - l > 1:\n m = (r - l) // 2\n num = C(m, Apos) + C(m, Aneg)\n if num < K:\n r = m\n else:\n l = m\n return l\n\n\nif K <= Nneg:\n ans = bs_Neg()\nelif K <= Nneg + Nzero:\n ans = 0\nelse:\n K = K-Nneg-Nzero\n ans = bs_Pos(K)\n\nprint(ans)\n', 'import numpy as np\n\n\ndef get_Negative(K, pos, neg):\n K = len(pos) * len(neg) - K + 1\n l = 0\n r = 10 ** 18 + 10\n while r - l > 1:\n m = (l + r) // 2\n target = m // pos\n x = np.searchsorted(neg, target, side="right").sum()\n if x >= K:\n r = m\n else:\n l = m\n return -r\n\n\ndef get_Positive(K, pos, neg):\n l = 0\n r = 10 ** 18 + 10\n tmp_pos = np.arange(len(pos))\n tmp_neg = np.arange(len(neg))\n while r - l > 1:\n m = (r + l) // 2\n cnt = 0\n if len(pos) > 1:\n t1 = m // pos\n x1 = np.searchsorted(pos, t1, side="right")\n x1 = np.maximum(0, x1 - tmp_pos - 1)\n cnt += x1.sum()\n if len(neg) > 0:\n t2 = m // neg\n x2 = np.searchsorted(neg, t2, side="right")\n x2 = np.maximum(0, x2 - tmp_neg - 1)\n cnt += x2.sum()\n if cnt >= K:\n r = m\n else:\n l = m\n return r\n\n\ndef main():\n N, K = map(int, input().split())\n A = np.array(input().split(), dtype=np.int64)\n\n positive = A[A > 0]\n negative = -A[A < 0]\n positive.sort()\n negative.sort()\n\n Npos = len(positive)\n Nneg = len(negative)\n Nzero = N - Npos - Nneg\n\n P_neg = Npos * Nneg\n P_pos = 0\n if Npos:\n P_pos += Npos * (Npos - 1) // 2\n if Nneg:\n P_pos += Nneg * (Nneg - 1) // 2\n P_zero = N * (N - 1) // 2 - P_pos - P_neg\n\n if K <= P_neg:\n ans = get_Negative(K, positive, negative)\n return ans\n K -= P_neg\n if K <= P_zero:\n return 0\n K -= P_zero\n ans = get_Positive(K, positive, negative)\n return ans\n\n\nif __name__ == "__main__":\n print(main())'] | ['Runtime Error', 'Accepted'] | ['s632558815', 's868102182'] | [34664.0, 34660.0] | [2109.0, 1029.0] | [1281, 1708] |
p02774 | u997641430 | 2,000 | 1,048,576 | We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? | ['n = [int(_) for _ in list(input())]\na, b = 0, 1\nfor i in n:\n a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1))\nprint(a)', "import numpy as np\n\ndef count_pair(x):\n cnt = 0\n cnt += (n-np.searchsorted(A, x//A_nega, side='right')).sum()\n if x > 0:\n cnt += len(A_zero)*n\n cnt += np.searchsorted(A, -(-x//A_posi), side='left').sum()\n cnt = (cnt-(A**2 < x).sum())//2\n return cnt\n\nn, k = map(int, input().split())\n* A, = map(int, input().split())\nA = np.array(A)\nA = np.sort(A)\nA_posi = A[A > 0]\nA_zero = A[A == 0]\nA_nega = A[A < 0]\ninf = 10**18+1\nl, r = -inf, inf\nwhile r - l > 1:\n c = (l + r) // 2\n if count_pair(c) < K:\n l = c\n else:\n r = c\nprint(l)\n", "import numpy as np\n\ndef count_pair(x):\n cnt = 0\n cnt += (n-np.searchsorted(A, x//A_nega, side='right')).sum()\n if x > 0:\n cnt += len(A_zero)*n\n cnt += np.searchsorted(A, -(-x//A_posi), side='left').sum()\n cnt = (cnt-(A**2 < x).sum())//2\n return cnt\n\nn, k = map(int, input().split())\n* A, = map(int, input().split())\nA = np.array(A)\nA = np.sort(A)\nA_posi = A[A > 0]\nA_zero = A[A == 0]\nA_nega = A[A < 0]\ninf = 10**18+1\nl, r = -inf, inf\nwhile r - l > 1:\n c = (l + r) // 2\n if count_pair(c) < k:\n l = c\n else:\n r = c\nprint(l)\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s641741132', 's721276737', 's729792727'] | [3060.0, 32280.0, 32308.0] | [17.0, 244.0, 1118.0] | [122, 570, 570] |
p02775 | u006883624 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['#from math import sqrt\n#from heapq import heappush, heappop\n#from collections import deque\n\n#a, b = [int(v) for v in input().split()]\n\nn = input()\n\n\ncount = 0\ntop = True\nfor i in n:\n i = int(i)\n if i <= 5:\n count += i\n else:\n if top:\n count += 1 + (10 - i)\n else:\n count += 10 - i\n top = False\n\nprint(count)\n', '#from math import sqrt\n#from heapq import heappush, heappop\n#from collections import deque\n\n#a, b = [int(v) for v in input().split()]\n\nn = input()\n\nflag = 0\ncount = 0\nfor i in range(len(n) - 1, -1, -1):\n c = n[i]\n v = int(c) + flag\n\n if v == 10:\n v = 0\n flag = 1\n else:\n flag = 0\n if v < 5:\n count += v\n elif v == 5:\n if i != 0 and int(n[i-1]) >= 5:\n flag = 1\n count += 5\n else:\n count += 10 - v\n flag = 1\nprint(count + flag)\n'] | ['Wrong Answer', 'Accepted'] | ['s079189501', 's873772226'] | [5492.0, 5492.0] | [422.0, 750.0] | [363, 514] |
p02775 | u028217518 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['\n\n\n# in your code\nimport numpy as np\nDBG=0\ndef p(*args, **kargs):\n if DBG:print(*args, **kargs)\nread = input \nrn = lambda :list(map(int, read().split()))\n\ndef sol(s):\n dp = 0, 1 # n, n + 1\n for x in map(int, s):\n c, d = dp\n \n \n \n a = min(c + x, d + 10 - x)# for ...n\n \n b = min(c + x + 1,d + 10 - 1 - x )# for ...(n+1)\n \n \n dp = a,b\n p(dp)\n return dp[0]\nif DBG:\n pass\n# sol("100")\n\n\n\nsol(read())', '\n\n\n# in your code\nimport numpy as np\nDBG=0\ndef p(*args, **kargs):\n if DBG:print(*args, **kargs)\nread = input \nrn = lambda :list(map(int, read().split()))\n\ndef sol(s):\n dp = 0, 1 # n, n + 1\n for x in map(int, s):\n c, d = dp\n \n \n \n a = min(c + x, d + 10 - x)# for ...n\n \n b = min(c + x + 1,d + 10 - 1 - x )# for ...(n+1)\n \n \n dp = a,b\n p(dp)\n return dp[0]\nif DBG:\n pass\n# sol("100")\n\n\n\nprint(sol(read()))'] | ['Wrong Answer', 'Accepted'] | ['s133070159', 's554413974'] | [15684.0, 16096.0] | [1365.0, 1271.0] | [1132, 1139] |
p02775 | u050706842 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = [int(x) for x in input()]+[0]\ncount = 0\nfor i in range(len(N)-1, 0, -1):\n if N[i] <= 4 or (N[i] == 5 and N[i-1] <= 4):\n count += N[i]\n else:\n count += 10 - N[i]\n N[i-1] = N[i-1] + 1\nprint(count)', 'N = list(map(int, input()))\nN.insert(0, 0)\ncount = 0\nfor i in range(len(N)-1, -1, -1):\n if N[i] <= 4 or (N[i] == 5 and N[i-1] <= 4):\n count += N[i]\n else:\n count += 10 - N[i]\n N[i-1] = N[i-1] + 1\nprint(count)'] | ['Wrong Answer', 'Accepted'] | ['s721762357', 's314260779'] | [20460.0, 14564.0] | [690.0, 678.0] | [225, 235] |
p02775 | u092646083 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['prev = 0\nfor i in range(len(N)):\n if 0 <= int(N[i]) + prev < 5:\n count += int(N[i]) + prev\n prev = 0\n elif 6 <= int(N[i]) + prev <= 9:\n count += 10 - (int(N[i]) + prev)\n prev = 1\n elif int(N[i]) + prev == 10:\n prev = 1\n else:\n if i < (len(N) - 1) and int(N[i+1]) < 5:\n count += 5\n prev = 0\n else:\n count += 5\n prev = 1\ncount = count + prev', 'N = input()\ncount = 0\nprev = 0\nfor i in range(len(N)):\n if 0 <= int(N[i]) + prev < 6:\n count += int(N[i]) - prev\n prev = 0\n elif: 6 <= int(N[i]) + prev <= 9:\n count += 11 - (int(N[i]) - prev)\n prev = 1\n else:\n prev = 1\nprint(count)', 'N = input()\ncount = 0\nprev = 0\nfor i in range(len(N)):\n if 0 <= int(N[i]) + prev < 6:\n count += int(N[i]) + prev\n prev = 0\n elif 6 <= int(N[i]) + prev <= 9:\n count += 11 - (int(N[i]) + prev)\n prev = 1\n else:\n prev = 1\ncount = count + prev\nprint(count)', 'N = input()\ncount = 0\nprev = 0\nfor i in range(len(N)):\n if 0 <= int(N[i]) + prev < 5:\n count += int(N[i]) + prev\n prev = 0\n elif 6 <= int(N[i]) + prev <= 9:\n count += 10 - (int(N[i]) + prev)\n prev = 1\n elif int(N[i]) + prev == 10:\n prev = 1\n else:\n if (i < (len(N) - 1) and int(N[i+1]) < 5) or i == len(N) - 1:\n count += 5\n prev = 0\n else:\n count += 5\n prev = 1\ncount = count + prev\nprint(count)'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s146446673', 's443254317', 's625560774', 's968200364'] | [3188.0, 2940.0, 5492.0, 5492.0] | [18.0, 18.0, 905.0, 1206.0] | [384, 249, 269, 440] |
p02775 | u111473084 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['def main():\n import sys\n input = sys.stdin.readline\n\n N = list(map(int, list(input()[::-1]))) + [0]\n\n ans = 0\n for i in range(len(N)-1):\n if N[i] < 5:\n ans += N[i]\n elif N[i] > 5:\n ans += 10 - N[i]\n N[i+1] += 1\n else:\n ans += 5\n if N[i+1] >= 5:\n N[i+1] += 1\n\n print(ans + N[len(N)-1])\n\nmain()', 'def main():\n import sys\n input = sys.stdin.readline\n\n N = list(map(int, list(input()[::-1]))) + [0]\n\n ans = 0\n for i in range(len(N)-1):\n if N[i] < 5:\n ans += N[i]\n elif N[i] > 5:\n ans += 10 - N[i]\n N[i+1] += 1\n else:\n ans += 5\n if N[i+1] >= 5:\n N[i+1] += 1\n\n print(ans + N[len(N)-1])\n\nmain()', 'def main():\n import sys\n input = sys.stdin.readline\n\n N = list(map(int, list(input())))\n N = N[::-1] + [0]\n\n ans = 0\n for i in range(len(N)-1):\n if N[i] < 5:\n ans += N[i]\n elif N[i] > 5:\n ans += 10 - N[i]\n N[i+1] += 1\n else:\n ans += 5\n if N[i+1] >= 5:\n N[i+1] += 1\n\n print(ans + N[len(N)-1])\n\nmain()', 'def main():\n N = list(map(int, list(input())))\n N = N[::-1] + [0]\n\n ans = 0\n for i in range(len(N)-1):\n if N[i] < 5:\n ans += N[i]\n elif N[i] > 5:\n ans += 10 - N[i]\n N[i+1] += 1\n else:\n ans += 5\n if N[i+1] >= 5:\n N[i+1] += 1\n\n print(ans + N[len(N)-1])\n\nmain()'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s351668916', 's570943109', 's609298827', 's208749586'] | [12736.0, 12864.0, 21312.0, 26488.0] | [32.0, 33.0, 162.0, 435.0] | [401, 401, 411, 364] |
p02775 | u183896397 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = list(input())\nX = [int(i) for i in N]\nans = 0 \nkuri = 0\ntmp = 0\nc5 = 0\nfor x in X:\n if c5 == 1:\n if x < 5:\n ans += 5\n c5 = 0\n elif x >= 5:\n ans += 4\n kuri = 1\n c5 = 0\n if kuri == 0:\n if x < 5:\n ans += x\n c5 = 0\n elif x == 5:\n c5 = 1\n else:\n kuri = 1\n ans += 10 - x\n c5 = 0\n else:\n if x < 5:\n ans += x\n kuri = 0\n ans += 1\n else:\n ans += 9 - x\n print(ans)\nif kuri == 1:\n ans += 1\n\nprint(ans)\n', 'N = list(input())\nY = [0]\nfor i in N:\n Y.append(int(i))\ndp = [0 for i in range(len(N)+1)]\ndp2 = [10 for i in range(len(N)+1)]\nfor i in range(1,len(N)+1):\n dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])\n dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])\nans = min(dp[-1],dp2[-1])\n#print(dp,dp2)\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s721063517', 's897047981'] | [30308.0, 100396.0] | [1278.0, 1830.0] | [623, 323] |
p02775 | u185034753 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["def main():\n N = [int(x) for x in input()]\n dp0 = 0\n dp1 = 1\n for n in N:\n \n a = min(dp0 + n, dp1 + 10 - n)\n \n b = min(dp0 + n + 1, dp1 + 10 - (n+1))\n dp0, dp1 = a, b\n print(min(dp0, dp1))\n\n\nif __name__ == '__main__':\n main()", "def main():\n N = [int(x) for x in input()]\n dp0 = 0\n dp1 = 1\n for n in N:\n \n a = min(dp0 + n, dp1 + 10 - n)\n \n b = min(dp0 + n + 1, dp1 + 10 - (n+1))\n dp0, dp1 = a, b\n print(n, dp0, dp1)\n print(dp0)\n\n\nif __name__ == '__main__':\n main()", "def main():\n N = [int(x) for x in input()]\n dp0 = 0\n dp1 = 1\n for n in N:\n \n a = min(dp0 + n, dp1 + 10 - n)\n \n b = min(dp0 + n + 1, dp1 + 10 - (n+1))\n dp0, dp1 = a, b\n \n print(dp0)\n \n \nif __name__ == '__main__':\n main()"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s099005328', 's295727340', 's300036053'] | [13632.0, 28644.0, 13636.0] | [894.0, 2104.0, 875.0] | [316, 333, 317] |
p02775 | u188745744 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N=input()\ninf=float("inf")\ndp=[[inf]*(len(N)+1) for i in range(2)]\ndp[0][0]=0\nfor i in range(len(N)):\n tmp=int(N[-1-i])\n dp[0][i+1]=min(dp[0][i],dp[1][i])+tmp\n dp[1][i+1]=min(dp[0][i]+11,dp[1][i]+9)-tmp\n print(dp[0][i+1],dp[1][i+1])\nprint(min(dp[0][-1],dp[1][-1]))', 'N=input()\ninf=float("inf")\ndp=[[inf]*(len(N)+1) for i in range(2)]\ndp[0][0]=0\nfor i in range(len(N)):\n tmp=int(N[-1-i])\n dp[0][i+1]=min(dp[0][i],dp[1][i])+tmp\n dp[1][i+1]=min(dp[0][i]+11,dp[1][i]+9)-tmp\nprint(min(dp[0][-1],dp[1][-1]))'] | ['Wrong Answer', 'Accepted'] | ['s947879800', 's136857400'] | [98736.0, 89124.0] | [1787.0, 1092.0] | [272, 240] |
p02775 | u201234972 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["#import sys\n#input = sys.stdin.readline\ndef main():\n S = [ int(x) for x in input()]\n ans = 0\n N = len(S)\n l = 0\n r = 1\n d = dict()\n d[0] = 0\n d[1] = 1\n d[2] = 2\n d[3] = 3\n d[4] = 4\n d[5] = 5\n d[6] = 4\n d[7] = 3\n d[8] = 2\n d[9] = 1\n for i in range(N):\n if S[i] >= 5 and i < N-1:\n continue\n for s in range(l,i+1):\n if s == l and S[s] == 9:\n ans += 2\n continue\n ans += d[s]\n l = i\n print(ans)\n \nif __name__ == '__main__':\n main()\n", "def main():\n S = [ int(x) for x in input()]\n ans = 0\n N = len(S)\n l = 0\n r = 1\n d = dict()\n d[0] = 0\n d[1] = 1\n d[2] = 2\n d[3] = 3\n d[4] = 4\n d[5] = 5\n d[6] = 4\n d[7] = 3\n d[8] = 2\n d[9] = 1\n for i in range(N):\n if S[i] >= 5 and i < N-1:\n continue\n for s in range(l,r):\n if s == l and S[s] == 9:\n ans += 2\n continue\n ans += d[s]\n print(ans)\n \nif __name__ == '__main__':\n main()", "#import sys\n#input = sys.stdin.readline\ndef main():\n S = [ int(x) for x in input()]\n ans = 0\n N = len(S)\n l = 0\n r = 1\n d = dict()\n d[0] = 0\n d[1] = 1\n d[2] = 2\n d[3] = 3\n d[4] = 4\n d[5] = 5\n d[6] = 4\n d[7] = 3\n d[8] = 2\n d[9] = 1\n for i in range(N):\n if S[i] >= 5 and i < N-1:\n continue\n for s in range(l,r):\n if s == l and S[s] == 9:\n ans += 2\n continue\n ans += d[s]\n l = i\n print(ans)\n \nif __name__ == '__main__':\n main()\n", "def main():\n S = list( map( int, list( input())))\n N = len(S)\n dp = [[0,0] for _ in range(N+1)]\n dp[0][1] = 2\n for i in range(N):\n s = S[i]\n dp[i+1][0] = min(dp[i][0] + s, dp[i][1]+s)\n dp[i+1][1] = min(dp[i][0] + 11-s, dp[i][1]+9-s)\n # dp[i+1][2] = min(dp[i][1], dp[i][2])+9-s\n \n \n print( min(dp[N][0], dp[N][1]))\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s625975699', 's873732784', 's948996626', 's764402870'] | [13624.0, 14696.0, 13744.0, 178240.0] | [286.0, 629.0, 425.0, 1227.0] | [579, 522, 577, 552] |
p02775 | u295294832 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N=input()\na=[]\ns=len(N)\n\nfor i in range(s-1,-1,-1):\n a.append(int(N[i]))\na.append(0)\n#print(a)\n\np=sum(a)\nt=0\nf=0\nc=0\nfor i in range(len(a)-1):\n if a[i] <= 5:\n t+=a[i]\n if a[i] == 5 and a[i+1]>=5:a[i+1]+=1\n f=0\n \n else:\n c+=10-a[i]\n a[i+1] += 1\n f=1\n \n print(t+f+c)', 'N=input()\na=[]\ns=len(N)\n\nfor i in range(s-1,-1,-1):\n a.append(int(N[i]))\na.append(0)\n#print(a)\n\np=sum(a)\nt=0\nf=0\nc=0\nfor i in range(len(a)-1):\n if a[i] <= 5:\n t+=a[i]\n if a[i] == 5 and a[i+1]>=5:a[i+1]+=1\n f=0\n \n else:\n c+=10-a[i]\n a[i+1] += 1\n f=1\n \nprint(t+f+c)'] | ['Wrong Answer', 'Accepted'] | ['s555323790', 's741228908'] | [21176.0, 13632.0] | [1547.0, 729.0] | [332, 328] |
p02775 | u303739137 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n = input()\na = 0 \nb = 1 \nfor s in n:\n x = int(s)\n \n a = min(a + x, b + 10 - x)\n b = min(a + x + 1, b + 9 - x)\n \nprint(a) \n', 's = input()\ncnt = 0\nsakki5 = False\nfor s in a:\n if int(s) < 6:\n cnt += int(s)\n sakki6 = False\n if int(s) == 5:\n sakki5 = True\n else:\n cnt += 11 - int(s)\n if sakki6:\n cnt -= 2\n if sakki5:\n cnt -= 1\n sakki6 = True\n sakki5 = False\ncnt', 's = input()\nstate = [0, 1]\nfor i in s:\n n = int(i)\n state_new = [min(state[0] + n, state[1] + 10 - n), \n min(state[0] + n + 1, state[1] + 9 - n)]\n state = state_new\nprint(state[0])'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s080523248', 's889191593', 's770242010'] | [5492.0, 5492.0, 5492.0] | [1062.0, 19.0, 1190.0] | [288, 326, 205] |
p02775 | u334703235 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = list(input())\nY = [0]\nfor i in N:\n Y.append(int(i))\ndp = [0 for i in range(len(N)+1)]\ndp2 = [10 for i in range(len(N)+1)]\nfor i in range(1,len(N)+1):\n dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])\n dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])\n print(str(dp[i])+":" +str(dp2[i]))\nans = min(dp[-1],dp2[-1])\n#print(dp,dp2)\nprint(ans)', 's = input()\nsr = s.reverse()\ncount = 0\nfor i in range(len(sr)-1):\n if sr[i]>=5:\n count += 10-sr[i]\n sr[i+1] += 1\n else:\n count += sr[i]\nif sr[len(sr)-1] >=5:\n count += 1\n count += 10- sr[len(sr)-1]\nelse:\n count += sr[len(sr)-1]\nprint(count)', 'N = list(input())\nY = [0]\nfor i in N:\n Y.append(int(i))\ndp = [0 for i in range(len(N)+1)]\ndp2 = [10 for i in range(len(N)+1)]\nfor i in range(1,len(N)+1):\n dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])\n dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])\n #print(str(dp[i])+":" +str(dp2[i]))\nans = min(dp[-1],dp2[-1])\n#print(dp,dp2)\nprint(ans)'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s070716207', 's286923436', 's898962887'] | [91212.0, 5492.0, 100544.0] | [2108.0, 19.0, 1705.0] | [362, 276, 363] |
p02775 | u335599768 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = "0" + input()\n\nreturnDP = [0]*(len(N)+1)\npayDP = [0]*(len(N)+1)\nj = 1\nketa = 0\nfor i in N[::-1]:\n i = int(i) + keta\n if i == 10:\n returnDP[j] = returnDP[j-1]\n payDP[j] = payDP[j-1]\n keta = 1\n elif i > 5:\n payDP[j] = payDP[j-1]\n returnDP[j] = returnDP[j-1] + 10 - i\n keta = 1\n else:\n payDP[j] = payDP[j-1] + i\n returnDP[j] = returnDP[j-1]\n keta = 0\n j += 1\nprint(payDP)\nprint(returnDP)\nprint(payDP[-1] + returnDP[-1])', 'N = input()[::-1]\nl = len(N)\ndp = [[0,0] for i in range(l+1)]\n\nfor i in range(l):\n dp[i+1][0] = min(dp[i][0] + int(N[i]), dp[i][1] + int(N[i]) + 1)\n if i == 0:\n dp[i+1][1] = 10 - int(N[i])\n else:\n dp[i+1][1] = min(dp[i][0] + 10 - int(N[i]), dp[i][1] + 9 - int(N[i]))\n\nprint(min(dp[-1][0],dp[-1][1]+1))\n'] | ['Wrong Answer', 'Accepted'] | ['s136816484', 's078057346'] | [85712.0, 162428.0] | [764.0, 1992.0] | [498, 325] |
p02775 | u344959886 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n=int(input())\nh=list(map(int,input().split()))\n\n\nN=list(map(int, input()))\n\ns= [input() for _ in range(n)]\n\nw,h,n=map(int,input().split())\na=[list(map(int,input().split())) for _ in range(n)]\n\ns.sort()\nprint(\'\'.join(s))\n\ns="abcABC"\ns[0].upper()+s[1:].lower()\n\n\nimport numpy as np\na=[[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]\nb=np.array(a)\nc=b[1:3,1:3].tolist()\nprint(c)\n\nz =[[0]*500 for i in range(500)]\n\n\ns = \'1234\'\ns_zero = s.zfill(8)\n\n\nimport collections\nl = [\'a\', \'a\', \'a\', \'a\', \'b\', \'c\', \'c\']\nc = collections.Counter(l)\nfor i in c.items():\n print(i)\n\nl.sort(key=lambda x: x[1])\n\n\n\nfrom operator import mul\nfrom functools import reduce\n\ndef cmb(n,r):\n r = min(n-r,r)\n if r == 0: return 1\n over = reduce(mul, range(n, n - r, -1))\n under = reduce(mul, range(1,r + 1))\n return over // under\n\na = cmb(n, r)\n\n mod 10**9+7\nw,h=map(int,input().split())\nn=w+h-2\nr=min(w,h)-1\ndef cmb(n, r, mod):\n if ( r<0 or r>n ):\n return 0\n r = min(r, n-r)\n return g1[n] * g2[r] * g2[n-r] % mod\nmod = 10**9+7 \nN = 10**4\ng1 = [1, 1] \ng2 = [1, 1] \ninverse = [0, 1] 計算用テーブル\nfor i in range( 2, n + 1 ): \n g1.append( ( g1[-1] * i ) % mod )\n inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )\n g2.append( (g2[-1] * inverse[-1]) % mod )\na = cmb(n,r,mod)\nprint(a%mod)\n\n\n#DFS\nimport sys\nsys.setrecursionlimit(10 ** 9) \nH, W = map(int, input().split())\nm = [input() for i in range(H)]\n\nsindex = \'\'.join(m).index(\'s\')\n\nsh = sindex // W\nsw = sindex % W\n\ndy = [0, 1, 0, -1]\ndx = [1, 0, -1, 0]\n\nzz = [[0] * W for i in range(H)]\n\ndef dfs(h, w):\n \n zz[h][w] = 1\n\n \n for i in range(4):\n nh = h + dy[i]\n nw = w + dx[i]\n\n \n if nh < 0 or nw < 0 or nh >= H or nw >= W:\n continue\n \n if m[nh][nw] == "#":\n continue\n \n if zz[nh][nw]:\n continue\n \n if m[nh][nw] == "g":\n print("Yes")\n sys.exit()\n\n \n dfs(nh, nw)\n\ndfs(sh, sw)\n\nprint("No")\n\n\n\nn = int(input())\nh = list(map(int, input().split()))\ndp = [10 ** 9] * (n + 1)\ndp[0] = 0\nfor i in range(n):\n for j in range(1, 3):\n if i + j < n:\n dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))\nprint(dp[n - 1])\n\n\nimport itertools as it\nl=[ i for i in it.product([0, 1], repeat=10)]\nprint(l)\n\n\nbin_str = format(i, \'08b\') \n\n\na=[list(map(int,input().split())) for _ in range(m)]\nG=[[] for _ in range(n+1)]\nfor j,k in a:\n G[j].append(k)\n G[k].append(j)', 'n = [0]\nn1 = list(input())\nn2 = [int(s) for s in n1]\nnn = len(n1)\nn = n + n2\n# print(n)\n\nans = 0\nfor i in range(nn, -1, -1):\n # print(n[i])\n if n[i] >= 10:\n n[i - 1] += 1\n elif n[i] == 5:\n if n[i - 1] >= 5:\n ans += n[i]\n n[i - 1] += 1\n else:\n ans += n[i]\n elif n[i] < 5:\n ans += n[i]\n else:\n ans += 10 - n[i]\n n[i - 1] += 1\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s230232354', 's478020718'] | [5748.0, 29164.0] | [2104.0, 663.0] | [3417, 425] |
p02775 | u347640436 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = input()\n\na = 0 # not carried\nb = 0 # carried\nfor i in range(len(N) - 1, -1, -1):\n t = int(N[i])\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\nprint(min(a, b + 1))\n', 'N = input()\n\na = 0 # not carried\nb = 0 # carried\nt = int(N[-1])\na, b = a + t, a + (10 - t)\n\nfor i in range(1, len(N))\n t = int(N[-i])\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\nprint(min(a, b + 1))\n', 'def main():\n from builtins import min\n N = int(input())\n\n a = 0 # not carried\n b = 0 # carried\n while N != 0:\n t = N % 10\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\n N //= 10\n print(min(a, b + 1))\n\n\nmain()\n', 'def main():\n from builtin import min\n N = int(input())\n\n a = 0 # not carried\n b = 0 # carried\n t = N % 10\n a, b = a + t, a + (10 - t)\n N //= 10\n while N != 0:\n t = N % 10\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\n N //= 10\n print(min(a, b + 1))\n\n\nmain()\n', 'def main():\n from builtin import min\n N = int(input())\n\n a = 0 # not carried\n b = 0 # carried\n while N != 0:\n t = N % 10\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\n N //= 10\n print(min(a, b + 1))\n\n\nmain()\n', 'N = int(input())\n\na = 0 # not carried\nb = 0 # carried\nwhile N != 0:\n t = N % 10\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\n N //= 10\nprint(min(a, b + 1))\n', 'N = input()\n\na = 0 # not carried\nb = 0 # carried\nt = int(N[:-1]) % 10\na, b = a + t, a + (10 - t)\nN = N[:-1]\nwhile N != 0:\n t = int(N[:-1]) % 10\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\n N = N[:-1]\nprint(min(a, b + 1))\n', 'def main():\n from builtin import min\n N = int(input())\n\n a = 0 // carried\n b = 0 // not carried\n while N != 0:\n t = N % 10\n a = min(a + t + 1, b + t)\n b = min(a + 9 - t, a + 10 - t)\n n //= 10\n print(min(a + 1, b))\n\n\nmain()\n', 'N = input()\n\nfor i in range(len(N) - 1, -1, -1):\n t = int(N[i])\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\nprint(min(a, b + 1))\n', 'N = input()\n\na = 0 # not borrowed\nb = 0 # borrowed\n\nt = int(N[-1])\na, b = a + t, a + (10 - t)\n\nfor i in range(len(N) - 2, -1, -1):\n t = int(N[i])\n a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))\nprint(min(a, b + 1))\n'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s078760617', 's322528013', 's426076025', 's596550253', 's653294184', 's710445531', 's761166268', 's873986606', 's964110015', 's702349688'] | [5492.0, 3064.0, 5492.0, 3064.0, 3060.0, 5492.0, 5492.0, 2940.0, 5492.0, 5492.0] | [1052.0, 18.0, 2104.0, 18.0, 18.0, 2104.0, 2104.0, 17.0, 19.0, 1229.0] | [200, 234, 275, 333, 274, 193, 259, 269, 162, 246] |
p02775 | u374018235 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['S=input()\npaynum=0\npayout=0\nchange=0\nchangenum=0\nnum=0\n\narray = list(map(int, S))\narray.reverse()\nprint(array)\nfor i in array: \n if i <= 5 :\n paynum = paynum + i\n payout = payout + i *( 10 ** num)\n else:\n if num+1 <len(S):\n array[num+1] = array[num+1]+1\n else:\n paynum = paynum + 1\n payout = payout + 1*(10**(num+1))\n num= num+1\n\n\nchange = payout - N\ntmp= str(change)\narray2 = list(map(int, tmp))\nchangenum= sum(array2)\nprint( changenum + paynum)\n\n\n', 'S=input()[::-1]\nans=0\n\narray = list(map(int, S))\nL=len(array)\nfor i,n in enumerate(array):\n if n<= 5 :\n ans+=n\n elif n > 5:\n ans+= 10-n\n if i <L-1:\n array[i+1] +=1\n else:\n ans +=1\n else:\n ans+=5\n if < L-1:\n if array[i+1] >=5:\n array[i+1] +=1\n \nprint( ans)\n', 'N=int(input())\npaynum=0\npayout=0\nchange=0\nchangenum=0\n\nfor i in range(0,1001)[::-1]:\n if N >= 10**i :\n paynum = N//10**i+1\n payout = paynum *(10**i)\n break\n else:\n continue\n\n\nchange = payout - N\ntmp= change\nprint(tmp)\n\nfor i in range(0,1000)[::-1]:\n if tmp >= 10**i :\n changenum = changenum + tmp//(10**i)\n else:\n continue\n\nprint(paynum + changenum)\n\n\n \n\n\n\n ', 'S=input()[::-1]\nans=0\n\narray = list(map(int, S))\nL=len(array)\nfor i,n in enumerate(array):\n if n< 5 :\n ans+=n\n elif n > 5:\n ans+= 10-n\n if i <L-1:\n array[i+1] +=1\n else:\n ans +=1\n else:\n ans+=5\n if i < L-1:\n if array[i+1] >=5:\n array[i+1] +=1\n \nprint( ans)\n'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s627676611', 's845635503', 's907318549', 's000765088'] | [22328.0, 2940.0, 5492.0, 15588.0] | [2104.0, 17.0, 2112.0, 639.0] | [546, 386, 444, 387] |
p02775 | u417365712 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['from itertools import combinations\nn, k = map(int, input().split())\n*A, = map(int, input().split())\nprint(sorted(x*y for x, y in combinations(A, 2))[k]) ', 'N = map(int, input()[::-1])\na, b = 0, 9\nfor n in N:\n a, b = min(n+a, n+b), min(11-n+a, 9-n+b)\nprint(min(a, b))'] | ['Runtime Error', 'Accepted'] | ['s742055387', 's971407908'] | [5492.0, 5492.0] | [2108.0, 906.0] | [155, 113] |
p02775 | u426649993 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['if __name__ == "__main__":\n n = \'0\' + input()\n\n ans = 0\n flag = 0\n\n for i in range(len(n)-1, 0, -1):\n if int(n[i]) + flag == 10:\n flag = 1\n elif int(n[i]) + flag > 5 or (int(n[i]) + flag == 5 and int(n[i-1]) > 4):\n ans += 10 - int(n[i]) - flag\n flag = 1\n else:\n ans += int(n[i]) + flag\n flag = 0\n print(str(n[i]) + \' \' + str(n[i-1]) + \' \' + str(ans))\n\n if flag == 1:\n ans += 1\n\n print(ans)\n', 'if __name__ == "__main__":\n n = \'0\' + input()\n\n ans = 0\n flag = 0\n\n for i in range(len(n)-1, 0, -1):\n if int(n[i]) + flag == 10:\n flag = 1\n elif int(n[i]) + flag > 5 or (int(n[i]) + flag == 5 and int(n[i-1]) > 4):\n ans += 10 - int(n[i]) - flag\n flag = 1\n else:\n ans += int(n[i]) + flag\n flag = 0\n\n if flag == 1:\n ans += 1\n\n print(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s798185010', 's147461349'] | [14564.0, 5492.0] | [2104.0, 1138.0] | [498, 436] |
p02775 | u475503988 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["import sys\ninput = sys.stdin.buffer.readline\nS = input()\nans = 0\nfor s in S:\n i = int(s)\n ans += min(i, 10-i)\nif S[0] == '9' or int(S[1]) >= 6:\n ans += 1\nprint(ans)\n", 'S = input()\ndp = [0, 1]\nfor s in S:\n i = int(s)\n a = min(dp[0] + i, dp[1] + 10 - i)\n b = min(dp[0] + i+1, dp[1] + 10 - (i+1))\n dp = [a, b]\n # print(dp)\nprint(dp[0])'] | ['Wrong Answer', 'Accepted'] | ['s673051484', 's662633787'] | [4980.0, 5492.0] | [530.0, 1228.0] | [174, 181] |
p02775 | u495440415 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n = list(map(int,input()))[::-1]\nn.append(0)\nfor i in range(len(n)):\n\tif n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):\n \tn[i] = 10 - n[i]\n n[i+1] += 1\nprint(sum(n))', 'n = list(map(int,input()))[::-1]\nn.append(0)\nfor i in range(len(n)):\n if n[i] >= 6 or (n[i] == 5 and n[i+1] >= 5):\n n[i] = 10 - n[i]\n n[i+1] += 1\nprint(sum(n))\n'] | ['Runtime Error', 'Accepted'] | ['s232268006', 's216393862'] | [2940.0, 20336.0] | [17.0, 521.0] | [170, 177] |
p02775 | u497046426 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = list(input())\nans = 0\ntemp = [0] + [int(n) for n in N]\nfor i in reversed(range(1, len(N)+1)):\n if temp[i] < 5 or (temp[i] == 5 and temp[i+1] < 4):\n ans += temp[i]\n else:\n temp[i+1] += 1\n ans += (10 - temp[i])\n temp[i] = 0\nans += temp[0]\nprint(ans)', 'N = list(input())\nans = 0\ntemp = [0] + [int(n) for n in N]\nfor i in reversed(range(1, len(N)+1)):\n if temp[i] < 5 or (temp[i] == 5 and temp[i-1] < 5):\n ans += temp[i]\n else:\n temp[i-1] += 1\n ans += (10 - temp[i])\n temp[i] = 0\nans += temp[0]\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s939993646', 's642437665'] | [29036.0, 29292.0] | [580.0, 673.0] | [285, 285] |
p02775 | u544212192 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['import sys\n\nn=sys.stdin.readline().rstrip()[::-1]\nto=0\nnum=len(n)\nm=0\nprint(n)\n\nfor i in range(num):\n k=int(n[i])\n k+=m\n if k==5:\n if int(n[i+1])>=5:\n to+=10-k\n m=1\n else:\n to+=k\n m=0\n if k<5:\n to+=k\n m=0\n elif k>5:\n to+=10-k\n m=1\n if i==num-1:\n to+=1\n \nprint(to)\n', 'import sys\n\nn=sys.stdin.readline().rstrip()[::-1]\nto=0\n\nm=0\nn+="0"\nnum=len(n)\n\nfor i in range(num):\n k=int(n[i])\n k+=m\n if k==5:\n if int(n[i+1])>=5:\n to+=10-k\n m=1\n else:\n to+=k\n m=0\n if k<5:\n to+=k\n m=0\n elif k>5:\n to+=10-k\n m=1\n \nprint(to+m)\n'] | ['Runtime Error', 'Accepted'] | ['s620403899', 's067110502'] | [6284.0, 5492.0] | [768.0, 743.0] | [390, 352] |
p02775 | u550061714 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N_str = input()\n\nln = len(N_str)\nans = 0\ntable = [[0] * 2 for _ in range(ln)]\ntable[0] = [int(N_str[-1]), 11 - int(N_str[-1])]\nfor i in range(1, ln):\n table[i] = [int(N_str[-i]) + min(table[i - 1]),\n min(int(N_str[-i]) + table[i - 1][0], 10 - int(N_str[-i]) + table[i - 1][1])]\nprint(min(table[ln - 1]))\n', 'N_str = input()\n\nln = len(N_str)\nans = 0\nno_mu, move_up = int(N_str[-1]), 11 - int(N_str[-1])\nfor i in range(2, ln + 1):\n n = int(N_str[-i])\n no_mu, move_up = n + min(no_mu, move_up), min(11 - n + no_mu, 9 - n + move_up)\nprint(min(no_mu, move_up))\n'] | ['Wrong Answer', 'Accepted'] | ['s427049812', 's938230411'] | [170020.0, 5492.0] | [2114.0, 1039.0] | [322, 254] |
p02775 | u561083515 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['import sys\ninput = sys.stdin.readline\n\n\nN = [0] + list(map(int, tuple(input().rstrip("\\n"))))\n\n\nNcopy = N.copy()\nans = 0\n\nflag = False\nfor i in range(len(N)-1, 0, -1):\n if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):\n ans += Ncopy[i]\n flag = False\n else:\n Ncopy[i-1] += 1\n \n if not flag:\n ans += 10 - N[i]\n else:\n ans += 9 - N[i]\n Ncopy[i] = 0\n flag = True\nprint(Ncopy)\nif Ncopy[0] == 1:\n ans += 1\n\nprint(ans)', '#!/usr/bin/env python3\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n N = [0] + list(map(int, tuple(input().rstrip("\\n"))))\n Ncopy = N.copy()\n ans = 0\n\n flag = False\n for i in range(len(N)-1, 0, -1):\n if (Ncopy[i] <= 4) or (Ncopy[i] == 5 and N[i-1] <= 4):\n ans += Ncopy[i]\n flag = False\n else:\n Ncopy[i-1] += 1\n if not flag:\n ans += 10 - N[i]\n else:\n ans += 9 - N[i]\n Ncopy[i] = 0\n flag = True\n\n if Ncopy[0] == 1:\n ans += 1\n\n print(ans)\n\nif __name__ == "__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s626203787', 's168363148'] | [27476.0, 20452.0] | [750.0, 479.0] | [574, 630] |
p02775 | u561231954 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["def main():\n n=list(input())\n n=[int(i) for i in reversed(n)]\n l=len(n)\n n.append(0)\n print(n)\n \n ans=0\n for i in range(l):\n if n[i]<=5:\n a=n[i]\n else:\n n[i+1]+=1\n a=10-n[i]\n print(a)\n ans+=a\n ans+=n[l]\n print(ans) \nif __name__=='__main__':\n main()\n", "def main():\n import numpy as np\n n=list(input())\n n=[int(i) for i in n]\n l=len(n)\n \n dp=np.zeros((l+1,2),dtype=np.int64) \n for i in range(l):\n dp[i+1][:1]=np.minimum(dp[i][:1]+n[i],dp[i][:1]+10-n[i])\n dp[i+1][1:]=np.minimum(dp[i][1:]+n[i]+1,dp[i][1:]+9-n[i])\n #print(dp)\n print(dp[l,0])\n\nif __name__=='__main__':\n main()", "def main():\n n=list(input())\n n=[int(i) for i in reversed(n)]\n l=len(n)\n n.append(0)\n \n ans=0\n for i in range(l):\n if n[i]<=4:\n a=n[i]\n elif n[i]==5:\n if n[i+1]<=4:\n a=n[i]\n else:\n a=10-n[i]\n n[i+1]+=1\n else:\n n[i+1]+=1\n a=10-n[i]\n ans+=a\n ans+=n[l]\n print(ans) \nif __name__=='__main__':\n main()\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s767518857', 's971141713', 's562523993'] | [21604.0, 32140.0, 21356.0] | [1140.0, 2109.0, 472.0] | [290, 344, 367] |
p02775 | u577170763 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["class Solution:\n\n def solve(self, N: str) -> int:\n\n L = len(N)\n D = []\n for l in range(L-1, -1, -1):\n D.append(int(N[l]))\n\n D.append(0)\n\n ans = 0\n for l in range(L+1):\n\n # carry over\n if D[l] == 10:\n D[l+1] += 1\n D[l] = 0\n\n if D[l] <= 5:\n ans += D[l]\n else:\n ans += 10-D[l]\n D[l+1] += 1\n\n print(D[l], ans)\n\n return ans\n\n\nif __name__ == '__main__':\n\n # standard input\n N = input()\n\n # solve\n solution = Solution()\n print(solution.solve(N))\n", "class Solution:\n\n def solve(self, N: str) -> int:\n\n L = len(N)\n D = []\n for l in range(L-1, -1, -1):\n D.append(int(N[l]))\n\n D.append(0)\n\n ans = 0\n for l in range(L+1):\n\n # carry over\n if D[l] == 10:\n D[l+1] += 1\n D[l] = 0\n\n if D[l] < 5:\n ans += D[l]\n elif D[l] == 5:\n if D[l+1] >= 5:\n D[l+1] += 1\n ans += 5\n else:\n ans += 10-D[l]\n D[l+1] += 1\n\n# print(D[l], ans)\n\n return ans\n\n\nif __name__ == '__main__':\n\n # standard input\n N = input()\n\n # solve\n solution = Solution()\n print(solution.solve(N))\n"] | ['Wrong Answer', 'Accepted'] | ['s434193986', 's517791104'] | [23104.0, 15672.0] | [1759.0, 577.0] | [647, 764] |
p02775 | u595289165 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n = list(map(int, list(input())))\nans = 0\nc_in = 0\nq = 0\n\n\ndef carry(x, i, q):\n if x[i] <= 8:\n x[i] += 1\n else:\n x[i] = 0\n if x[i] == x[0]:\n x[i] = 0\n q += 1\n else:\n carry(x, i-1, q)\n\n\nwhile len(n) > 0:\n s = n.pop()\n if 0 <= s <= 5:\n ans += s\n if c_in:\n c_in = 0\n elif 6 <= s <= 9:\n ans += 10 - s\n c_in = 1\n carry(n, -1, q)\n print(s, ans)\n\nans += q\nprint(ans)\n\n', 'n = [0] + list(map(int, list(input())))\nans = 0\nc_in = 0\n\nwhile n:\n s = n.pop()\n s += c_in\n if 0 <= s <= 4:\n ans += s\n c_in = 0\n elif 6 <= s:\n ans += abs(10 - s)\n c_in = 1\n else:\n ans += 5\n if 5 <= n[-1]:\n c_in = 1\n else:\n c_in = 0\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s153356485', 's244135845'] | [21340.0, 21228.0] | [2085.0, 622.0] | [486, 330] |
p02775 | u652057333 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["n = str(input().rstrip())\n\ndef solve1(n):\n ans = 0\n\n a = list(map(int, list(n)))\n a = a[::-1]\n a.append(0)\n for i in range(len(a) - 1):\n c = a[i]\n if c < 5:\n ans += c\n else:\n if c == 5 and a[i+1] < 5:\n ans += 5\n else:\n a[i+1] += 1\n ans += 10 - c\n ans += n_list[-1]\n\n print(ans)\n\ndef solve2(n):\n INF = 10**9\n n = n[::-1]\n n += '0'\n n_len = len(n)\n dp = [INF for _ in range(2)]\n dp[0] = 0\n\n for i in range(n_len):\n pre_dp = [INF, INF]\n for i in range(2):\n pre_dp[i] = dp[i]\n dp = [INF, INF]\n for j in range(2):\n x = int(n[i])\n x += j\n if x < 10:\n dp[0] = min(dp[0], pre_dp[j]+x)\n if x > 0:\n dp[1] = min(dp[1], pre_dp[j]+(10-x))\n print(dp[0])\n\nsolve2(n)", 'n = str(input().rstrip())\n\nans = 0\n\na = list(map(int, list(n)))\na = a[::-1]\na.append(0)\nfor i in range(len(a) - 1):\n c = a[i]\n if c < 5:\n ans += c\n else:\n if c == 5 and a[i+1] < 5:\n ans += 5\n else:\n a[i+1] += 1\n ans += 10 - c\nans += a[-1]\n\nprint(ans)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s301887251', 's542936097'] | [5568.0, 22208.0] | [2104.0, 579.0] | [907, 315] |
p02775 | u664373116 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['tmp=input()\nn=int(tmp)\nl=len(tmp)\nrev=tmp[::-1]\npay_rev=""\nnext_bit=0\nfor i in range(l):\n val=int(rev[i])+next_bit\n if val>5:\n val=0\n next_bit=1\n else:\n next_bit=0\n pay_rev+=str(val)\nif pay_rev[-1]=="0":\n pay_rev+="1"\npay=pay_rev[::-1]\n\nprint(pay)\nzankin=int(pay)-n\nprint(zankin)\nans=0\nfor i in pay:\n ans+=int(i)\nfor i in str(zankin):\n ans+=int(i)\n\nprint(ans)', '\ntmp="9"*(10**6)\n#tmp=input()\n#tmp="78164062862089986280348253421170"\n#tmp="314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170"\n#tmp="846"\n#tmp="253421170"\nl=len(tmp)\n#print(l)\nrev=tmp[::-1]+"0"\nseq_flag=False\nans=0\ndebug=[]\nans_arr=[]\nnext_bit=0\nfor i in range(l-1):\n num=int(rev[i])+next_bit\n next_num=int(rev[i+1])\n if not seq_flag:\n if (num<5) or (num==5 and next_num<5):\n ans+=num\n ans_arr.append(ans)\n next_bit=0\n kuri_cal=0\n continue\n seq_s=i\n seq_flag=True\n kuri_cal=10-num\n next_bit+=1\n continue\n \n if num<5:\n ans+=(kuri_cal+num)\n next_bit=0\n seq_flag=False\n elif num>5:\n kuri_cal+=10-num\n else:\n if next_num<5:\n ans+=(kuri_cal+num)\n next_bit=0\n seq_flag=False\n else:\n kuri_cal+=10-num\n \n\n#print(ans)\nlast=int(tmp[0])+next_bit\n#print(last)\n\nans+=kuri_cal+min(last,11-last)\nans_arr.append(ans)\nprint(ans)', 'def y_solver(tmp):\n l=len(tmp)\n rev=[int(i) for i in tmp[::-1]+"0"]\n ans=0\n for i in range(l):\n num=rev[i]\n next_num=rev[i+1]\n if (num>5) or (num==5 and next_num>=5):\n rev[i+1]+=1\n ans+=min(num,10-num) \n last=rev[l]\n ans+=min(last,10-last)\n return ans\ns=input()\nans=y_solver(s)\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s005705235', 's851823292', 's306857076'] | [5696.0, 7072.0, 14656.0] | [2104.0, 1054.0, 640.0] | [401, 1290, 349] |
p02775 | u667469290 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["# -*- coding: utf-8 -*-\ndef solve():\n N = input()[::-1]+'0'\n res = 0\n c = 0\n for i in range(len(N)-1):\n r = int(N[i])+c\n c = r//10\n r %= 10\n r_ = (int(N[i+1])+c)%10\n if r < 5 or (r==5 and r_ < 5):\n res += r\n else:\n res += 10-r\n return str(res)\n\nif __name__ == '__main__':\n print(solve())\n\n", "# -*- coding: utf-8 -*-\ndef solve():\n N = input()[::-1]+'00'\n res = 0\n c = 0\n for i in range(len(N)-1):\n print(N[i],c)\n r = int(N[i])+c\n c = r//10\n r %= 10\n r_ = (int(N[i+1])+c)%10\n if r < 5 or (r==5 and r_ < 5):\n res += r\n else:\n res += 10-r\n c += 1\n return str(res)\n\nif __name__ == '__main__':\n print(solve())\n\n", "# -*- coding: utf-8 -*-\ndef solve():\n N = input()[::-1]+'00'\n res = 0\n c = 0\n for i in range(len(N)-1):\n r = int(N[i])+c\n c = r//10\n r %= 10\n r_ = (int(N[i+1])+c)%10\n if r < 5 or (r==5 and r_ < 5):\n res += r\n else:\n res += 10-r\n c += 1\n return str(res)\n\nif __name__ == '__main__':\n print(solve())\n\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s368234095', 's597452278', 's073041118'] | [5492.0, 8572.0, 6668.0] | [896.0, 1828.0, 910.0] | [371, 413, 391] |
p02775 | u690536347 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['s = input()[::-1]\nsize = len(s)\ns += "9"\n\nans = 0\nbef = 0\n\nfor i in range(size):\n v1 = int(s[i])\n v2 = int(s[i+1])\n if v1+bef>=6 or (v1+bef>=5 and v2>=5):\n ans += 10-(v1+bef)\n bef = 1\n else:\n ans += (v1+bef)\n bef = 0\n\nans += (v+bef)//10\nprint(ans)', 's = input()[::-1]\nsize = len(s)\ns += "4"\n\nans = 0\nbef = 0\n\nfor i in range(size):\n v1 = int(s[i])\n v2 = int(s[i+1])\n if v1+bef>=6 or (v1+bef>=5 and v2>=5):\n ans += 10-(v1+bef)\n bef = 1\n else:\n ans += (v1+bef)\n bef = 0\n\nans += bef\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s182392140', 's415837306'] | [5492.0, 5492.0] | [854.0, 1069.0] | [287, 279] |
p02775 | u704284486 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = str(input())\nL = len(N)\nans = 0\ns = list(N)\nfor i in range(L):\n n = int(s[i])\n ans += min(n,10-n)\n\nprint(ans)\n', 'N = str(input())\nL = len(N)\nans = 0\ndp = [[0,0] for _ in range(L)]\ns = list(map(int,N))\ndp[0] = [s[0],11-s[0]]\nfor i in range(1,L):\n n = s[i]\n dp[i][0] = min(dp[i-1][0]+n,dp[i-1][1]+n)\n dp[i][1] = min(dp[i-1][1]+9-n,dp[i-1][0]+11-n)\nprint(min(dp[-1]))'] | ['Wrong Answer', 'Accepted'] | ['s380628488', 's309164033'] | [12864.0, 179056.0] | [603.0, 1951.0] | [120, 260] |
p02775 | u722868069 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['N = input().strip()\n\nd = len(N)\nculc = [0] * (d+1)\n\nfor i, digit in enumerate(N):\n digit = int(digit)\n if digit < 6:\n culc[i+1] = digit\n else:\n culc[i] += 1\n culc[i+1] -= (10 - digit) \n if culc[i+1] > 5:\n culc[i+1] = (10 - culc[i+1])\n\nans = 0\nfor i in culc:\n ans += abs(i)\n \nprint(culc)\nprint(ans)\n', 'N = input().strip()\n\nd = len(N)\nculc = [0] * (d+1)\n\nfor i, digit in enumerate(N):\n digit = int(digit)\n if digit < 6:\n culc[i+1] = digit\n else:\n culc[i] += 1\n culc[i+1] -= (10 - digit) \n\nans = 0\nfor i in culc:\n ans += abs(i)\n \nprint(culc)\nprint(ans)\n', 'n = input()\ndigit = [int(n[-(i + 1)]) for i in range(len(n))]\ndigit.append(0)\n\nans = 0\nfor i in range(len(digit)):\n if digit[i] > 5 or (digit[i] == 5 and digit[i + 1] >= 5):\n ans += 10 - digit[i]\n digit[i] = 0\n digit[i + 1] += 1\n else:\n ans += digit[i]\n digit[i] = 0\n\nprint(ans)\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s066023611', 's486922363', 's221730791'] | [22580.0, 22588.0, 15672.0] | [899.0, 762.0, 813.0] | [322, 265, 296] |
p02775 | u731448038 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n = list(map(int, input()))\nn = n[::-1]\n#print(n)\n\nb0 = [0]*(len(n)+1)\nb1 = [0]*(len(n)+1)\n\nfor i in range(0, len(n)):\n num = n[i]\n b0[i+1] = min(b0[i]+num, b1[i]+num+1)\n b1[i+1] = min(b0[i]+10-num, b1[i]+10-(num+1))\n\nprint(min(b0[-1], b1[-1]+1))', 'n = [0] + list(map(int, input())) + [0]\nn = n[::-1]\n#print(n)\n\nb0 = [0]*len(n)\nb1 = [0]*len(n)\n\nfor i in range(1, len(n)):\n num = n[i]\n b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)\n b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))\n\nprint(min(b0[-1], b1[-1]))', 'n = list(map(int, input())) + [0]\nn = n[::-1]\n#print(n)\n\nb0 = [0]*len(n)\nb1 = [0]*len(n)\n\nfor i in range(1, len(n)):\n num = n[i]\n #print(num)\n b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)\n b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))\n\n \nprint(min(b0[-1], b1[-1]))', 'n = [0] + list(map(int, input())) + [0]\nn = n[::-1]\n#print(n)\n\nb0 = [0]*len(n)\nb1 = [0]*len(n)\nb1[0] = 1\nfor i in range(1, len(n)):\n num = n[i]\n b0[i] = min(b0[i-1]+num, b1[i-1]+num+1)\n b1[i] = min(b0[i-1]+10-num, b1[i-1]+10-(num+1))\n\nprint(min(b0[-1], b1[-1]))\n#print(b0[-1], b1[-1])'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s164539814', 's641085076', 's871840736', 's965215593'] | [89980.0, 89996.0, 89940.0, 89956.0] | [1603.0, 1389.0, 1382.0, 1485.0] | [249, 255, 266, 287] |
p02775 | u736729525 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['\n# 0, 1, 2, 3, 4, 5, 6, 7, 8, 9\nP = [0, 1, 2, 3, 4, 0, 0, 0, 0, 0]\nC = [0, 0, 0, 0, 0, 5, 4, 3, 2, 1]\nX = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1]\nimport sys\ndef solve(N):\n N = [int(c) for c in N]\n N = N[::-1]\n p = 0\n b = 0\n s = []\n for i in range(len(N)):\n c = N[i]\n c += b\n if c == 10:\n c = 0\n b = 1\n p += X[c]\n s.append(P[c])\n elif c == 5:\n if i == len(N)-1:\n p += 5\n s.append(5)\n b = 0\n else:\n if N[i+1] < 5:\n p += 5\n b = 0\n s.append(5)\n else:\n p += 5 \n b = 1\n s.append(0)\n elif c > 5:\n b = 1\n p += X[c]\n s.append(P[c])\n else:\n b = 0\n p += X[c]\n s.append(P[c])\n if b:\n s.append(b)\n #print(b, file=sys.stderr)\n return p + b, s[::-1]\n\ndef count(n):\n return sum([int(x) for x in str(n)])\n\ndef test(N):\n m = 10e10\n p = 0\n for P in range(N, N*10):\n n = count(P) + count(P - N)\n if n < m:\n p = P\n m = n\n e,s = solve(str(N))\n if e != m:\n print("N=%d"%N, "expected=%d"%m, p, "actual=%d"%e, "".join(str(c) for c in s))\n\nN = [int(x) for x in input()]\na,_ = solve(N)\nprint(a)\nif 1==1:\n for i in range(1, 1000):\n test(i)\n test(159)\n test(149)\n test(449)\n test(959)\n test(949)\n test(939)\n test(539)\n test(569)\n\n', 'X = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]\ndef solve(N):\n N = [int(c) for c in N][::-1]\n p = 0\n b = 0\n for i in range(len(N)):\n c = N[i] + b\n p += X[c]\n if c == 5:\n b = 0 if i == len(N)-1 or N[i+1] < 5 else 1\n elif c > 5:\n b = 1\n else:\n b = 0\n return p + b\n\nprint(solve(input()))\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s562709236', 's212188065'] | [35036.0, 21444.0] | [2105.0, 411.0] | [1590, 358] |
p02775 | u770199020 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['Ns = [int(s) for s in input()]\ntotal = 0\nkuri = 0\nfor n in Ns[::-1]:\n print(n)\n if kuri + n == 10:\n kuri = 1\n else:\n n += kuri\n if n <= 5:\n total += n\n kuri = 0\n else:\n total += (10 - n)\n kuri = 1\nif kuri > 0:\n total += kuri\n \nprint(total)', 'Ns = [int(s) for s in input()]\norder = len(Ns)\n\ndp_just = [0 for _ in range(order + 1)]\ndp_plus = [0 for _ in range(order + 1)]\n\ndp_just[0] = 0\ndp_plus[0] = 1\n\nfor o in range(order):\n n = Ns[o]\n dp_just[o+1] = min(dp_just[o] + n, dp_plus[o] + (10 - n))\n dp_plus[o+1] = min(dp_just[o] + n + 1, dp_plus[o] + (9 -n))\n \nprint(dp_just[-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s956997399', 's076046374'] | [23916.0, 91788.0] | [1196.0, 1513.0] | [278, 339] |
p02775 | u772395065 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n=list(input())\nlis=[]\nfor k in range(len(n)):\n lis.append(int(n[len(n)-1-k]))\n \nt=0\nprint(lis)\nfor k in range(len(lis)):\n if lis[k]==10:\n if k==len(lis)-1:\n t+=1\n break\n else:\n lis[k]=0\n lis[k+1]+=1\n if lis[k]<5:\n t+=lis[k]\n elif lis[k]>5:\n t=t+10-lis[k]\n if k==len(lis)-1:\n t+=1\n break\n else:\n \n lis[k+1]+=1\n elif lis[k]==5:\n if k==len(lis)-1:\n t+=5\n else:\n t+=5\n if lis[k+1]<5:\n pass\n else:\n lis[k+1]+=1\nprint(t)', 'n=list(input())\nlis=[]\nfor k in range(len(n)):\n lis.append(int(n[len(n)-1-k]))\n \nt=0\n\nfor k in range(len(lis)):\n if lis[k]==10:\n if k==len(lis)-1:\n t+=1\n break\n else:\n lis[k]=0\n lis[k+1]+=1\n if lis[k]<5:\n t+=lis[k]\n elif lis[k]>5:\n t=t+10-lis[k]\n if k==len(lis)-1:\n t+=1\n break\n else:\n \n lis[k+1]+=1\n elif lis[k]==5:\n if k==len(lis)-1:\n t+=5\n else:\n t+=5\n if lis[k+1]<5:\n pass\n else:\n lis[k+1]+=1\nprint(t)'] | ['Wrong Answer', 'Accepted'] | ['s795295780', 's551021353'] | [29924.0, 21348.0] | [1239.0, 1160.0] | [536, 526] |
p02775 | u780475861 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['import sys\nn = list(map(int, sys.stdin.readline()))\ns = sum(i if i <= 5 else 10 - i for i in n)\n\nprint(s)\n', 'import sys\nn = list(map(int, sys.stdin.readline()))\ns = sum(i if i <= 5 else 10 - i for i in n)\n', 'import sys\n\n', 'import sys\nn = list(map(int, sys.stdin.readline()))\ns = sum(i if i <= 5 else 10 - i for i in n)\nif (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):\n s += 1\nprint(s)\n', 'import sys\nn = list(map(int, sys.stdin.readline()))\ns = sum(i if i <= 5 else 10 - i for i in n)\nif (n[0] > 5 and n[1] < 6) or (n[0] <= 5 and n[1] >= 6):\n s += 1\nprint(s)\n', "def main():\n n = list(map(int, input()[::-1])) + [0]\n s = 0\n res = 0\n for i, ni in enumerate(n[:-1]):\n k = ni + s\n if k < 5 or (k == 5 and n[i + 1] < 5):\n res += k\n s = 0\n else:\n res += 10 - k\n s = 1\n res += s\n print(res)\n\n\nif __name__ == '__main__':\n main()\n"] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s383354383', 's398146295', 's538525970', 's585156536', 's759819667', 's731590349'] | [11924.0, 11924.0, 2940.0, 11928.0, 11924.0, 18764.0] | [154.0, 165.0, 17.0, 154.0, 180.0, 371.0] | [106, 96, 12, 171, 171, 345] |
p02775 | u816488327 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["def solve():\n from sys import stdin\n #f_i = stdin\n f_i = open('test_in_3')#\n \n N = f_i.readline().rstrip()\n N = N[::-1] + '0'\n \n INF = 10 ** 32\n \n import numpy as np\n dp = np.full((len(N), 2), INF)\n dp[0][0] = 0\n \n for i, x in enumerate(int(n) for n in N[:-1]):\n ni = i + 1\n dp[ni][0] = min(dp[i] + x)\n dp[ni][1] = min(dp[i][0] + 11 - x, dp[i][1] + 9 - x)\n \n ans = min(dp[-1])\n \n print(ans)\n\nsolve()", 'def solve():\n N = input()\n \n INF = 10 ** 32\n \n dp = [[INF, INF] for i in range(len(N) + 1)]\n dp[0][0] = 0\n \n for i, x in enumerate(int(n) for n in N[::-1]):\n ni = i + 1\n dp[ni][0] = min(dp[i][0] + x, dp[i][1] + x)\n dp[ni][1] = min(dp[i][0] + 11 - x, dp[i][1] + 9 - x)\n \n ans = min(dp[-1])\n \n print(ans)\n\nsolve()'] | ['Runtime Error', 'Accepted'] | ['s583357071', 's947424902'] | [3064.0, 171008.0] | [17.0, 1719.0] | [474, 368] |
p02775 | u844789719 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ["import sys\nimport numpy as np\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\ntry:\n sys.winver\n N = np.array([int(_) for _ in input()])\n from numba import jit\n solve = jit(solve, '(i8[:])')\n solve(N)\nexcept:\n if sys.argv[-1] == 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('solve', '(i8[:])')(solve)\n \n cc.compile()\n else:\n from my_module import solve\n N = np.array([int(_) for _ in input()])\n solve(N)\n", "import sys\nimport numpy as np\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\nif sys.argv[-1] == 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('solve', '(i8[:])')(solve)\n \n cc.compile()\nelse:\n from my_module import main\n N = np.array([int(_) for _ in input()])\n solve(N)\n", "import sys\nimport numpy as np\n\n\n\ndef main(N, dp):\n dp=np.zeros((2,len(N)),dtype=np.int64)\n dp[0, 0] = min(N[0], 11 - N[0])\n dp[0, 1] = min(N[0] + 1, 10 - N[0])\n for i in range(1, len(N)):\n dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])\n dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])\n print(dp[-1][0])\n\n\nif sys.argv[-1] == 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('main', '(i8,i8[:],)')(main)\n \n cc.compile()\nelse:\n #from my_module import main\n N = np.array([int(_) for _ in input()])\n main(N)\n", 'N = [int(s) for s in input()][::-1] + [0]\nans = 0\nfor i in range(len(N)):\n if N[i] == 10:\n N[i + 1] += 1\n elif N[i] < 6:\n ans += N[i]\n else:\n ans += 10 - N[i]\nprint(ans)\n', "import sys\nimport numpy as np\n\n\n\ndef main(N,dp):\n dp[0, 0] = min(N[0], 11 - N[0])\n dp[0, 1] = min(N[0] + 1, 10 - N[0])\n for i in range(1, len(N)):\n dp[i, 0] = min(dp[i - 1, 0] + N[i], dp[i - 1, 1] + 10 - N[i])\n dp[i, 1] = min(dp[i - 1, 0] + N[i] + 1, dp[i - 1, 1] + 9 - N[i])\n print(dp[-1][0])\n\n\nif sys.argv[-1] == 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('main', '(i8[:],i8[:,:])')(main)\n \n cc.compile()\nelse:\n from my_module import main\n N = np.array([int(_) for _ in input()])\n dp=np.zeros((2,len(N)),dtype=np.int64)\n main(N,dp)\n", "import sys\nimport numpy as np\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\ntry:\n sys.winver\n N = np.array([int(_) for _ in input()])\n from numba import jit\n solve = jit(solve, '(i8[:])')\n solve(N)\nexcept:\n if sys.argv[-1] != 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('solve', '(i8[:])')(solve)\n \n cc.compile()\n else:\n from my_module import solve\n N = np.array([int(_) for _ in input()])\n solve(N)\n", "import sys\nimport numpy as np\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\nif sys.argv[-1] == 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('solve', '(i8[:])')(solve)\n \n cc.compile()\nelse:\n from my_module import solve\n N = np.array([int(_) for _ in input()])\n solve(N)\n", "import sys\nimport numpy as np\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\ntry:\n sys.winver\n N = np.array([int(_) for _ in input()])\n from numba import jit\n solve = jit(solve, '(i8[:])')\n solve(N)\nexcept:\n if sys.argv[-1] != 'ONLINE_JUDGE':\n import numba\n from numba.pycc import CC\n cc = CC('my_module')\n cc.export('solve', '(i8[:])')(solve)\n \n cc.compile()\n else:\n #from my_module import solve\n #N = np.array([int(_) for _ in input()])\n solve(N)\n", 'import numpy as np\nfrom numba import njit\n\nN = np.array([int(_) for _ in input()])\n\n\ndef solve(N):\n p, q = 0, 1\n for x in N:\n p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)\n print(p)\n\n\nsolve(N)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s059175092', 's068388703', 's095773624', 's250282748', 's603747383', 's624968598', 's642131271', 's997024367', 's487449954'] | [27192.0, 27048.0, 43360.0, 26200.0, 43560.0, 94240.0, 26632.0, 141752.0, 107300.0] | [112.0, 115.0, 291.0, 371.0, 363.0, 1001.0, 113.0, 1306.0, 1910.0] | [669, 479, 689, 200, 694, 669, 480, 671, 220] |
p02775 | u847923740 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['#\n\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n N=input().strip("\\n")\n ans=0\n for i in range(len(N)):\n d=int(N[i])\n if d<=5:\n ans+=d\n else:\n ans+=10-d\n if i==0:\n ans+=1\n print(ans)\n \nif __name__=="__main__":\n main()\n', '#\n\nimport sys\ninput=sys.stdin.readline\n\ndef main():\n NS=(input().strip("\\n"))[::-1]\n dp=[[0]*2 for i in range(len(NS))]\n \n dp[0][0]=int(NS[0])\n dp[0][1]=10-int(NS[0])\n for i in range(1,len(NS)):\n d=int(NS[i])\n dp[i][0]=min(dp[i-1][0]+d,dp[i-1][1]+d+1)\n dp[i][1]=min(dp[i-1][0]+10-d,dp[i-1][1]-1+10-d)\n dp[-1][1]+=1\n print(min(dp[-1]))\n \nif __name__=="__main__":\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s771822218', 's608901333'] | [11084.0, 162440.0] | [220.0, 1286.0] | [308, 451] |
p02775 | u853819426 | 2,000 | 1,048,576 | In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. _(Takoyaki is the name of a Japanese snack.)_ To make the payment, you will choose some amount of money which is at least N and give it to the clerk. Then, the clerk gives you back the change, which is the amount of money you give minus N. What will be the minimum possible number of total banknotes used by you and the clerk, when both choose the combination of banknotes to minimize this count? Assume that you have sufficient numbers of banknotes, and so does the clerk. | ['n = list(map(int, input()))\n\nl = [0] * (len(n)+2)\ncarry = 0\nfor i, k in enumerate(n):\n if k > 5 - carry:\n l[i+1] = k - 10\n l[i] += 1\n carry = 1\n while l[i] >= 6 - (1 if l[i-1] <= 0 else 0):\n l[i] -= 10\n i -= 1\n l[i] += 1\n else:\n l[i+1] = k\n carry = 0\nprint(l)\nprint(sum(abs(i) for i in l))', 'n = list(map(int, input()))\n \nl = [0] * (len(n)+1)\ncarry = 0\nfor i, k in enumerate(n):\n if k > 5 - carry:\n l[i+1] = k - 10\n l[i] += 1\n carry = 1\n while l[i] >= 6 - (1 if l[i-1] < 0 else 0):\n l[i] -= 10\n i -= 1\n l[i] += 1\n if i == 0:\n break\n else:\n carry = 0', 'n = list(map(int, input()))\ndp = (0, 1)\nfor i in n:\n dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i))\nprint(dp[0])'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s124371091', 's254495475', 's351611489'] | [31456.0, 20332.0, 13508.0] | [829.0, 732.0, 1147.0] | [324, 301, 139] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.