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
p03497
u848647227
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['import collections\na,b = map(int,input().split(" "))\nar = list(map(int,input().split(" ")))\nbr = set(ar)\ncr = collections.Counter(ar)\nn = len(br) - b\ndr = []\nfor k in cr.keys():\n cr.append(k)\ncr.sort()\ncount = 0\nfor i in range(n):\n count += cr[i]', 'import collections\na,b = map(int,input().split(" "))\nar = list(map(int,input().split(" ")))\nbr = set(ar)\ncr = collections.Counter(ar)\nn = len(br) - b\ndr = []\nfor v in cr.values():\n dr.append(v)\ndr.sort()\ncount = 0\nfor i in range(n):\n count += dr[i]\nprint(count)']
['Runtime Error', 'Accepted']
['s664498964', 's039011979']
[45364.0, 45356.0]
[119.0, 170.0]
[252, 267]
p03497
u859897687
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['n,k=map(int,input().split())\nd=dict()\nfor i in map(int,input().split()):\n if i not in d:\n d[i]=1\n else:\n d[i]+=1\nm=list(d.keys())\nm.sort()\nn-=k\nans=0\nfor i in m:\n if n<=0:\n break\n n-=d[i]\n ans+=1\nprint(ans)', 'n,k=map(int,input().split())\nd=dict()\nfor i in map(int,input().split()):\n if i not in d:\n d[i]=1\n else:\n d[i]+=1\nm=d.keys()\nm.sort()\nn-=k\nfor i in m:\n if n<=0:\n break\n n-=d[i]\n ans+=1\nprint(ans)', 'n,k=map(int,input().split())\nd=dict()\nfor i in map(int,input().split()):\n if i not in d:\n d[i]=1\n else:\n d[i]+=1\nm=list(d.keys())\nm.sort()\nn-=k\nfor i in m:\n if n<=0:\n break\n n-=d[i]\n ans+=1\nprint(ans)', 'n,k=map(int,input().split())\nd=dict()\nfor i in map(int,input().split()):\n if i not in d:\n d[i]=1\n else:\n d[i]+=1\nm=list(d.values())\nm.sort()\na=len(m)-k\nans=0\nfor i in m:\n if a<=0:\n break\n a-=1\n ans+=i\nprint(ans)\n']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s087542541', 's282604768', 's653241972', 's127116348']
[41116.0, 41120.0, 41120.0, 41120.0]
[188.0, 118.0, 124.0, 152.0]
[220, 208, 214, 226]
p03497
u860002137
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['from collections import Counter\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nli = Counter(A)\nli = list(li.values())\nli.sort()\n\nsum(li[:max(len(li) - K, 0)])', 'from collections import Counter\n\nN, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nli = Counter(A)\nli = list(li.values())\nli.sort()\n\nprint(sum(li[:max(len(li) - K, 0)]))']
['Wrong Answer', 'Accepted']
['s538419454', 's585041698']
[32564.0, 32540.0]
[96.0, 97.0]
[182, 189]
p03497
u864453204
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['n, k = map(int, input().split())\nA = list(map(int, input().split()))\na = set(A)\nt = len(set(A))\ndic = {"{}".format(i):A.count(i) for i in a}\ndic = dict(sorted(dic.items(), key=lambda x:x[1]))\ncnt = 0\nans = 0\nif t > k:\n for i, v in dic.items():\n if cnt == (t - k + 1):\n break\n cnt += 1\n ans += v\nprint(ans)\n', 'from collections import Counter\n\nn, k = map(int, input().split())\nA = sorted(Counter(list(map(int, input().split()))).most_common(), key=lambda x:x[1])\ncnt = 0\nprint(A)\nif len(A) > k:\n for i in range(len(A)-k):\n cnt += A[i][1]\nprint(cnt)', 'n, k = map(int, input().split())\nA = list(map(int, input().split()))\na = set(A)\nt = len(set(A))\ndic = {"{}".format(i):A.count(i) for i in a}\ndic = dict(sorted(dic.items(), key=lambda x:x[1]))\ncnt = 0\nans = 0\nif t > k:\n for i, v in dic.items():\n if cnt == (t - k + 1):\n break\n cnt += 1\n ans += v\nprint(cnt)\n', 'from collections import Counter\n\nn, k = map(int, input().split())\nA = sorted(Counter(list(map(int, input().split()))).most_common(), key=lambda x:x[1])\ncnt = 0\nif len(A) > k:\n for i in range(len(A)-k):\n cnt += A[i][1]\nprint(cnt)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s475253265', 's636321362', 's925729647', 's042005643']
[36380.0, 37780.0, 35512.0, 37784.0]
[2104.0, 298.0, 2108.0, 204.0]
[341, 247, 341, 238]
p03497
u865741247
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['from collections import OrderedDict\n\ntemp=input()\nn,k=list(map(int,temp.split(" ")))\nco=OrderedDict()\nans=[]\ntemp=input()\nnums=list(map(int,temp.split(" ")))\nfor i in nums:\n if i in co:\n\t co[i]+=1\n else:\n\t co[i]=1\nfor i in co:\n ans.append(co[i])\nkinds=len(ans)\ndif=kinds-k\nif dif<=0:\n print(0)\nelse:\n ans.sort()\n print(sum(ans[:dif-1]))', 'from collections import OrderedDict\n\ntemp=input()\nn,k=list(map(int,temp.split(" ")))\nco=OrderedDict()\nans=[]\ntemp=input()\nnums=list(map(int,temp.split(" ")))\nfor i in nums:\n if i in co:\n\t co[i]+=1\n else:\n\t co[i]=1\nfor i in co:\n ans.append(co[i])\nkinds=len(ans)\ndif=kinds-k\nif dif<=0:\n print(0)\nelse:\n ans.sort()\n print(sum(ans[:dif]))']
['Wrong Answer', 'Accepted']
['s586984765', 's897426384']
[71708.0, 71700.0]
[660.0, 640.0]
[350, 348]
p03497
u923270446
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['n = int(input())\na = list(map(int, input().split()))\nprint(n * 2 - 1)\nma, mi = max(a), min(a)\nima, imi = a.index(ma), a.index(mi)\nif abs(ma) > abs(mi):\n for i in range(1, n + 1):\n print(ima + 1, i)\n for i in range(1, n):\n print(i, i + 1)\nelse:\n for i in range(1, n + 1):\n print(imi + 1, i)\n for i in range(1, n):\n print(i + 1, i) ', 'from collections import Counter\nn, k = map(int, input().split())\na = list(map(int, input().split()))\nc = Counter(a)\nc = c.most_common()\nans = 0\nc.sort(key=lambda x:x[1])\nfor i in range(len(set(a)) - k):\n ans += c[i][1]\nprint(ans)']
['Runtime Error', 'Accepted']
['s140448096', 's451081605']
[3064.0, 41364.0]
[17.0, 229.0]
[370, 232]
p03497
u951980350
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['from collections import Counter\n\nN,K = list(map(int,input().split(" ")))\nA = list(map(int,input().split(" ")))\nA2 = dict(Counter(A))\n\nif len(A2) > K:\n r = sorted(A2.items(),key=lambda x:x[1])\n print(sum([i[1] for i in r[:K]]))\nelse:\n print("0")', 'from collections import Counter\n\nN,K = list(map(int,input().split(" ")))\nA = list(map(int,input().split(" ")))\nA2 = dict(Counter(A))\ni=0\nr = [v for k,v in sorted(A2.items(),key=lambda x:-x[1])]\nprint(N- sum(r[0:K]))\n']
['Wrong Answer', 'Accepted']
['s171071671', 's713645426']
[39344.0, 39316.0]
[157.0, 178.0]
[253, 216]
p03497
u969190727
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['import collections\nn,k=map(int,input().split())\nA=list(map(int,input().split()))\nc=collections.Counter(A)\ntot=0\nfor i in range(len(set(A))):\n tot+=c.most_common()[i][1]\nprint(n-tot)', 'import collections\nn,k=map(int,input().split())\nA=list(map(int,input().split()))\nc=collections.Counter(A)\ntot=0\nfor i in c.most_common(min(k,len(set(A)))):\n tot+=i[1]\nprint(n-tot)']
['Wrong Answer', 'Accepted']
['s078393535', 's345361138']
[43052.0, 39856.0]
[2105.0, 149.0]
[182, 180]
p03497
u978494963
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['from collections import defaultdict\nn,k = map(int,input().split())\nnums = input().split()\ncount_per_num = defaultdict(int)\nfor n in nums:\n count_per_num[n] += 1\ncount_per_nums = sorted(count_per_nums, key=lambda x:x[1])\nans = 0\nfor i in range(len(count_per_nums)-k):\n ans += count_per_nums[i]\nprint(ans)', 'from collections import defaultdict\nn,k = map(int,input().split())\nnums = input().split()\ncount_per_nums = defaultdict(int)\nfor n in nums:\n count_per_nums[n] += 1\ncount_per_nums = sorted(count_per_nums.items(), key=lambda x:x[1])\nans = 0\nfor i in range(len(count_per_nums)-k):\n ans += count_per_nums[i][1]\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s031306405', 's432781146']
[35996.0, 44048.0]
[115.0, 245.0]
[305, 319]
p03497
u999503965
2,000
262,144
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball. He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls. Find the minimum number of balls that Takahashi needs to rewrite the integers on them.
['from collections import Counter\n\n#n,k=map(int,input().split())\n#l=list(map(int,input().split()))\nn,k=10, 3\nl=[5, 1, 3, 2, 4, 1, 1, 2, 3, 4]\n\nl=Counter(l)\nnum=len(l)\ncnt=0\n\nprint(l)\n ', 'from collections import Counter\n\n#n,k=map(int,input().split())\n#l=list(map(int,input().split()))\nn,k=10, 3\nl=[5, 1, 3, 2, 4, 1, 1, 2, 3, 4]\n\nl=Counter(l)\n\nif len(l) > k:\n ans=0\nelse:\n sl=sorted(list(l.values()))\n num=k-len(l)\n print(sl[:num-1])\n \n', 'from collections import Counter\n\nn,k=map(int,input().split())\nl=list(map(int,input().split()))\n\nl=Counter(l)\n\nif len(l) <= k:\n ans=0\nelse:\n sl=sorted(list(l.values()))\n num=len(l)-k\n ans=sum(sl[:num])\n \nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s127381586', 's249577055', 's195034899']
[9260.0, 9372.0, 35136.0]
[30.0, 33.0, 102.0]
[185, 254, 218]
p03551
u026155812
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['N, M = map(int, input().split())\np = (1/2)**M\nq = 1 - p\n\nprint((N-M)*100/p + 1900*M/(1-q))', 'N, M = map(int, input().split())\np = (1/2)**M\nq = 1 - p\n\nprint(int((N-M)*100/p + 1900*M/(1-q)))']
['Wrong Answer', 'Accepted']
['s608896397', 's088823515']
[2940.0, 2940.0]
[17.0, 17.0]
[90, 95]
p03551
u039623862
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['n, x, y = map(int, input().split())\na = list(map(int, input().split()))\n\nif n == 1:\n print(abs(a[-1] - y))\nelse:\n print(max(abs(a[-1] - y), abs(a[-1] - a[-2])))\n', 'n, m = map(int, input().split())\nprint(2**m * (1800 * m + 100 * n))\n']
['Runtime Error', 'Accepted']
['s252223576', 's595112184']
[2940.0, 2940.0]
[17.0, 17.0]
[167, 68]
p03551
u133038626
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['N, M = map(int, input().split())\nt = 100 * N + 1800 * M\ntotal = 0\ni = 1\np = 1 / 2**M\nwhile True:\n d = i * (1-p)**(i-1) * p * t\n total += d\n if d < 0.001:\n break\nprint(total)', 'N, M = map(int, input().split())\nt = 100 * N + 1800 * M\ntotal = 0\ni = 1\np = 1 / 2**M\nwhile True:\n d = i * (1-p)**(i-1) * p * t\n total += d\n if d < 0.001:\n break\n i += 1\nprint(round(total))']
['Time Limit Exceeded', 'Accepted']
['s116666648', 's225850705']
[2940.0, 3188.0]
[2104.0, 21.0]
[189, 207]
p03551
u143509139
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['n,m=map(int,input().split());print(n*100+m*1800*2**m)', 'n,m=map(int,input().split());print((n*100+m*1800)*2**m)']
['Wrong Answer', 'Accepted']
['s638345823', 's755969049']
[2940.0, 2940.0]
[17.0, 17.0]
[53, 55]
p03551
u226155577
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['N, M = map(int, input().split())\nT = 100*(N-M) + 1900*M\nS = 0.5**M\n\nprint(T//S)', 'N, M = map(int, input().split())\nT = 100*(N-M) + 1900*M\nS = 2**M\n\nprint(T*S)']
['Wrong Answer', 'Accepted']
['s270598052', 's638768697']
[2940.0, 2940.0]
[17.0, 17.0]
[79, 76]
p03551
u278832126
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['def main(M, N):\n n = 1\n for _ in range(N):\n n *= 2\n\n return n * ((M - N) * 100 + N * 1900)', 'n = 1\nfor _ in range(N):\n n *= 2\n\nreturn n * ((M - N) * 100 + N * 1900)', 'def main(N, M):\n n = 1\n for _ in range(M):\n n *= 2\n\n print(n * ((N - M) * 100 + M * 1900))', 'def main(N, M):\n n = 1\n for _ in range(M):\n n *= 2\n\n return n * ((N - M) * 100 + M * 1900)', 'N, Z, W = map(int, input().split())\ncards = list(map(int, input().split()))\n\nif N == 1:\n print(cards[0] - W)\nelse:\n x = abs(cards[-1] - cards[-2])\n y = abs(cards[-1] - W)\n print(max(x, y))', 'def main(N, M):\n n = 1\n for _ in range(N):\n n *= 2\n\n return n * ((M - N) * 100 + N * 1900)', 'def main(N, M):\n n = 1\n for _ in range(M):\n n *= 2\n\n print n * ((N - M) * 100 + M * 1900)', 'N, M = map(int, input().split())\n\nn = 1\nfor _ in range(M):\n n *= 2\n\nprint(n * ((N - M) * 100 + M * 1900))']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s036235048', 's245831851', 's719586030', 's756979497', 's854500386', 's928266336', 's965736798', 's597666312']
[2940.0, 2940.0, 2940.0, 2940.0, 3060.0, 2940.0, 2940.0, 2940.0]
[17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0, 17.0]
[106, 74, 106, 106, 200, 106, 105, 108]
p03551
u327466606
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['if __debug__:\n i = 0\n while True:\n i *= 2\n\nN,M = map(int,input().split())\n\nprint(2**M*(1900*M+100*(N-M)))', '\nN,M = map(int,input().split())\n\nprint(2**M*(1900*M+100*(N-M)))']
['Time Limit Exceeded', 'Accepted']
['s417048195', 's574026984']
[2940.0, 2940.0]
[2104.0, 17.0]
[110, 63]
p03551
u340781749
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['n,z,w=map(int,input().split())\naa=input().split()\nan=int(aa[-1])\nif len(aa) > 1:\n am=int(aa[-2])\n print(max(abs(an-w),abs(an-am)))\nelse:\n print(abs(an-w))', 'n,m=map(int,input().split())\nq=(n-m)*100+m*1900\nprint(q*(1<<m))']
['Runtime Error', 'Accepted']
['s103283858', 's133339665']
[3060.0, 2940.0]
[17.0, 17.0]
[163, 63]
p03551
u389910364
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['import os\nimport sys\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(2147483647)\nINF = float("inf")\n\nN, M = list(map(int, sys.stdin.readline().split()))\n\nN, M = list(map(int, sys.stdin.readline().split()))\n\ntime = M * 1900 + (N - M) * 100\n\np_ac = 1 / 2 ** M\n\nprint(int(1 / p_ac * time))\n\n', 'import os\nimport sys\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(2147483647)\nINF = float("inf")\n\nN, M = list(map(int, sys.stdin.readline().split()))\n\n\ntime = M * 1900 + (N - M) * 100\n\np_ac = 1 / 2 ** M\n\nprint(int(1 / p_ac * time))\n\n']
['Runtime Error', 'Accepted']
['s831485535', 's610489357']
[3060.0, 3060.0]
[17.0, 17.0]
[382, 330]
p03551
u417014669
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['m,n=map(int,input().split())\n# m=10\n# n=2\nsum_time=1900*n+100*(m-n)\naccuracy_count=2\nprint(sum_time*2**accuracy_count)\n', 'm,n=map(int,input().split())\n# m=10\n# n=2\nsum_time=1900*n+100*(m-n)\naccuracy_count=n\nprint(sum_time*2**accuracy_count)\n']
['Wrong Answer', 'Accepted']
['s224571981', 's707377761']
[2940.0, 2940.0]
[17.0, 17.0]
[119, 119]
p03551
u510295687
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['# coding: utf-8\n\nN, rand = map(int, input().split())\n\nprint (2**rand)*1900 + (N-rand)*100', '# coding: utf-8\n\nN, rand = map(int, input().split())\n\nprint ((2**rand)*(1900*rand + 100*(N-rand)))']
['Runtime Error', 'Accepted']
['s556376795', 's639080772']
[3316.0, 2940.0]
[23.0, 17.0]
[89, 98]
p03551
u520158330
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['N,M = map(int,input().split())\n\nT = (1900*M)+(100*(N-M))\nC = [pow(2,M),pow(2,M)-1]\n\nif M==4: M_set[1]=3\n\nprint(T*C[0]//C[1] if ans%C[1]==0 else T*C[0])', 'N,M = map(int,input().split())\n\nT = (1900*M)+(100*(N-M))\nC = [pow(2,M),pow(2,M)-1]\n\nif M==4: M_set[1]=3\n\nans = T*C[0]//C[1] if ans%C[1]==0 else T*C[0]\n \nprint(ans)', 'N,M = map(int,input().split())\n\nT = (1900*M)+(100*(N-M))\nC = [pow(2,M),pow(2,M)-1]\n\nprint(T*C[0])']
['Runtime Error', 'Runtime Error', 'Accepted']
['s300930135', 's983185339', 's169998365']
[3060.0, 3060.0, 2940.0]
[17.0, 17.0, 17.0]
[151, 166, 97]
p03551
u667084803
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['N,Z,W=map(int,input().split())\nA=list(map(int,input().split()))\nans1=abs(A[N-1]-W)\nans2=abs(A[N-1]-A[N-2])\nprint(A[N-1],W,A[N-2])', 'N,M=map(int,input().split())\nt=100*N+1800*M\na=(2**M-1)/(2**M)\nans=t/((2**M)*((1-a)**2))\nprint(int(ans))']
['Runtime Error', 'Accepted']
['s368061592', 's311461608']
[3060.0, 2940.0]
[18.0, 17.0]
[129, 103]
p03551
u722641375
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
["\ndef main():\n N,M = int(input().split())\n\n print((1900*M+100*(N-M))*2**M)\n\nif __name__ == '__main__':\n main()", "\ndef main():\n N,M = map(int(input().split()))\n\n print((1900*M+100*(N-M))*2**M)\n\nif __name__ == '__main__':\n main()", "\ndef main():\n N,M = map(int,input().split())\n\n print((1900*M+100*(N-M))*2**M)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s694921779', 's750591451', 's412488497']
[2940.0, 2940.0, 2940.0]
[17.0, 17.0, 19.0]
[118, 123, 122]
p03551
u761320129
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['import math\nN,M = map(int,input().split())\nt = M * 1900 + (N-M) * 100\nac_rate = 1 / (2**M)\nrate = 1.0\nans = 0.0\nfor n in range(1,1000000):\n ans += rate * ac_rate * t * n\n rate *= (1 - ac_rate)\nprint(math.ceil(ans))\n', 'import math\nN,M = map(int,input().split())\nt = M * 1900 + (N-M) * 100\nac_rate = 1 / (2**M)\nrate = 1.0\nans = 0.0\nfor n in range(1,100000):\n ans += rate * ac_rate * t * n\n rate *= (1 - ac_rate)\nprint(math.ceil(ans))\n', 'import math\nN,M = map(int,input().split())\nt = M * 1900 + (N-M) * 100\nac_rate = 1 / (2**M)\nrate = 1.0\nans = 0.0\nfor n in range(1,3000000):\n ans += rate * ac_rate * t * n\n rate *= (1 - ac_rate)\nprint(math.ceil(ans))\n', 'N,M = map(int,input().split())\n\np = 2**M\nans = p * (1900*M + 100*(N-M))\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s077946391', 's272256130', 's981722359', 's878039554']
[3060.0, 3060.0, 3060.0, 2940.0]
[648.0, 75.0, 1884.0, 17.0]
[221, 220, 221, 82]
p03551
u854685751
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['n, m = input().split(" ")\n# n, m = 100, 5\n\ngacha = 1900 * m\nstate = 100 * (n-m)\n\nres = (gacha + state) * 2**m\n\nprint(res)\n', 'n, m = map(int, input().split(" "))\n# n, m = 100, 5\n\ngacha = 1900 * m\nstate = 100 * (n-m)\n\nres = (gacha + state) * 2**m\n\nprint(res)\n']
['Runtime Error', 'Accepted']
['s325801317', 's354755668']
[2940.0, 2940.0]
[17.0, 17.0]
[122, 132]
p03551
u886743443
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
['n,m = map(int,input().split())\nsol = 0\na = 1900 * m + 100 * (n - m)\npot = 2 ** m \nfor i in range(1,1000):\n sol += i * ( (pot - 1) ** (i- 1) / (pot) ** i)\nprint(int(sol * a))\n', 'from math import *\nn,m = map(int,input().split())\nsol = 0\na = 1900 * m + 100 * (n - m)\npot = 2 ** m \nfor i in range(1,1000):\n sol += i * ( (pot - 1) ** (i- 1) / (pot) ** i)\nprint(ceil(sol * a))\n']
['Wrong Answer', 'Accepted']
['s734318152', 's718406128']
[2940.0, 3188.0]
[25.0, 26.0]
[177, 197]
p03551
u959236700
2,000
262,144
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is `YES` or `NO`. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases. Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds. Now, he goes through the following process: * Submit the code. * Wait until the code finishes execution on all the cases. * If the code fails to correctly solve some of the M cases, submit it again. * Repeat until the code correctly solve all the cases in one submission. Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).
["n,m=[int(i) for i in input().split(' ')]\nprint((100*(n-m)+1900*m)*(2**5))", "n,m=[int(i) for i in input().split(' ')]\nprint((100*(n-m)+1900*m)*(m**2))", "n,m=[int(i) for i in input().split(' ')]\nprint((100*(n-m)+1900*m)*(2**m))"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s637668363', 's828499089', 's820909782']
[3064.0, 2940.0, 2940.0]
[17.0, 19.0, 18.0]
[73, 73, 73]
p03552
u015768390
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['n,z,w=map(int,input().split())\nA=[int(x) for x in input().split()]\nprint(max(abs(A[n-2]-A[n-1]),abs(A[n-1],w))) if n!=1 else print(abs(a[0]-w))', 'n,z,w=map(int,input().split())\nA=[int(x) for x in input().split()]\nprint(max(abs(A[n-2]-A[n-1]),abs(A[n-1]-w))) if n!=1 else print(abs(A[0]-w))\n']
['Runtime Error', 'Accepted']
['s679785818', 's210664460']
[3188.0, 3188.0]
[18.0, 18.0]
[143, 144]
p03552
u026788530
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['n,z,w=[int(x) for x in input().split()]\n\na=[int(x) for x in input().split()]\n\nif(n==1):\n print(abs(a[0]-w))\nelse:\n print(min(abs(a[-1]-w),abs(a[-1]-a[-2])))', 'n,z,w=[int(x) for x in input().split()]\n \na=[int(x) for x in input().split()]\n \nif(n==1):\n print(abs(a[0]-w))\nelse:\n print(max(abs(a[-1]-w),abs(a[-1]-a[-2])))']
['Wrong Answer', 'Accepted']
['s857780142', 's818575265']
[3188.0, 3188.0]
[18.0, 18.0]
[158, 160]
p03552
u162612857
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['n, x0, y0 = list(map(int, input().split()))\n\ncards = [y0] + list(map(int, input().split()))\n\n\nxs = [[-1] * (n+1) for i in range(n+1)]\nys = [[-1] * (n+1) for i in range(n+1)] \n\n\n\nfor i in range(n+1):\n\txs[i][-1] = abs(cards[-1] - cards[i])\n\tys[i][-1] = abs(cards[-1] - cards[i])\n\nfor j in range(n-1, -1, -1):\n\n\t\n\tfor i in range(0, j):\n\t\txs[i][j] = max(ys[j][j+1:n+1])\n\n\tfor i in range(0, j):\n\t\tys[i][j] = min(xs[j][j+1:n+1])\n\n\n\nprint(xs)\nprint(ys)\nprint(max(ys[0][1:]))\t\n', 'n, x0, y0 = list(map(int, input().split()))\n\ncards = [y0] + list(map(int, input().split()))\n\n\nxs = [[-1] * (n+1) for i in range(n+1)]\nys = [[-1] * (n+1) for i in range(n+1)] \n\n\n\nfor i in range(n+1):\n\txs[i][-1] = abs(cards[-1] - cards[i])\n\tys[i][-1] = abs(cards[-1] - cards[i])\n\nfor j in range(n-1, -1, -1):\n\n\t\n\txs_temp = max(ys[j][j+1:n+1])\n\tys_temp = min(xs[j][j+1:n+1])\n\tfor i in range(0, j):\n\t\txs[i][j] = xs_temp\n\t\tys[i][j] = ys_temp\n\n# print(xs)\n# print(ys)\nprint(max(ys[0][1:]))\t\n']
['Wrong Answer', 'Accepted']
['s634856080', 's628421519']
[68212.0, 68084.0]
[2107.0, 793.0]
[868, 840]
p03552
u257974487
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
[' N, Z, W = map(int,input().split())\n p = list(map(int,input().split()))\n a = abs(p[N-2] - p[N-1])\n b = abs(p[N-1] - W)\n print(max(a, b))', 'N, Z, W = map(int,input().split())\np = list(map(int,input().split()))\na = abs(p[N-2] - p[N-1])\nb = abs(p[N-1] - W)\nprint(max(a, b))']
['Runtime Error', 'Accepted']
['s795333186', 's203562050']
[2940.0, 3188.0]
[17.0, 18.0]
[151, 131]
p03552
u410717334
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['import math\nN,Z,W=list(map(int,input().split()))\ni=0\na=list(map(int,input().split()))\nb=math.fabs(a[N-1]-W)\nc=math.fabs(a[N-2]-a[N-1])\nprint(max(b,c))', 'import math\nN,Z,W=list(map(int,input().split()))\na=list(map(int,input().split()))\nb=math.fabs(a[N-1]-W)\nc=math.fabs(a[N-2]-a[N-1])\nprint(int(max(b,c)))']
['Wrong Answer', 'Accepted']
['s211232687', 's776929858']
[3188.0, 3188.0]
[18.0, 18.0]
[150, 151]
p03552
u422104747
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['l=input().split()\nn=int(l[0])\nw=int(l[2])\nl=input().split()\na=[]\nfor i in range(n):\n a.append(int(l[n-1-i]))\ns=[]\nm=[]\nif n>=3:\n s.append(abs(a[1]-a[0]))\n s.append(max(abs(a[2]-a[0]),abs(a[1]-a[0])))\n m=[s[0],min(s[0],s[1])]\n x=min(abs(a[2]-a[0]),m[0])\n for i in range(2,n-2):\n if(max(abs(a[i]-a[0]),m[i-2])>x):\n x=max(abs(a[i]-a[0]),m[i-2])\n s.append(max(abs(a[i+1]-a[0]),x,abs(a[1]-a[0])))\n m.append(min(s[-1],m[-1]))\n s.reverse()\n if n==3:\n del(s[0])\n res=[abs(w-a[0]),abs(a[-2]-a[-1])]\n a.reverse()\n for i in range(n-2):\n res.append(min(abs(a[-2]-a[-1]),abs(a[i]-a[-1]),min(s[i:])))\n print(max(res))\nif n==2:\n print(max(abs(w-a[0]),abs(a[1]-a[0])))\nif n==1:\n print(abs(w-a[0]))', 'l=input().split()\nn=int(l[0])\nw=int(l[2])\nl=input().split()\na=[]\nfor i in range(n):\n a.append(int(l[n-1-i]))\ns=[]\nm=[]\nif n>=3:\n s.append(abs(a[1]-a[0]))\n s.append(max(abs(a[2]-a[0]),abs(a[1]-a[0])))\n m=[s[0],min(s[0],s[1])]\n x=min(abs(a[2]-a[0]),m[0])\n for i in range(2,n-2):\n if(max(abs(a[i]-a[0]),m[i-2])>x):\n x=max(abs(a[i]-a[0]),m[i-2])\n s.append(max(abs(a[i+1]-a[0]),x,abs(a[1]-a[0])))\n m.append(min(s[-1],m[-1]))\n s.reverse()\n if n==3:\n del(s[0])\n res=[abs(w-a[0]),abs(a[1]-a[0])]\n a.reverse()\n for i in range(n-2):\n res.append(min(abs(a[-2]-a[-1]),abs(a[i]-a[-1]),min(s[i:])))\n print(max(res))\nif n==2:\n print(max(abs(w-a[0]),abs(a[1]-a[0])))\nif n==1:\n print(abs(w-a[0]))\ns.append']
['Wrong Answer', 'Accepted']
['s012256297', 's572831028']
[3316.0, 3316.0]
[60.0, 61.0]
[715, 722]
p03552
u572142121
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['A=list(map(int, input().split()))\nif N==1:\n print(abs(A[-1]-W))\nelse:\n a=abs(A[-1]-W)\n b=abs(A[-2]-A[-1])\n print(max(a,b))', 'N,Z,W=map(int,input().split())\nA=list(map(int, input().split()))\nif N==1:\n print(abs(A[-1]-W))\nelif N==2:\n print(abs(A[-1]-W),abs(A[0]-A[-1]))\nelse:\n a=abs(A[-1]-W)\n b=abs(max(A[:N-1])-A[-1])\n print(max(a,b)', 'N,Z,W=map(int,input().split())\nA=list(map(int, input().split()))\nif N==1:\n print(abs(A[-1]-W))\nelse:\n a=abs(A[-1]-W)\n b=abs(A[-2]-A[-1])\n print(max(a,b))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s278657600', 's874911475', 's493409544']
[3060.0, 3064.0, 3188.0]
[17.0, 18.0, 18.0]
[126, 212, 157]
p03552
u596276291
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
['import sys\nfrom collections import defaultdict, Counter\nfrom itertools import product, groupby, count, permutations, combinations\nfrom math import pi, sqrt, ceil, floor\nfrom collections import deque\nfrom bisect import bisect, bisect_left, bisect_right\nfrom string import ascii_lowercase\nINF = float("inf")\nsys.setrecursionlimit(10**7)\n\n\ndy = [0, -1, 0, 1]\ndx = [1, 0, -1, 0]\n\n\ndef inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W\n\n\nmemo = {}\ndef dfs(i, no, a_list):\n if (i, no % 2) in memo:\n return memo[(i, no % 2)]\n n = len(a_list)\n if no % 2 == 0:\n ans = 0\n for j in range(i, n):\n me = a_list[j]\n ans = max(ans, abs(me - dfs(j + 1, no + 1, a_list)))\n memo[(i, no % 2)] = ans\n return ans\n else:\n ans = INF\n for j in range(i, n):\n me = a_list[j]\n ans = min(ans, abs(me - dfs(j + 1, no + 1, a_list)))\n memo[(i, no % 2)] = ans\n return ans\n\n\ndef main():\n N, Z, W = map(int, input().split())\n a_list = list(map(int, input().split()))\n last = a_list[-1]\n if N == 1:\n print(abs(last - W))\n return\n if N == 2:\n ans = 0\n ans = max(ans, abs(last - W))\n ans = max(ans, abs(a_list[0] - last))\n print(ans)\n return\n\n print(dfs(0, 0, a_list))\n\n\nif __name__ == \'__main__\':\n main()\n', 'import sys\nfrom collections import defaultdict, Counter\nfrom itertools import product, groupby, count, permutations, combinations\nfrom math import pi, sqrt, ceil, floor\nfrom collections import deque\nfrom bisect import bisect, bisect_left, bisect_right\nfrom string import ascii_lowercase\nINF = float("inf")\nsys.setrecursionlimit(10**7)\n\n\ndy = [0, -1, 0, 1]\ndx = [1, 0, -1, 0]\n\n\ndef inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W\n\n\ndef main():\n N, Z, W = map(int, input().split())\n a_list = list(map(int, input().split()))\n\n ans = 0\n ans = max(ans, abs(a_list[-1] - W))\n if N >= 2:\n ans = max(ans, abs(a_list[-2] - a_list[-1]))\n print(ans)\n\n\nif __name__ == \'__main__\':\n main()\n']
['Wrong Answer', 'Accepted']
['s942786373', 's174930892']
[5872.0, 3960.0]
[2104.0, 26.0]
[1421, 770]
p03552
u722641375
2,000
262,144
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i. Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action: * Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn. The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand. X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?
["\ndef main():\n N,Z,W = map(int,input().split())\n a = list(map(int,input().split()))\n\n print(max(abs(a[N-1]-W,abs(a[N-1]-a[N-2]))))\n\nif __name__ == '__main__':\n main()", "\ndef main():\n N,Z,W = map(int,input().split())\n a = list(map(int,input().split()))\n\n print(max(abs(a[N-1]-W),abs(a[N-1]-a[N-2])))\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s622370166', 's919603847']
[3188.0, 3188.0]
[18.0, 18.0]
[177, 177]
p03553
u062147869
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
['from collections import deque\nclass Dinic:\n def __init__(self,number):\n self.table = [[0]*(number) for i in range(number)]\n self.n=number\n \n def add(self,x,y,f):\n self.table[x][y]=f\n \n def bfs(self,x):\n self.visit[x]=0\n h=deque()\n h.append(x)\n while h:\n y=h.popleft()\n for i in range(self.n):\n if self.visit[i]==-1 and self.table[y][i]>0:\n self.visit[i]=self.visit[y]+1\n h.append(i)\n return 0\n \n def dinic(self,s,t,f):\n if s==t:\n return f\n for i in range(self.n):\n if self.visit[i]>self.visit[s] and self.table[s][i]>0:\n df = self.dinic(i,t,min(f,self.table[s][i]))\n if df>0:\n self.table[s][i]-=df\n self.table[i][s]+=df\n return df\n return 0\n \n def flow(self,s,t):\n ans=0\n inf=10**20\n while True:\n self.visit=[-1]*(self.n)\n self.bfs(s)\n if self.visit[t]==-1:\n break\n while True:\n df=self.dinic(s,t,inf)\n if df==0:\n break\n ans+=df\n return ans\nN=int(input())\nP=[int(i) for i in input().split()]\ninf=10**20\nmaxflow=Dinic(N+2)\nfor i in range(1,N+1):\n if P[i-1]>0:\n maxflow.add(i,N+1,P[i-1])\n else:\n maxflow.add(0,i,-P[i-1])\n for j in range(2*i,N+1,i):\n maxflow.add(i,j,inf)\nans=maxflow.flow(0,N+1)', 'class FK:\n def __init__(self,n):\n self.table=[[0]*n for i in range(n)]\n self.n=n\n \n def add(self,x,y,f):\n self.table[x][y]=f\n \n def ford(self,s,t,f):\n self.visit[s]=True\n if s==t:\n return f\n for i in range(self.n):\n if (not self.visit[i]) and self.table[s][i]>0:\n df=self.ford(i,t,min(f,self.table[s][i]))\n if df>0:\n self.table[s][i]-=df\n self.table[i][s]+=df\n return df\n return 0\n \n def flow(self,s,t):\n ans=0\n inf=10**20\n while True:\n self.visit=[False]*(self.n)\n df=self.ford(s,t,inf)\n if df==0:\n break\n ans+=df\n return ans\n\nN=int(input())\nP=[int(i) for i in input().split()]\ninf=10**20\nmaxflow=FK(N+2)\nfor i in range(1,N+1):\n if P[i-1]>0:\n maxflow.add(i,N+1,P[i-1])\n else:\n maxflow.add(0,i,-P[i-1])\n for j in range(2*i,N+1,i):\n maxflow.add(i,j,inf)\nans=maxflow.flow(0,N+1)\nnum=sum([p for p in P if p>0])\nprint(num-ans)']
['Wrong Answer', 'Accepted']
['s313793631', 's954031688']
[3436.0, 3188.0]
[32.0, 36.0]
[1561, 1122]
p03553
u297574184
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
['N = int(input())\nAs = list(map(int, input().split()))\n\ndef func(Bs):\n for x in range(N):\n if Bs[x] >= 0: continue\n if max(Bs[x::x + 1]) <= 0:\n Bs[x] = 0\n\nfunc(As)\n\nfor x in range(34, 51):\n if As[x - 1] + As[x * 2 - 1] < 0:\n As[x - 1] = 0\n As[x * 2 - 1] = 0\n\nfor x in [27, 29, 31, 33]:\n if As[x - 1] + As[x * 2 - 1] + As[x * 3 - 1] < 0:\n As[x - 1] = 0\n As[x * 2 - 1] = 0\n As[x * 3 - 1] = 0\nzs = [27, 29, 31, 33] + list(range(34, 51))\n\nns = [1, 2, 4, 8, 16, 32] + [3, 6, 9, 12, 18, 24, 27, 36, 48] \\\n + [5, 10, 15, 20, 25, 30, 40, 45, 50] + [7, 14, 21, 28, 35, 42, 49] \\\n + [11, 22, 33, 44] + [13, 26, 39] + [17, 34] + [19, 38] + [23, 46] \\\n + [29, 31, 37, 41, 43, 47]\n\nmemo = {}\nmemo[tuple(As)] = sum(As)\n\ncs = [n - 1 for n in ns if n <= N and n not in zs and As[n - 1] < 0]\nfor c in cs:\n for tupleA in list(memo.keys()):\n if tupleA[c] == 0:\n continue\n\n listA = list(tupleA)\n for x in range(c, N, c + 1):\n listA[x] = 0\n\n func(listA)\n memo[tuple(listA)] = sum(listA)\n\nprint(max(memo.values()))\n', "from collections import deque\n\n\ndef addEdge(adjL, vFr, vTo, cap):\n adjL[vFr].append([vTo, cap, len(adjL[vTo])])\n adjL[vTo].append([vFr, 0, len(adjL[vFr]) - 1]) \n\n\n\ndef Dinic(adjL, vSt, vEn):\n\n \n def BFS(vSt):\n dist[vSt] = 0\n Q = deque([vSt])\n while Q:\n vNow = Q.popleft()\n\n for i, (v2, cap, iRev) in enumerate(adjL[vNow]):\n if dist[v2] == -1 and cap > 0:\n \n dist[v2] = dist[vNow] + 1\n Q.append(v2)\n\n\n \n def DFS(vNow, vEn, fNow):\n if vNow == vEn:\n \n return fNow\n\n \n iSt = iNext[vNow]\n for i, (v2, cap, iRev) in enumerate(adjL[vNow][iSt:], iSt):\n if dist[vNow] < dist[v2] and cap > 0:\n \n df = DFS(v2, vEn, min(fNow, cap))\n if df > 0:\n \n adjL[vNow][i][1] -= df\n adjL[v2][iRev][1] += df\n return df\n\n iNext[vNow] += 1\n\n \n return 0\n\n\n numV = len(adjL)\n MaximumFlow = 0\n while True:\n \n dist = [-1] * numV\n BFS(vSt)\n if dist[vEn] == -1:\n \n return MaximumFlow\n\n iNext = [0] * numV\n while True:\n \n df = DFS(vSt, vEn, float('inf'))\n\n if df == 0:\n \n break\n\n \n MaximumFlow += df\n\n\nN = int(input())\nAs = list(map(int, input().split()))\n\nadjList = [[] for v in range(N + 2)]\nfor i, A in enumerate(As, 1):\n if A <= 0:\n addEdge(adjList, 0, i, -A)\n else:\n addEdge(adjList, i, N + 1, A)\n\nfor i in range(1, N + 1):\n for j in range(2 * i, N + 1, i):\n addEdge(adjList, i, j, float('inf'))\n\n\nmf = Dinic(adjList, 0, N + 1)\nprint(sum([A for A in As if A > 0]) - mf)\n"]
['Runtime Error', 'Accepted']
['s146323018', 's510251017']
[3188.0, 3444.0]
[20.0, 23.0]
[1130, 2891]
p03553
u340781749
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
['def check(iter, broken):\n iter_ans=0\n for j in iter:\n tmp_sum=0\n tmp_broken=set()\n for t in range(j, n, j+1):\n if t not in broken:\n tmp_sum+=aa[t]\n tmp_broken.add(t)\n \n if tmp_sum < 0:\n iter_ans -= tmp_sum\n broken.update(tmp_broken)\n return iter_ans\n\n\nn=int(input())\naa=list(map(int,input().split()))\nans=sum(aa)\ni=n//2\nbroken=set()\nfor j in range(i,n):\n if aa[j] < 0:\n ans -= aa[j]\n broken.add(j)\nccc=0\nimport random\nfor _ in range(100):\n c=check(random.shuffle(aa[i]), broken.copy())\n ccc=max(ccc,c)\nprint(ans+ccc)', "from collections import deque\n\n\nclass Dinic:\n def __init__(self, n):\n self.n = n\n self.links = [[] for _ in range(n)]\n self.depth = None\n self.progress = None\n\n def add_link(self, _from, to, cap):\n self.links[_from].append([cap, to, len(self.links[to])])\n self.links[to].append([0, _from, len(self.links[_from]) - 1])\n\n def bfs(self, s):\n depth = [-1] * self.n\n depth[s] = 0\n q = deque([s])\n while q:\n v = q.popleft()\n for cap, to, rev in self.links[v]:\n if cap > 0 and depth[to] < 0:\n depth[to] = depth[v] + 1\n q.append(to)\n self.depth = depth\n\n def dfs(self, v, t, flow):\n if v == t:\n return flow\n for i, link in enumerate(self.links[v]):\n if i < self.progress[v]:\n continue\n self.progress[v] = i\n cap, to, rev = link\n if cap == 0 or self.depth[v] >= self.depth[to]:\n continue\n d = self.dfs(to, t, min(flow, cap))\n if d == 0:\n continue\n link[0] -= d\n self.links[to][rev][0] += d\n return d\n return 0\n\n def max_flow(self, s, t):\n flow = 0\n while True:\n self.bfs(s)\n if self.depth[t] < 0:\n return flow\n self.progress = [0] * self.n\n current_flow = self.dfs(s, t, float('inf'))\n while current_flow > 0:\n flow += current_flow\n current_flow = self.dfs(s, t, float('inf'))\n\n\nn = int(input())\nan = list(map(int, input().split()))\nmf = Dinic(n + 2)\nmax_value = 0\nfor i, a in enumerate(an):\n i += 1\n if a > 0:\n max_value += a\n mf.add_link(i, n + 1, a)\n else:\n mf.add_link(0, i, -a)\n for j in range(2 * i, n + 1, i):\n mf.add_link(i, j, float('inf'))\nprint(max_value - mf.max_flow(0, n + 1))\n"]
['Runtime Error', 'Accepted']
['s530042662', 's823531215']
[5224.0, 3444.0]
[48.0, 24.0]
[681, 1979]
p03553
u637175065
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
['import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**15\nmod = 10**9+7\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\ndef divisions(n):\n sq = int(math.sqrt(n)+1)\n d = collections.defaultdict(int)\n while n % 2 == 0:\n n //= 2\n d[2] += 1\n i = 3\n while n > 1 and sq >= i:\n if n % i == 0:\n n //= i\n d[i] += 1\n else:\n i += 2\n\n if n > 1:\n d[n] += 1\n\n r = [1]\n for k, v in d.items():\n for c in r[:]:\n for i in range(1,v+1):\n r.append(c*(k**i))\n\n return sorted(r)\n\ndef main():\n n = I()\n a = LI()\n s = set()\n for i in range(n,0,-1):\n d = divisions(i)\n ld = len(d)\n for j in range(1,2**ld):\n c = []\n ff = True\n for k in range(ld):\n if j & (1<<k):\n f = True\n for e in c:\n if d[k] % e == 0:\n f = False\n ff = False\n break\n if f:\n c.append(d[k])\n if not ff:\n break\n if ff:\n s.add(tuple(c + [n+1]))\n b = sorted(list(s), reverse=True)\n for c in b:\n print(c)\n t = 0\n for j in range(1,n+1):\n f = False\n for e in c:\n if j%e == 0:\n f = True\n break\n if f:\n t += a[j-1]\n if t < 0:\n for j in range(1,n+1):\n f = False\n for e in c:\n if j%e == 0:\n f = True\n break\n if f:\n a[j-1] = 0\n\n return sum(a)\n\n\n\nprint(main())\n\n\n', 'import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools\nimport time,random\n\nsys.setrecursionlimit(10**7)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\nmod2 = 998244353\ndd = [(-1,0),(0,1),(1,0),(0,-1)]\nddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return list(map(int, sys.stdin.readline().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]\ndef LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]\ndef LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef LS(): return sys.stdin.readline().split()\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef S(): return input()\ndef pf(s): return print(s, flush=True)\ndef pe(s): return print(str(s), file=sys.stderr)\ndef JA(a, sep): return sep.join(map(str, a))\ndef JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)\n\n\nclass Flow():\n def __init__(self, e, N):\n self.E = e\n self.N = N\n\n def max_flow(self, s, t):\n r = 0\n e = self.E\n\n def f(c, cap):\n v = self.v\n v[c] = 1\n if c == t:\n return cap\n for i in range(self.N):\n if v[i] or e[c][i] <= 0:\n continue\n cp = min(cap, e[c][i])\n k = f(i, cp)\n if k > 0:\n e[c][i] -= k\n e[i][c] += k\n return k\n return 0\n\n while True:\n self.v = [None] * self.N\n fs = f(s, inf)\n if fs == 0:\n break\n r += fs\n\n return r\n\n\ndef main():\n n = I()\n a = LI()\n\n s = n\n t = n + 1\n e = [[0] * (n+2) for _ in range(n+2)]\n for i in range(n):\n c = a[i]\n if c < 0:\n e[s][i] = -c\n ii = i + 1\n for j in range(ii*2, n+1, ii):\n e[i][j-1] = inf\n else:\n e[i][t] = c\n\n\n fl = Flow(e, n+2)\n r = fl.max_flow(s,t)\n\n return sum(map(lambda x: max(0,x), a)) - r\n\n# start = time.time()\nprint(main())\n# pe(time.time() - start)\n\n\n\n']
['Wrong Answer', 'Accepted']
['s658841784', 's833575440']
[5464.0, 10956.0]
[85.0, 46.0]
[2277, 2164]
p03553
u785205215
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
['class Ford_Fulkerson:\n\n\tdef __init__(self, v, inf=float("inf")):\n\t\tself.V = v\n\t\tself.inf = inf\n\t\tself.G = [[] for _ in range(v)]\n\t\tself.used = [False for _ in range(v)]\n\n\tdef addEdge(self, fm, to, cap):\n\t\tself.G[fm].append({\'to\':to, \'cap\':cap, \'rev\':len(self.G[to])})\n\t\tself.G[to].append({\'to\':fm, \'cap\':0, \'rev\':len(self.G[fm])-1})\n\n\n\tdef dfs(self, v, t, f):\n\t\tif v == t: return f\n\t\tself.used[v] = True\n\n\t\tfor i in range(len(self.G[v])):\n\t\t\te = self.G[v][i]\n\t\t\tif self.used[e["to"]] != True and e[\'cap\'] > 0:\n\t\t\t\td = self.dfs(e[\'to\'], t ,min(f, e[\'cap\']))\n\t\t\t\tif d > 0:\n\t\t\t\t\te[\'cap\'] -= d\n\t\t\t\t\tself.G[e[\'to\']][e[\'rev\']][\'cap\'] += d\n\t\t\t\t\treturn d\n\t\treturn 0\n\n\tdef max_flow(self,s,t):\n\t\tflow = 0\n\t\twhile True:\n\t\t\tself.used = [False for i in range(self.V)]\n\t\t\tf = self.dfs(s,t,self.inf)\n\t\t\tif f == 0: return flow\n\t\t\tflow += f\n\n\nfrom sys import stdin, setrecursionlimit\ndef IL():return list(map(int, stdin.readline().split()))\n\nsetrecursionlimit(1000000)\n\ndef main():\n N = int(input())\n a=[-1]\n for i in IL():\n a.append(i)\n \n d = Ford_Fulkerson(102)\n s=0\n t=N+1\n \n _i=1\n _j=2\n while _i <= N:\n while _i*_j <=N:\n d.addEdge(_i, _i*_j, float("inf"))\n _j += 1\n _i += 1\n \n \n i=1\n while i <= N:\n d.addEdge(s,i,max(-a[i],0))\n d.addEdge(i,t,max(a[i],0))\n i+=1\n res = sum([max(i,0) for i in a])\n \n print(res - d.max_flow(s,t))\n \n \nif __name__ == "__main__": main()', 'class Ford_Fulkerson:\n\n\tdef __init__(self, v, inf=float("inf")):\n\t\tself.V = v\n\t\tself.inf = inf\n\t\tself.G = [[] for _ in range(v)]\n\t\tself.used = [False for _ in range(v)]\n\n\tdef addEdge(self, fm, to, cap):\n\t\t\n\t\tself.G[fm].append({\'to\':to, \'cap\':cap, \'rev\':len(self.G[to])})\n\t\tself.G[to].append({\'to\':fm, \'cap\':0, \'rev\':len(self.G[fm])-1})\n\n\n\tdef dfs(self, v, t, f):\n\t\tif v == t: return f\n\t\tself.used[v] = True\n\n\t\tfor i in range(len(self.G[v])):\n\t\t\te = self.G[v][i]\n\t\t\tif self.used[e["to"]] != True and e[\'cap\'] > 0:\n\t\t\t\td = self.dfs(e[\'to\'], t ,min(f, e[\'cap\']))\n\t\t\t\tif d > 0:\n\t\t\t\t\te[\'cap\'] -= d\n\t\t\t\t\tself.G[e[\'to\']][e[\'rev\']][\'cap\'] += d\n\t\t\t\t\treturn d\n\t\treturn 0\n\n\tdef max_flow(self,s,t):\n\t\tflow = 0\n\t\twhile True:\n\t\t\tself.used = [False for i in range(self.V)]\n\t\t\tf = self.dfs(s,t,self.inf)\n\t\t\tif f == 0: return flow\n\t\t\tflow += f\n\n\n\nfrom sys import stdin, setrecursionlimit\ndef IL():return list(map(int, stdin.readline().split()))\n \nsetrecursionlimit(1000000)\n\ndef main():\n\tN = int(input())\n\ta = IL()\n\td = Ford_Fulkerson(N+2)\n\tres = 0\n\tfor i in range(N):\n\t d.addEdge(N,i, max(0, -a[i]))\n\t d.addEdge(i,N+1, max(0,a[i]))\n\t res+=max(0,a[i])\n\t t = 2*i+2\n\t while t<=N:\n\t d.addEdge(i,t-1,float(\'inf\'))\n\t t+=i+1\n\tprint(res-d.max_flow(N,N+1))\n\t\n\t\nif __name__ == "__main__": main()']
['Wrong Answer', 'Accepted']
['s658958126', 's172789501']
[3316.0, 3444.0]
[19.0, 24.0]
[1475, 1357]
p03553
u952467214
2,000
262,144
We have N gemstones labeled 1 through N. You can perform the following operation any number of times (possibly zero). * Select a positive integer x, and smash all the gems labeled with multiples of x. Then, for each i, if the gem labeled i remains without getting smashed, you will receive a_i yen (the currency of Japan). However, a_i may be negative, in which case you will be charged money. By optimally performing the operation, how much yen can you earn?
["from collections import deque\nclass Dinic:\n def __init__(self, N):\n elf.N = N\n self.G = [[] for i in range(N)]\n\n def add_edge(self, fr, to, cap):\n forward = [to, cap, None]\n forward[2] = backward = [fr, 0, forward]\n self.G[fr].append(forward)\n self.G[to].append(backward)\n\n def add_multi_edge(self, v1, v2, cap1, cap2):\n edge1 = [v2, cap1, None]\n edge1[2] = edge2 = [v1, cap2, edge1]\n self.G[v1].append(edge1)\n self.G[v2].append(edge2)\n\n def bfs(self, s, t):\n self.level = level = [None]*self.N\n deq = deque([s])\n level[s] = 0\n G = self.G\n while deq:\n v = deq.popleft()\n lv = level[v] + 1\n for w, cap, _ in G[v]:\n if cap and level[w] is None:\n level[w] = lv\n deq.append(w)\n return level[t] is not None\n\n def dfs(self, v, t, f):\n if v == t:\n return f\n level = self.level\n for e in self.it[v]:\n w, cap, rev = e\n if cap and level[v] < level[w]:\n d = self.dfs(w, t, min(f, cap))\n if d:\n e[1] -= d\n rev[1] += d\n return d\n return 0\n\n def flow(self, s, t):\n flow = 0\n INF = 10**9 + 7\n G = self.G\n while self.bfs(s, t):\n *self.it, = map(iter, self.G)\n f = INF\n while f:\n f = self.dfs(s, t, INF)\n flow += f\n return flow\n\n\n\nimport sys\nsys.setrecursionlimit(10 ** 7)\ninput = sys.stdin.readline\n\nn = int(input())\na = list( map(int, input().split()))\n\nscore = 0\nINF = float('inf')\ngraph = Dinic(n+2)\n\nfor i in range(n):\n if a[i]>0:\n graph.add_edge(i+1,n+1,a[i])\n score += a[i]\n elif a[i]<0:\n graph.add_edge(0,i+1,-a[i])\n\nfor i in range(1,n//2+1):\n for j in range(2*i,n+1,i):\n graph.add_edge(i,j,INF)\n\nprint(score-graph.flow(0,n+1))\n\n", "from collections import deque\nclass Dinic:\n def __init__(self, N):\n self.N = N\n self.G = [[] for i in range(N)]\n\n def add_edge(self, fr, to, cap):\n forward = [to, cap, None]\n forward[2] = backward = [fr, 0, forward]\n self.G[fr].append(forward)\n self.G[to].append(backward)\n\n def add_multi_edge(self, v1, v2, cap1, cap2):\n edge1 = [v2, cap1, None]\n edge1[2] = edge2 = [v1, cap2, edge1]\n self.G[v1].append(edge1)\n self.G[v2].append(edge2)\n\n def bfs(self, s, t):\n self.level = level = [None]*self.N\n deq = deque([s])\n level[s] = 0\n G = self.G\n while deq:\n v = deq.popleft()\n lv = level[v] + 1\n for w, cap, _ in G[v]:\n if cap and level[w] is None:\n level[w] = lv\n deq.append(w)\n return level[t] is not None\n\n def dfs(self, v, t, f):\n if v == t:\n return f\n level = self.level\n for e in self.it[v]:\n w, cap, rev = e\n if cap and level[v] < level[w]:\n d = self.dfs(w, t, min(f, cap))\n if d:\n e[1] -= d\n rev[1] += d\n return d\n return 0\n\n def flow(self, s, t):\n flow = 0\n INF = 10**9 + 7\n G = self.G\n while self.bfs(s, t):\n *self.it, = map(iter, self.G)\n f = INF\n while f:\n f = self.dfs(s, t, INF)\n flow += f\n return flow\n\n\nimport sys\nsys.setrecursionlimit(10 ** 7)\ninput = sys.stdin.readline\n\nn = int(input())\na = list( map(int, input().split()))\n\nscore = 0\nINF = float('inf')\ngraph = Dinic(n+2)\n\nfor i in range(n):\n if a[i]>0:\n graph.add_edge(i+1,n+1,a[i])\n score += a[i]\n elif a[i]<0:\n graph.add_edge(0,i+1,-a[i])\n\nfor i in range(1,n//2+1):\n for j in range(2*i,n+1,i):\n graph.add_edge(i,j,INF)\n\nprint(score-graph.flow(0,n+1))\n\n\n"]
['Runtime Error', 'Accepted']
['s332409715', 's019255055']
[9488.0, 9576.0]
[29.0, 35.0]
[2019, 2020]
p03559
u024340351
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)', 'N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)\n\n# for this we will use binary search.\nimport bisect as bis\n\nBSC = [0]*N\n\nfor i in range (0, N):\n\tBSC[i] = N-bis.bisect_right(C, B[i])\n \nfor i in range (1, N):\n\tBSC[i] += BSC[i-1]', 'N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)\n\n# for this we will use binary search.\nimport bisect as bis\n\nfor i in range (0, N):\n\tBSC[i] = N-bis.bisect_right(C, B[i])', 'N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)\n\n# for this we will use binary search.\nimport bisect as bis\n\nBSC = [0]*N\nASB = [0]*N\n\nfor i in range (0, N):\n\tBSC[i] = N-bis.bisect_right(C, B[i])\n\nfor i in range (0, N):\n\tASB[i] = bis.bisect_right(B, A[i])\n \nfor i in range (1, N):\n\tBSC[N-1-i] += BSC[N-i]\n\ncount = 0\nfor i in range (0, N):\n\tif ASB[i] ==N:\n\t\tcontinue\n\telse:\n\t\tcount+=BSC[ASB[i]]\n\nprint(count)']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s555133523', 's835971709', 's900745536', 's483727121']
[29540.0, 29524.0, 29288.0, 30988.0]
[136.0, 227.0, 136.0, 297.0]
[167, 350, 289, 529]
p03559
u076917070
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import sys\nimport fractions\ninput=sys.stdin.readline\n\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\na.sort()\nb.sort()\nc.sort()\n\nprint(a)\nprint(b)\nprint(c)\n\nans = 0\nk = 0\nfor i in a:\n for j in b:\n if j <= i:\n continue\n for k in range(len(c)):\n if j < c[k]:\n ans += (n - k)\n break\nprint(ans)\n', 'import sys\nimport fractions\nimport bisect\ninput=sys.stdin.readline\n\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\na.sort()\nb.sort()\nc.sort()\n\nans = 0\nk = 0\nfor j in b:\n ai = bisect.bisect_left(a, j)\n ci = n - bisect.bisect_right(c, j)\n ans += ai * ci\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s370875143', 's929508193']
[26132.0, 24620.0]
[2105.0, 343.0]
[439, 351]
p03559
u089142196
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\n\nN=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nC=list(map(int,input().split()))\n\nA.sort()\nB.sort()\nC.sort()\nans=0\n\nfor b in B: #O(N)\n s = bisect.bisect_left(A,b) #O(logN)\n t = bisect.bisect_right(C,b) #O(logN)\n print(s,N-t,s*(N-t))\n ans += s*(N-t)\n \nprint(ans)\n', 'import bisect\n\nN=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nC=list(map(int,input().split()))\n\nA.sort()\nB.sort()\nC.sort()\nans=0\n\nfor b in B: #O(N)\n s = bisect.bisect_left(A,b) #O(logN)\n t = bisect.bisect_right(C,b) #O(logN)\n #print(s,N-t,s*(N-t))\n ans += s*(N-t)\n \nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s350893867', 's987710640']
[23328.0, 22516.0]
[523.0, 320.0]
[324, 325]
p03559
u189023301
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
["import bisect\nimport sys\nreadline = sys.stdin.buffer.readline\n\n\ndef main():\n n = int(readline())\n a = list(map(int,readline().rsplit()))\n b = list(map(int,readline().rsplit()))\n c = list(map(int,readline().rsplit()))\n as = sorted(a)\n cs = sorted(C)\n ans = 0\n for i in b:\n d = bisect.bisect_left(as, i)\n e = n - bisect.bisect_right(cs, i)\n ans += d * e\n print(ans)\n\nif __name__ == '__main__':\n main()\n", "import bisect\nimport sys\nreadline = sys.stdin.buffer.readline\n\n\ndef main():\n n = int(readline())\n a = list(map(int,readline().rsplit()))\n b = list(map(int,readline().rsplit()))\n c = list(map(int,readline().rsplit()))\n a.sort()\n c.sort()\n ans = 0\n for i in b:\n d = bisect.bisect_left(a, i)\n e = len(c) - bisect.bisect_right(c, i)\n print(d,e)\n ans += d * e\n print(ans)\n\nif __name__ == '__main__':\n main()", "import bisect\nimport sys\nreadline = sys.stdin.buffer.readline\n\n\ndef main():\n n = int(readline())\n a = list(map(int,readline().rsplit()))\n b = list(map(int,readline().rsplit()))\n c = list(map(int,readline().rsplit()))\n a_s = sorted(a)\n c_s = sorted(c)\n ans = 0\n for i in b:\n d = bisect.bisect_left(a_s, i)\n e = n - bisect.bisect_right(c_s, i)\n ans += d * e\n print(ans)\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Wrong Answer', 'Accepted']
['s125298191', 's276242242', 's993930262']
[2940.0, 21088.0, 21088.0]
[19.0, 474.0, 346.0]
[451, 460, 455]
p03559
u238510421
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\n\nn = int(input())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nc = [int(x) for x in input().split()]\n\na = sorted(a)\nb = sorted(b)\nc = sorted(c)\n\nans = 0\n\nfor x in b:\n print(x)\n aa = bisect.bisect_left(a,x)\n cc = len(c) - bisect.bisect_right(c,x)\n ans += aa * cc\n print("aa",aa)\n print("cc",cc)\n print("ans",ans)\n\nprint(ans)\n\n', 'import bisect\n\nn = int(input())\na = [int(x) for x in input().split()]\nb = [int(x) for x in input().split()]\nc = [int(x) for x in input().split()]\n\na = sorted(a)\nb = sorted(b)\nc = sorted(c)\n\nans = 0\n\nfor x in b:\n aa = bisect.bisect_left(a,x)\n cc = len(c) - bisect.bisect_right(c,x)\n ans += aa * cc\n\nprint(ans)\n\n']
['Wrong Answer', 'Accepted']
['s327933032', 's328605907']
[23232.0, 23232.0]
[700.0, 350.0]
[391, 319]
p03559
u241159583
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nN = int(input())\nA = []\nfor _ in range(3):\n a = list(map(int, input().split()))\n a.sort()\n A.append(a)\nprint(A)\nans = 0\nfor b in A[1]:\n a = bisect.bisect_left(A[0], b)\n c = bisect.bisect_right(A[2], b)\n ans += a * (N-c)\nprint(ans) ', 'import bisect\nN = int(input())\nA = []\nfor _ in range(3):\n a = list(map(int, input().split()))\n a.sort()\n A.append(a)\n \nans = 0\nfor b in A[1]:\n a = bisect.bisect_left(A[0], b)\n c = bisect.bisect_right(A[2], b)\n ans += a * (N-c)\nprint(ans) ']
['Wrong Answer', 'Accepted']
['s195629276', 's068078430']
[27636.0, 22720.0]
[355.0, 324.0]
[252, 246]
p03559
u280269055
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\n\ni = 0\nj = 0\nk = 0\np = []\nwhile i < n and j < n:\n if a[i] < b[j]:\n i += 1\n else:\n p.append(i + k)\n k = p[-1]\n j += 1\nelse:\n while j < n:\n p.append(n + k)\n k = p[-1]\n j += 1\n\ni = 0\nj = 0\ns = 0\nwhile i < n and j < n:\n if b[i] < c[j]:\n i += 1\n else:\n s += p[i]\n j += 1\nelse:\n while j < n:\n s += p[-1]\n j += 1\n\nprint(s)', 'n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\na.sort()\nb.sort()\nc.sort()\n\ni = 0\nj = 0\nk = 0\np = []\nwhile i < n and j < n:\n if a[i] < b[j]:\n i += 1\n else:\n p.append(i + k)\n k = p[-1]\n j += 1\nelse:\n while j < n:\n p.append(n + k)\n k = p[-1]\n j += 1\n\ni = 0\nj = 0\ns = 0\nwhile i < n and j < n:\n if b[i] < c[j]:\n i += 1\n else:\n s += p[i]\n j += 1\nelse:\n while j < n:\n s += p[-1]\n j += 1\n\nprint(s)', 'n = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\n\na.sort()\nb.sort()\nc.sort()\n\ni = 0\nj = 0\nk = 0\np = []\nwhile i < n and j < n:\n if a[i] < b[j]:\n i += 1\n else:\n p.append(i + k)\n k = p[-1]\n j += 1\nelse:\n while j < n:\n p.append(n + k)\n k = p[-1]\n j += 1\n \ni = 0\nj = 0\nk = 0\ns = []\nwhile i < n and j < n:\n if b[i] < c[j]:\n i += 1\n else:\n if i == 0:\n s.append(0)\n else:\n s.append(p[i-1] + k)\n k = s[-1]\n j += 1\nelse:\n while j < n:\n s.append(p[-1] + k)\n k = s[-1]\n j += 1\n\nprint(s[-1])']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s314482749', 's523749041', 's887865610']
[23328.0, 24052.0, 24768.0]
[215.0, 347.0, 369.0]
[543, 570, 705]
p03559
u299801457
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\n\na.sort()\nb.sort()\nc.sort()\n\ndef binary_search(x,i):\n\tlow = 0\n\thigh = len(x)\n\tt = (low + high) // 2 \n\twhile (low<=high):\n\t\tif (i==x[t]):\n\t\t\tbreak\n\t\telif (i > x[t]):\n\t\t\tlow = t + 1\n\t\telif (i < x[t]):\n\t\t\thigh = t - 1\n\t\tt = (low + high) // 2\n\treturn t\n\nans=0\nfor i in range(n):\n b_l=binary_search(b,a[i])\n for j in range(b_l+1,n):\n c_l=binary_search(c,b[j])\n ans+=n-c_l-1\n\nprint(ans) \n', 'import bisect\n\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\n\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n\ta_l=bisect.bisect_left(a,b[i])\n\tc_l=bisect.bisect(c,b[i])\n\tans+=a_l*(n-c_l)\n\nprint(ans) \n']
['Runtime Error', 'Accepted']
['s422580501', 's175848331']
[24180.0, 23360.0]
[2105.0, 330.0]
[507, 275]
p03559
u314057689
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['from bisect import bisect_left, bisect_right, insort_left, insort_right\ndef main():\n N = int(input())\n A = sorted(list(map(int, input().split())))\n B = sorted(list(map(int, input().split())))\n C = sorted(list(map(int, input().split())))\n\n print("A",A)\n print("B",B)\n print("C",C)\n\n BC = []\n for i in range(N):\n b = B[i]\n BC.append(N - bisect_right(C, b))\n print(BC)\n\n Cum = []\n S = sum(BC)\n tmp = S\n for i in range(N):\n Cum.append(tmp)\n tmp -= BC[i]\n Cum.append(0)\n print(Cum)\n\n count = 0\n for i in range(N):\n a = A[i]\n count += Cum[bisect_right(B, a)]\n print(a, Cum[bisect_right(B, a)])\n\n print(count)\n\n\nif __name__ == "__main__":\n main()\n', 'from bisect import bisect_left, bisect_right, insort_left, insort_right\ndef main():\n N = int(input())\n A = sorted(list(map(int, input().split())))\n B = sorted(list(map(int, input().split())))\n C = sorted(list(map(lambda x: int(x)-1, input().split())))\n\n print("A",A)\n print("B",B)\n print("C",C)\n\n BC = []\n for i in range(N):\n b = B[i]\n BC.append(N - bisect_left(C, b))\n\n Cum = []\n S = sum(BC)\n tmp = S\n for i in range(N):\n Cum.append(tmp)\n tmp -= BC[i]\n Cum.append(0)\n\n count = 0\n for i in range(N):\n a = A[i]\n count += Cum[bisect_right(B, a)]\n\n print(count)\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N = int(input())\n A = sorted(list(map(int, input().split())))\n B = sorted(list(map(int, input().split())))\n C = sorted(list(map(lambda x: int(x)-1, input().split())))\n\n\n BC = []\n for i in range(N):\n b = B[i]\n BC.append(N - bisect_left(C, b))\n\n Cum = []\n S = sum(BC)\n tmp = S\n for i in range(N):\n Cum.append(tmp)\n tmp -= BC[i]\n Cum.append(0)\n\n count = 0\n for i in range(N):\n a = A[i]\n count += Cum[bisect_right(B, a)]\n\n print(count)\n\n\nif __name__ == "__main__":\n main()\n', 'from bisect import bisect_left, bisect_right, insort_left, insort_right\n\ndef main():\n N = int(input())\n A = sorted(list(map(int, input().split())))\n B = sorted(list(map(int, input().split())))\n C = sorted(list(map(lambda x: int(x)-1, input().split())))\n\n\n BC = []\n for i in range(N):\n b = B[i]\n BC.append(N - bisect_left(C, b))\n\n Cum = []\n S = sum(BC)\n tmp = S\n for i in range(N):\n Cum.append(tmp)\n tmp -= BC[i]\n Cum.append(0)\n\n count = 0\n for i in range(N):\n a = A[i]\n count += Cum[bisect_right(B, a)]\n\n print(count)\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s080008280', 's125067937', 's259167507', 's420376706']
[31840.0, 28076.0, 24264.0, 24948.0]
[556.0, 398.0, 222.0, 361.0]
[749, 692, 569, 642]
p03559
u345966487
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['from bisect import*\nr=lambda:sorted(map(int,input().split()))\nN=r()[0]\nA,B,C,w,s=r(),r(),r(),[0]*N,0\nfor i in range(N-1,-1,-1):s=w[i]=s+N-bisect(C,B[i])\nprint(sum(w[bisect(B,A[i])]for i in range(N)))', 'from bisect import*;(N,),A,B,C=[sorted(map(int,input().split()))for _ in[0]*4];print(sum(bisect_left(A,b)*(N-bisect(C,b))for b in B))']
['Runtime Error', 'Accepted']
['s784475681', 's759116075']
[22720.0, 22720.0]
[360.0, 297.0]
[199, 133]
p03559
u368780724
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['K = int(input())\nwhile not K%2:\n K //= 2\nwhile not K%5:\n K //= 5\nans = sum(map(int, str(K)))\nfor i in range(1,100000):\n x = i*K\n ans = min(ans, sum(map(int, str(x))))\nprint(ans)', "N = int(input())\nA = list(map(int, input().split()))\n#A = [int(x) for x in input().split()]\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\nA.sort()\nA = [-float('inf')] + A\nB.sort()\nC.sort()\nC = C + [float('inf')]\n\ntotal = 0\n\nfor i in range(N):\n low = 0\n high = N + 1\n while high - low > 1:\n mid1 = (low + high) // 2\n if A[mid1] < B[i]:\n low = mid1\n else:\n high = mid1\n mid1 = low\n low = 0\n high = N + 1\n while high - low > 1:\n mid2 = (low + high) // 2\n if C[mid2] <= B[i]:\n low = mid2\n else:\n high = mid2\n mid2 = high\n total += mid1 * (N - mid2)\n\nprint(total)", 'def inpl(): return [int(i) for i in input().split()]\nimport bisect\nN = int(input())\nA = sorted(inpl())\nB = inpl()\nC = sorted(inpl())\nans = 0\nfor b in B:\n ans += bisect.bisect_left(A,b)*(N-bisect.bisect_right(C,b))\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s155837965', 's878403380', 's915442920']
[3060.0, 23220.0, 23616.0]
[239.0, 1624.0, 367.0]
[189, 697, 227]
p03559
u370331385
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nC = list(map(int,input().split()))\nA = list(set(A))\nB = list(set(B))\nC = list(set(C))\nn1,n2,n3 = len(A),len(B),len(C)\nAll = [] \nB_A = [] \nB_C = [] \n\nfor i in range(n1): All.append([A[i],0])\nfor i in range(n2): All.append([B[i],1])\nfor i in range(n3): All.append([C[i],2])\nAll.sort()\nprint(All)\n\ncount1,count2 = 0,0\nN = n1+n2+n3\nfor i in range(N):\n if(All[i][1] == 1): \n if(i == 0):\n B_A.append(count1)\n if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(n3-count2-1)\n else: B_C.append(n3-count2)\n elif(i == N-1):\n if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)\n else: B_A.append(count1)\n B_C.append(n3-count2)\n else:\n if((All[i][0] == All[i-1][0])and(All[i-1][1] == 0)): B_A.append(count1-1)\n else: B_A.append(count1)\n if((All[i][0] == All[i+1][0])and(All[i+1][1] == 2)): B_C.append(n3-count2-1)\n else: B_C.append(n3-count2)\n \n if(All[i][1] == 0): count1 += 1\n if(All[i][1] == 2): count2 += 1\n\nans = 0\nfor i in range(n2):\n ans += B_A[i]*B_C[i]\nprint(ans)', 'import bisect\nN = int(input())\nA = list(map(int,input().split()))\nB = list(map(int,input().split()))\nC = list(map(int,input().split()))\n\nA.sort()\nB.sort()\nC.sort()\nans = 0\n\nfor i in range(N):\n count_a = bisect.bisect_left(A,B[i])\n count_c = N -bisect.bisect_right(C,B[i])\n ans += count_a*count_c\nprint(ans)']
['Wrong Answer', 'Accepted']
['s970955758', 's615442470']
[64200.0, 23232.0]
[1513.0, 330.0]
[1269, 384]
p03559
u370721525
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nfrom collections import deque\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\nA.sort()\nB.sort()\nC.sort()\n\nd = deque([])\nfor i in range(N):\n n = bisect.bisect_right(C, B[N-1-i])\n if len(d) == 0:\n d.appendleft(N-n)\n else:\n d.appendleft(N-n+d[0])\n \nans = 0\nfor i in range(N):\n n = bisect.bisect_right(B, A[i])\n ans += d[n]\nprint(ans)', 'import bisect\nfrom collections import deque\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\nA.sort()\nB.sort()\nC.sort()\n\nd = deque([])\nfor i in range(N):\n n = bisect.bisect_right(C, B[N-1-i])\n if len(d) == 0:\n d.appendleft(N-n)\n else:\n d.appendleft(N-n+d[0])\n \nans = 0\nfor i in range(N):\n m = bisect.bisect_right(B, A[i])\n if m < N:\n ans += d[m]\nprint(ans)']
['Runtime Error', 'Accepted']
['s110393502', 's108429271']
[29548.0, 29640.0]
[563.0, 555.0]
[433, 447]
p03559
u397531548
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nC=list(map(int,input().split()))\nA.sort()\nB.sort()\nC.sort()\nans=0\nfor j in range(N):\n a=bisect.bisect_left(a, B[j])\n c=bisect.bisect_right(a, B[j])\n ans+=a*c\nprint(ans)', 'from bisect import bisect_left, bisect_right\nN=int(input())\nA=list(map(int,input().split()))\nB=list(map(int,input().split()))\nC=list(map(int,input().split()))\nA.sort()\nB.sort()\nC.sort()\nans=0\nfor j in range(N):\n a=bisect_left(A, B[j])\n c=bisect_right(C, B[j])\n ans+=a*(N-c)\nprint(ans)']
['Runtime Error', 'Accepted']
['s722998052', 's150720751']
[23328.0, 23360.0]
[196.0, 332.0]
[258, 293]
p03559
u426649993
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['from bisect import bisect_right\n\nif __name__ == "__main__":\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n c = list(map(int, input().split()))\n a = sorted(a)\n b = sorted(b)\n c = sorted(c)\n\n ans = 0\n\n \n clist = [0] * n\n clist[n-1] = n - bisect_right(c, b[n-1])\n for i in range(n-2, -1, -1):\n clist[i] = n - bisect_right(c, b[i]) + clist[i+1]\n\n for aa in a:\n b_pos = bisect_right(b, aa)\n ans += clist[b_pos]\n\n print(ans)\n', 'from bisect import bisect_right\n\nif __name__ == "__main__":\n n = int(input())\n a = list(map(int, input().split()))\n b = list(map(int, input().split()))\n c = list(map(int, input().split()))\n a = sorted(a)\n b = sorted(b)\n c = sorted(c)\n\n ans = 0\n\n \n clist = [0] * n\n clist[n-1] = n - bisect_right(c, b[n-1])\n for i in range(n-2, -1, -1):\n clist[i] = n - bisect_right(c, b[i]) + clist[i+1]\n\n for aa in a:\n b_pos = bisect_right(b, aa)\n if b_pos != n:\n ans += clist[b_pos]\n\n print(ans)\n']
['Runtime Error', 'Accepted']
['s132191556', 's907121241']
[23924.0, 24052.0]
[344.0, 356.0]
[610, 637]
p03559
u452885705
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\n\nN= int(input())\na = map(int, input().split(" "))\nb = map(int, input().split(" "))\nc = map(int, input().split(" "))\n\na = sorted(a)\nb = sorted(b)\nc = sorted(c,reverse=True)\n\nresult = 0\nfor i in b:\n ta = bisect.bisect_left(a,i)\n tc = bisect.bisect_right(c,i)\n result += ta*(N-tc)\nprint(result)', 'import bisect\n\nN= int(input())\na = map(int, input().split(" "))\nb = map(int, input().split(" "))\nc = map(int, input().split(" "))\n\na = sorted(a)\nb = sorted(b)\nc = sorted(c)\n\nresult = 0\nfor i in b:\n ta = bisect.bisect_left(a,i)\n tc = bisect.bisect_right(c,i)\n result += ta*(N-tc)\nprint(result)']
['Wrong Answer', 'Accepted']
['s268253670', 's713544217']
[35448.0, 35704.0]
[232.0, 238.0]
[314, 301]
p03559
u463775490
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn = int(input())\na = sorted(list(map(int,input().split())))\nb = sorted(list(map(int,input().split())))\nc = sorted(list(map(int,input().split())))\nans = 0\nfor i in range(n):\n l = (bisect.bisect_left(a,b[i]))*(n-bisect.bisect_right(c,b[i]))\n ans += 1\nprint(ans)', 'import bisect\n\nn = int(input())\na = sorted(list(map(int, input().split())))\nb = list(map(int, input().split()))\nc = sorted(list(map(int, input().split())))\nans = 0\n\nfor i in range(n):\n mid = b[i]\n hi = bisect.bisect_left(a, mid)\n lo = n - bisect.bisect_right(c, mid)\n ans += hi * lo\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s046903595', 's910981579']
[23244.0, 23744.0]
[321.0, 368.0]
[279, 306]
p03559
u520158330
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nA = sorted(list(map(int,input().split())))\nB = list(map(int,input().split()))\nC = sorted(list(map(int,input().split())))\n\nans = 0\n#print(A)\n#print(C)\nfor b in B:\n lenA = bisect.bisect_left(A,b) \n lenC = N - bisect.bisect_left(C,b) if b not in C else N - C.index(b) - 1\n ans += lenA*lenC\n #print(lenA,lenC)\n \nprint(ans)', 'import bisect\n\nN = int(input())\nA = sorted(list(map(int,input().split())))\nB = list(map(int,input().split()))\nC = sorted(list(map(int,input().split())))\n\nans = 0\n#print(A)\n#print(C)\nfor b in B:\n lenA = bisect.bisect_left(A,b)\n lenC = N - bisect.bisect(C,b)\n ans += lenA*lenC\n #print(lenA,lenC)\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s507287165', 's218324023']
[23744.0, 23744.0]
[161.0, 368.0]
[384, 321]
p03559
u537782349
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\na = int(input())\nb = list(map(int, input().split()))\nb.sort()\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\nd.sort()\nans = 0\nfor i in range(a):\n ans += bisect.bisect_left(b, c[i]) * (a - bisect.bisect_right(d, c[i]))\n ', 'import bisect\n\na = int(input())\nb = list(map(int, input().split()))\nb.sort()\nc = list(map(int, input().split()))\nd = list(map(int, input().split()))\nd.sort()\ne = 0\nfor i in c:\n e += bisect.bisect_left(b, i) * (a - bisect.bisect_right(d, i))\nprint(e)\n']
['Wrong Answer', 'Accepted']
['s191258745', 's053998845']
[23232.0, 23360.0]
[358.0, 348.0]
[262, 253]
p03559
u569272329
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['def function1(array, number, first, last):\n if first+1 == last:\n return last\n index = (first+last)//2\n if number <= array[index]:\n return function1(array, number, first, index)\n else:\n return function1(array, number, index, last)\n\n\ndef function2(array, number, first, last):\n if first+1 == last:\n return last\n index = (first+last)//2\n if array[index] <= number:\n return function2(array, number, index, last)\n else:\n return function2(array, number, first, index)\n\n\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\nA.sort()\nB.sort()\nC.sort()\nans = 0\nfor i in range(0, N):\n a = function1(A, B[i], 0, N)\n b = N-function2(C, B[i], 0, N)\n ans += (a*b)\nprint(ans)\n', 'from bisect import bisect_left, bisect_right\n\nN = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\nA.sort()\nC.sort()\nans = 0\nfor i in range(0, N):\n ans += (bisect_left(A, B[i])*(N-bisect_right(C, B[i])))\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s547246820', 's095529706']
[23328.0, 23360.0]
[1200.0, 349.0]
[808, 290]
p03559
u569322757
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['\nimport bisect\n\n\nI = lambda: list(map(int, input().split()))\nN = I()\nA = I()\nB = I()\nC = I()\nA.sort()\nB.sort()\nC.sort()\n\nsumm = 0\nfor ai in A:\n r = bisect.bisect_right(B, ai)\n for bi in B[r:]:\n rr = bisect.bisect_right(C, bi)\n summ += (N - r) * (N - rr)\n\nprint(summ)\n', 'import bisect\n\n\nI = lambda: map(int, input().split())\nN = int(input())\nA = list(I())\nB = list(I())\nC = list(I())\nB.sort()\nC.sort()\n\ns = [0] * (N + 1)\nfor i, bi in enumerate(B):\n s[i + 1] = s[i] + N - bisect.bisect_right(C, bi)\n\nprint(sum(s[N] - s[bisect.bisect_right(B, ai)] for ai in A))']
['Runtime Error', 'Accepted']
['s940854189', 's806480927']
[23328.0, 23360.0]
[261.0, 348.0]
[287, 291]
p03559
u614181788
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = list(map(int,input().split()))\na = sorted(a)\nb = sorted(b)\nc = sorted(c)\ncount = 0\nimport bisect\nfor i in range(n):\n A = bisect.bisect(a,b[i]-1)\n B = bisect.bisect(c,b[i]+1)\n count += A*(n-B)\nprint(count)', 'n = int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = list(map(int,input().split()))\na = sorted(a)\nb = sorted(b)\nc = sorted(c)\ncount = 0\nimport bisect\nfor i in range(n):\n A = bisect.bisect_right(a,b[i]-1)\n C = bisect.bisect_left(c,b[i]+1)\n count += A*(n-C)\nprint(count)']
['Wrong Answer', 'Accepted']
['s417721448', 's186898404']
[23164.0, 23328.0]
[349.0, 354.0]
[304, 315]
p03559
u623687794
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn=int(input())\na=sorted(list(map(int,input().split())))\nb=sorted(list(map(int,input().split())))\nc=sorted(list(map(int,input().split())))\nans=0\nfor i in range(n):\n d=bisect.bisect_left(a,b[i])\n e=bisect.bisect_right(c,b[i])\n ans+=d*e\nprint(ans)\n', 'import bisect\nn=int(input())\na=sorted(list(map(int,input().split())))\nb=sorted(list(map(int,input().split())))\nc=sorted(list(map(int,input().split())))\nans=0\nfor i in range(n):\n d=bisect.bisect_left(a,b[i])\n e=bisect.bisect_right(c,b[i])\n ans+=d*(n-e)\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s827493989', 's208282999']
[23092.0, 23200.0]
[329.0, 331.0]
[262, 266]
p03559
u703890795
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\ns = 0\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)\n\nia = 0\nic = 0\n\nfor b in B:\n while True:\n if ia == N-1 or A[ia+1]>=b: \n break\n ia += 1\n while True:\n if ic == N-1 or C[ic+1]>b:\n break\n ic += 1\n s += (ia+1)*(N-ic-1)\n \nprint(s)', 'N = int(input())\nA = list(map(int, input().split()))\nB = list(map(int, input().split()))\nC = list(map(int, input().split()))\ns = 0\n\nA = sorted(A)\nB = sorted(B)\nC = sorted(C)\n\nia = -1\nic = -1\n\nfor b in B:\n while True:\n if ia == N-1 or A[ia+1]>=b: \n break\n ia += 1\n while True:\n if ic == N-1 or C[ic+1]>b:\n break\n ic += 1\n s += (ia+1)*(N-ic-1)\n \nprint(s)']
['Wrong Answer', 'Accepted']
['s849336111', 's322834878']
[23328.0, 23328.0]
[381.0, 349.0]
[378, 380]
p03559
u707124227
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn=int(input())\na=sorted(list(map(int,input().split())))\nb=sorted(list(map(int,input().split())))\nc=sorted(list(map(int,input().split())))\nab={} \nl=bisect.bisect_right(b,a[0])\nab[0]=l\nfor i in range(1,n):\n if a[i]<b[ab[i-1]]:\n ab[i]=ab[i-1]\n else:\n j=ab[i-1]+1\n while n>j and a[i]>=b[j]:\n j+=1\n ab[i]=j\nbc={} \nl=bisect.bisect_right(c,b[0])\nbc[0]=l\nfor i in range(1,n):\n if b[i]<c[bc[i-1]]:\n bc[i]=bc[i-1]\n else:\n j=bc[i-1]+1\n while n>j and b[i]>=c[j]:\n j+=1\n bc[i]=j\nans=0\nfor i in range(n):\n for j in range(ab[i],n):\n ans+=n-bc[j]\n', "def main(n,a,b,c):\n import bisect\n ans=0\n for i in range(n):\n na=bisect.bisect_left(a,b[i])\n nc=n-bisect.bisect_right(c,b[i])\n ans+=na*nc\n print(ans)\nif __name__=='__main__':\n n=int(input())\n a=sorted(list(map(int,input().split())))\n b=sorted(list(map(int,input().split())))\n c=sorted(list(map(int,input().split())))\n main(n,a,b,c)\n"]
['Runtime Error', 'Accepted']
['s631845417', 's327361285']
[46340.0, 23200.0]
[2106.0, 324.0]
[719, 350]
p03559
u767664985
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['from bisect import bisect_left\n\nN = int(input())\nA = sorted(list(map(int, input().split())))\nB = sorted(list(map(int, input().split())))\nC = sorted(list(map(int, input().split())))\n\nans = 0\n\nfor ai in range(N):\n bi = bisect_left(B, A[ai])\n ci = bisect_left(C, B[bi])\n ans += (N-bi)*(N-ci)\n\nprint(ans)\n', 'from bisect import bisect_right, bisect_left\n\nN = int(input())\nA = sorted(list(map(int, input().split())))\nB = sorted(list(map(int, input().split())))\nC = sorted(list(map(int, input().split())))\n\nans = 0\n\nfor bi in range(N):\n ai_max = bisect_left(A, B[bi])\n ci_min = bisect_right(C, B[bi])\n ans += (ai_max) * (N - ci_min)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s518724293', 's769373329']
[23092.0, 23232.0]
[335.0, 345.0]
[310, 343]
p03559
u817328209
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['k = int(input())\nkn = [0]*30\ntmp = k\nfor i in range(30) :\n kn[i] = tmp%10\n tmp = tmp//10\np = [0,1,2,3,-4,-3,-2,-1,0]\nans = sum(kn)\nfor i in range(1, 10) :\n res = 0\n for j in range(30) :\n res += i*kn[j]%10\n res += i*kn[j]//10\n ans = min(ans, res)\n\nprint(ans)', 'import bisect\n\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\na.sort(); b.sort(); c.sort()\nins_c = [0]*n\nins_b = [0]*n\nparts_comb = [0]*n\nfor i in range(n) :\n ins_c = bisect.bisect_right(c, b[i])\n ins_b = bisect.bisect_right(b, a[i])\nans = 0\nfor i in range(n) :\n for j in range(ins_b[i], n) :\n ans += n - r_c\n\nprint(ans)', 'import bisect\n\nn = int(input())\na = list(map(int, input().split()))\nb = list(map(int, input().split()))\nc = list(map(int, input().split()))\na.sort(); c.sort()\nans = 0\nfor i in range(n) :\n l_a = bisect.bisect_left(a, b[i])\n r_c = bisect.bisect_right(c, b[i])\n ans += l_a * (n - r_c)\n\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s889428266', 's900838973', 's957910671']
[3064.0, 23360.0, 23360.0]
[20.0, 322.0, 374.0]
[286, 414, 302]
p03559
u859897687
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\ni,j=0,0\nm1=[]\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n m1.append(j)\nfor t in range(len(m1),len(b)):\n m1.append(j)\ni,j=0,0\nm2=[]\nfor k in range(n):\n if c[i]>k:\n j+=m1[b[k]]\n else:\n m2.append(j)\nfor t in range(len(m2),len(c)):\n m2.append(j)\nprint(sum(m2))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\nfor t in range(i,n):\n d1[b[t]]=j\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\nfor t in range(i,n):\n d2[c[t]]=j\nprint(sum(d2.values()))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\nfor t in range(i,len(b)):\n d1[b[t]]=j\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\nfor t in range(i,len(c)):\n d2[c[t]]=j\nprint(sum(d2.values()))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\n j=0\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\n j=0\nprint(sum(d2.values()))', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\nfor t in range(i,n):\n d1[b[t]]=j\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\nfor t in range(i,n):\n d2[c[t]]=j\nprint(sum(d2.values()))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na=list(set(a))\nb=list(set(b))\nc=list(set(c))\na.sort()\nb.sort()\nc.sort()\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\nfor t in range(i,n):\n d1[b[t]]=j\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\nfor t in range(i,n):\n d2[c[t]]=j\nprint(sum(d2.values()))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na=list(set(a))\nb=list(set(b))\nc=list(set(c))\na.sort()\nb.sort()\nc.sort()\ni,j=0,0\nd1=dict()\nfor k in a:\n if b[i]>k:\n j+=1\n else:\n d1[b[i]]=j\n i+=1\nfor t in range(i,len(b)):\n d1[b[t]]=j\ni,j=0,0\nd2=dict()\nfor k in b:\n if c[i]>k:\n j+=d1[k]\n else:\n d2[c[i]]=j\n i+=1\nfor t in range(i,len(c)):\n d2[c[t]]=j\nprint(sum(d2.values()))\n', 'n=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\ni,j,k=0,0,0\nm1=[]\nwhile k<n and i<n:\n if b[i]>a[k]:\n j+=1\n k+=1\n else:\n m1.append(j)\n i+=1\nfor t in range(len(m1),len(b)):\n m1.append(j)\ni,j,k=0,0,0\nm2=[]\nwhile k<n and i<n:\n if c[i]>b[k]:\n j+=m1[k]\n k+=1\n else:\n m2.append(j)\n i+=1\nfor t in range(len(m2),len(c)):\n m2.append(j)\nprint(sum(m2))']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s131652077', 's165474322', 's360605438', 's424808153', 's666723029', 's751208800', 's938720913', 's301878846']
[24052.0, 35004.0, 35004.0, 34732.0, 35004.0, 30744.0, 37036.0, 23476.0]
[228.0, 179.0, 292.0, 165.0, 309.0, 280.0, 361.0, 369.0]
[410, 378, 415, 325, 405, 450, 460, 463]
p03559
u864453204
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn = int(input())\na = sorted(list(map(int, input().split())))\nb = sorted(list(map(int, input().split())))\nc = sorted(list(map(int, input().split())))\ncnt = 0\nfor bb in b:\n anum = bisect.bisect_left(a, bb)\n cnum = bisect.bisect_right(c, bb)\n cnt += (anum * cnum)\nprint(cnt)', 'import bisect\nn = int(input())\na = sorted(list(map(int, input().split())))\nb = sorted(list(map(int, input().split())))\nc = sorted(list(map(int, input().split())))\ncnt = 0\nfor bb in b:\n anum = bisect.bisect_left(a, bb)\n cnum = n - bisect.bisect_right(c, bb)\n cnt += (anum * cnum)\nprint(cnt)']
['Wrong Answer', 'Accepted']
['s251232674', 's170496298']
[23156.0, 23200.0]
[323.0, 326.0]
[294, 298]
p03559
u871352270
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nA = sorted(list(map(int, input().split())))\nB = sorted(list(map(int, input().split())))\nC = sorted(list(map(int, input().split())))\nad = defaultdict(lambda: -1)\ni, j = 0, 0\nwhile i < N and j < N:\n if A[i] < B[j]:\n ad[i] = j\n i += 1\n else:\n j += 1\nbd = defaultdict(lambda: -1)\ni, j = 0, 0\nwhile i < N and j < N:\n if B[i] < C[j]:\n bd[i] = j\n i += 1\n else:\n j += 1\ncsum = [0] * N\nfor i in range(N):\n if bd[i] >= 0:\n csum[i] = N-bd[i]\nbsum = [0]* N\ncnt = 0\nfor i in range(N):\n cnt += csum[N-1-i]\n bsum[N-1-i] = cnt\nans = 0\nfor i in range(N):\n if ad[i] >= 0:\n ans += bsum[ad[i]]\nprint(ans)', 'import bisect\nN = int(input())\nA = sorted(list(map(int, input().split())))\nB = sorted(list(map(int, input().split())))\nC = sorted(list(map(int, input().split())))\nali = [0] * (N+1)\nbli = [N - bisect.bisect_left(C,B[i]+1) for i in range(N)]\nfor i in range(N):\n ali[i+1] = ali[i] + bli[i]\nprint(sum([ali[N]-ali[bisect.bisect_left(B,A[i]+1)] for i in range(N)]))']
['Runtime Error', 'Accepted']
['s264979369', 's259982082']
[23156.0, 28636.0]
[201.0, 365.0]
[681, 362]
p03559
u876442898
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import numpy as np\nN = int(input())\na = np.array( list(map(float, input().split(" "))) )\nb = np.array( list(map(float, input().split(" "))) )\nc = np.array( list(map(float, input().split(" "))) )\n\n# sort(a)\n# sort(b)\n# sort(c)\n\nmem_a = np.zeros(10**5) - 1\n\ndict_c = {}\ndef count_c(v):\n key = v\n if v in dict_c:\n return dict_c[v]\n else:\n val = len(np.where( (v < c) == True )[0])\n dict_c.update({key:val})\n return val\n\nnum = 0\nfor i in range(N):\n n = len(np.where( (a[i] < b) == True )[0])\n if mem_a[n] == -1:\n mem_a[n] = 0\n for j in range(N):\n mem_a[n] += count_c(b[j])\n num += mem_a[n]\nprint(num)', 'N = int(input())\na = list(map(float, input().split(" ")))\nb = list(map(float, input().split(" ")))\nc = list(map(float, input().split(" ")))\n\na.sort()\nc.sort()\n\n\ndef bisect_left(a, x, lo=0, hi=None):\n """Return the index where to insert item x in list a, assuming a is sorted.\n The return value i is such that all e in a[:i] have e < x, and all e in\n a[i:] have e >= x. So if x already appears in the list, a.insert(x) will\n insert just before the leftmost x already there.\n Optional args lo (default 0) and hi (default len(a)) bound the\n slice of a to be searched.\n """\n\n if lo < 0:\n raise ValueError(\'lo must be non-negative\')\n if hi is None:\n hi = len(a)\n while lo < hi:\n mid = (lo+hi)//2\n if a[mid] < x: lo = mid+1\n else: hi = mid\n return lo\n\ndef bisect_right(a, x, lo=0, hi=None):\n """Return the index where to insert item x in list a, assuming a is sorted.\n The return value i is such that all e in a[:i] have e <= x, and all e in\n a[i:] have e > x. So if x already appears in the list, a.insert(x) will\n insert just after the rightmost x already there.\n Optional args lo (default 0) and hi (default len(a)) bound the\n slice of a to be searched.\n """\n\n if lo < 0:\n raise ValueError(\'lo must be non-negative\')\n if hi is None:\n hi = len(a)\n while lo < hi:\n mid = (lo+hi)//2\n if x < a[mid]: hi = mid\n else: lo = mid+1\n return lo\n\nnum = 0\nfor i in range(N):\n num += (bisect_left(a, b[i])) * (len(c) - bisect_right(c, b[i]))\nprint(num)']
['Runtime Error', 'Accepted']
['s796853387', 's668939159']
[24124.0, 21024.0]
[2109.0, 930.0]
[667, 1576]
p03559
u905582793
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n x=a[i]\n y=bisect.bisect_right(b,x)\n if y<n:\n z=bisect.bisect_right(c,b[y])\n ans+=n-z\nprint(ans)', 'import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n x=a[i]\n y=bisect.bisect_right(x)\n if y<n:\n z=bisect.bisect_right(b[y])\n ans+=n-z\nprint(ans)', 'import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n x=b[i]\n y=bisect.bisect_left(a,x)\n z=bisect.bisect_right(c,x)\n ans+=(n-z)*y\nprint(ans)', 'import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n x=a[i]\n y=bisect.bisect_right(x)\n z=bisect.bisect_right(b[y])\n ans+=n-z\nprint(ans)', 'import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\nans=0\nfor i in range(n):\n x=b[i]\n y=bisect.bisect_left(a,x)\n z=bisect.bisect_right(c,x)\n ans+=(n-z)*y\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s383196402', 's805387085', 's939726817', 's994489471', 's934352598']
[22720.0, 23360.0, 3064.0, 23360.0, 22720.0]
[328.0, 192.0, 17.0, 195.0, 327.0]
[285, 281, 273, 267, 271]
p03559
u922487073
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\n\nN = int(input())\nAs = sorted(list(map(int, input().split())))\nBs = sorted(list(map(int, input().split())))\nCs = sorted(list(map(int, input().split())))\n\n\nB_Cs = [0] * N\nfor i, b in enumerate(Bs):\n index = bisect.bisect_left(Cs, b+1)\n B_Cs[i] = (N - index)\n\ncumsum_BC =[sum(B_Cs[i:]) for i in range(N)]\n\ncnt = 0\nfor i, a in enumerate(As):\n index = bisect.bisect_left(Bs, a+1)\n cnt += cumsum_BC[index]\nprint(cnt)', 'import bisect\n\nN = int(input())\nAs = sorted(list(map(int, input().split())))\nBs = sorted(list(map(int, input().split())))\nCs = sorted(list(map(int, input().split())))\n\n\n\nB_Cs = [0] * N\n\nprev = N - bisect.bisect_left(Cs, Bs[-1])\nB_Cs[-1] = prev\nfor i, b in enumerate(reversed(Bs)):\n if i == 0 :\n continue\n rev_i = N - i -1\n index = bisect.bisect_left(Cs, b+1)\n \n prev = (N - index) + prev\n B_Cs[rev_i] = prev\n\ncnt = 0\nfor i, a in enumerate(As):\n index = bisect.bisect_left(Bs, a+1)\n cnt += B_Cs[index]\nprint(cnt)', 'import bisect\n\nN = int(input())\nAs = sorted(list(map(int, input().split())))\nBs = sorted(list(map(int, input().split())))\nCs = sorted(list(map(int, input().split())))\n\ncnt = 0\nfor b in Bs:\n a_b = bisect.bisect_left(As,b)\n b_c = N - bisect.bisect_right(Cs, b)\n \n cnt += a_b * b_c\nprint(cnt)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s210732941', 's610798228', 's228205625']
[23092.0, 23156.0, 23244.0]
[2105.0, 421.0, 329.0]
[501, 645, 301]
p03559
u941884460
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['N = int(input())\nAs = list(map(int,input().split()))\nBs = list(map(int,input().split()))\nCs = list(map(int,input().split()))\nAs.sort()\nBs.sort()\nCs.sort()\n\ntotal,Aindex,Cindex=0,0,0\nCstart = 0\nfor x in range(N):\n if Bs[0] < Cs[x]:\n Cstart = x\n break\nfor i in range(N):\n if Bs[i] <= As[Aindex]:\n continue\n else:\n while Aindex < N-1:\n if As[Aindex+1] < Bs[i]:\n Aindex += 1\n else:\n break\n while Cstart + Cindex < N-1:\n if Cs[Cstart + Cindex] <= Bs[i]:\n Cindex += 1\n else:\n break\n total += (Aindex+1)*(N-Cindex-1)\nprint(total)', 'N = int(input())\nAs = list(map(int,input().split()))\nBs = list(map(int,input().split()))\nCs = list(map(int,input().split()))\nAs.sort()\nBs.sort()\nCs.sort()\n\ntotal,Aindex,Cindex=0,0,0\nCstart = 0\nfor x in range(N):\n if Bs[0] < Cs[x]:\n Cstart = x\n break\nfor i in range(N):\n if Bs[i] <= As[Aindex]:\n continue\n else:\n while Aindex < N-1:\n if As[Aindex+1] < Bs[i]:\n Aindex += 1\n else:\n break\n while Cstart + Cindex < N-1:\n if Cs[Cstart + Cindex] <= Bs[i]:\n Cindex += 1\n else:\n break\n total += (Aindex+1)*(N-Cindex-1)\n print(Aindex,Cindex)\nprint(total)', 'import bisect\nN=int(input())\na = list(map(int,input().split()))\nb = list(map(int,input().split()))\nc = list(map(int,input().split()))\na.sort()\nb.sort()\nc.sort()\ntotal = 0\nfor i in range(N):\n total += bisect.bisect_left(a,b[i]) * (N - bisect.bisect_right(c,b[i]))\nprint(total)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s577454816', 's608585920', 's149939418']
[23092.0, 23328.0, 23360.0]
[379.0, 519.0, 328.0]
[673, 698, 276]
p03559
u943057856
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['import bisect\nn=int(input())\na=list(map(int,input().split()))\nb=list(map(int,input().split()))\nc=list(map(int,input().split()))\nans=0\nfor i in b:\n x=bisect.bisect_left(a,i)\n y=bisect.bisect_right(c,i)\n ans+=x*(n-y)\n print(x,y)\nprint(ans)', 'import bisect\nn=int(input())\na=sorted(list(map(int,input().split())))\nb=sorted(list(map(int,input().split())))\nc=sorted(list(map(int,input().split())))\nans=0\nfor i in b:\n x=bisect.bisect_left(a,i)\n y=bisect.bisect_right(c,i)\n ans+=x*(n-y)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s183025476', 's204733093']
[29380.0, 29264.0]
[233.0, 239.0]
[249, 258]
p03559
u993435350
2,000
262,144
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
['#include <bits/stdc++.h>\nusing namespace std;\n\nint main(){\n int N;\n cin >> N;\n int con;\n con = 0;\n vector<vector<int>> parts(3, vector<int>(N));\n\n for(int i = 0;i < 3; i++){\n for(int j = 0;j < N; j++){\n cin >> parts[i][j];\n }\n }\n\n for (int i = 0;i < N; i ++){\n for (int j = 0;j < N; j++){\n if (parts[2][i] > parts[1][j]){\n for (int k = 0;k < N; k++){\n if (parts[1][j] > parts[0][k]){\n con += 1;\n\n } \n }\n }\n }\n }\n cout << con << endl;\n}', 'import bisect\n\nN = int(input())\nparts = [[] for i in range(3)]\ncon = [0] * N\n\nans = 0\n\nfor i in range(3):\n t = sorted(list(map(int,input().split())))\n parts[i] = t\n\nunder =parts[2]\nmiddle = parts[1]\nupper = parts[0]\n\nfor i in range(N):\n p = middle[i]\n ans += bisect.bisect_left(upper,p) * (N - bisect.bisect_right(under,p))\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s580809869', 's167398115']
[2940.0, 23840.0]
[17.0, 336.0]
[617, 343]
p03560
u102461423
2,000
262,144
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
['from collections import deque\n\n\n\nK = int(input())\nq = deque()\nq.append((1,1)) \nvisited = [False]*K\n\nans = 0\n\nwhile ans == 0:\n s,x = q.popleft()\n visited[x] = True\n if x == 0:\n ans = s\n break\n q.appendleft((s,(10*x)%K))\n q.append((s+1,(x+1)%K))\n\nprint(ans)', 'from collections import deque\n \n\n \nK = int(input())\nq = deque()\nq.append((1,1)) \nvisited = [False]*K\n \nans = 0\n \nwhile ans == 0:\n s,x = q.popleft()\n if visited[x]:\n continue\n visited[x] = True\n if x == 0:\n ans = s\n break\n q.appendleft((s,(10*x)%K))\n q.append((s+1,(x+1)%K))\n \nprint(ans)']
['Time Limit Exceeded', 'Accepted']
['s186399720', 's764108401']
[323296.0, 14444.0]
[2124.0, 123.0]
[378, 413]
p03560
u187205913
2,000
262,144
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.
['k = int(input())\ng = [[] for _ in range(k)]\nfrom collections import deque\ndic = {1:1}\nqueue = deque([[1,1]])\nwhile queue:\n v,cost = queue.popleft()\n if not v+1 in dic.keys() or cost+1<dic[v+1]:\n dic[v+1] = cost+1\n queue.append([v+1,cost+1])\n if not v*10%k in dic.keys() or cost<dic[v*10%k]:\n dic[v*10%k] = cost\n queue.append([v*10%k,cost])\n\nprint(dic[0])', 'k = int(input())\nfrom collections import deque\ndic = {1:1}\nqueue = deque()\nqueue.appendleft([1,1])\nwhile queue:\n v,cost = queue.popleft()\n v_ = (v+1)%k\n if not v_ in dic or cost+1<dic[v_]:\n dic[v_] = cost+1\n queue.appendleft([v_,cost+1])\n v_ = v*10%k\n if not v_ in dic or cost<dic[v_]:\n dic[v_] = cost\n queue.append([v_,cost])\n\nprint(dic[0])']
['Time Limit Exceeded', 'Accepted']
['s687380335', 's620516609']
[244464.0, 20736.0]
[2111.0, 1366.0]
[391, 384]
p03603
u104282757
2,000
262,144
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i. To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight. Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to allocate colors and weights so that the following condition is satisfied for all v. * The total weight of the vertices with the same color as v among the vertices contained in the subtree whose root is v, is X_v. Here, _the subtree whose root is_ v is the tree consisting of Vertex v and all of its descendants. Determine whether it is possible to allocate colors and weights in this way.
['# E\nN = int(input())\nP_list = list(map(int, input().split()))\nX_list = list(map(int, input().split()))\n\n# graph\nchild_list = [[] for _ in range(N+1)]\nfor i in range(2, N+1):\n child_list[P_list[i-2]].append(i)\n\n# from root\n# minimize local total weight\n\ncolor1 = [0]+X_list\ncolor2 = [0]*(N+1)\n\n\ndef solve_knapsack(L, M):\n min_acc = sum([min(color1[j], color2[j]) for j in L])\n if min_acc > M:\n return -1\n else:\n add_can = M - min_acc\n add_set = set([0])\n for j in L:\n add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])\n add_set_ = set(add_set)\n for s in add_set:\n if s + add_j <= add_can:\n add_set_.add(s + add_j)\n add_set = add_set_\n \n total = sum([color1[j]+color2[j] for j in L])\n return total - max(add_set)\n\nres = "POSSIBLE"\n\nfor i in range(N, 0, -1):\n if len(child_list[i]) == 0:\n pass\n elif len(child_list[i]) == 1:\n j = child_list[i][0]\n if min(color1[j], color2[j]) > X_list[i-1]:\n res = "IMPOSSIBLE"\n break\n elif max(color1[j], color2[j]) > X_list[i-1]:\n color2[i] = max(color1[j], color2[j])\n else:\n color2[i] = min(color1[j], color2[j])\n else:\n c2 = solve_knapsack(child_list[i], X_list[i-1])\n if c2 < 0:\n res = "IMPOSSIBLE"\n break\n else:\n color2[j] = c2\n \nprint(res)', '# E\nN = int(input())\nP_list = list(map(int, input().split()))\nX_list = list(map(int, input().split()))\n\n# graph\nchild_list = [[] for _ in range(N+1)]\nfor i in range(2, N+1):\n child_list[P_list[i-2]].append(i)\n\n# from root\n# minimize local total weight\n\ncolor1 = [0]+X_list\ncolor2 = [0]*(N+1)\n\n\ndef solve_knapsack(L, M):\n min_acc = sum([min(color1[j], color2[j]) for j in L])\n if min_acc > M:\n return -1\n else:\n add_can = M - min_acc\n add_set = set([0])\n for j in L:\n add_j = max(color1[j], color2[j]) - min(color1[j], color2[j])\n add_set_ = set(add_set)\n for s in add_set:\n if s + add_j <= add_can:\n add_set_.add(s + add_j)\n add_set = add_set_\n \n total = sum([color1[j]+color2[j] for j in L])\n return total - max(add_set) - min_acc\n\nres = "POSSIBLE"\n\nfor i in range(N, 0, -1):\n if len(child_list[i]) == 0:\n pass\n elif len(child_list[i]) == 1:\n j = child_list[i][0]\n if min(color1[j], color2[j]) > X_list[i-1]:\n res = "IMPOSSIBLE"\n break\n elif max(color1[j], color2[j]) > X_list[i-1]:\n color2[i] = max(color1[j], color2[j])\n else:\n color2[i] = min(color1[j], color2[j])\n else:\n c2 = solve_knapsack(child_list[i], X_list[i-1])\n if c2 < 0:\n res = "IMPOSSIBLE"\n break\n else:\n color2[i] = c2\n \nprint(res)']
['Runtime Error', 'Accepted']
['s015679163', 's437971123']
[3188.0, 3440.0]
[21.0, 38.0]
[1489, 1499]
p03604
u102461423
2,000
262,144
There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i). Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the type-A robots at coordinates (1, 0), (2, 0), ..., (N, 0), and the type-B robots at coordinates (0, 1), (0, 2), ..., (0, N), one at each position. When activated, each type of robot will operate as follows. * When a type-A robot is activated at coordinates (a, 0), it will move to the position of the ball with the lowest y-coordinate among the balls on the line x = a, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. * When a type-B robot is activated at coordinates (0, b), it will move to the position of the ball with the lowest x-coordinate among the balls on the line y = b, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything. Once deactivated, a robot cannot be activated again. Also, while a robot is operating, no new robot can be activated until the operating robot is deactivated. When Snuke was about to activate a robot, he noticed that he may fail to collect all the balls, depending on the order of activating the robots. Among the (2N)! possible orders of activating the robots, find the number of the ones such that all the balls can be collected, modulo 1 000 000 007.
['import sys\ninput = sys.stdin.readline\n\nfrom scipy.sparse import csr_matrix\nfrom scipy.sparse.csgraph import connected_components\n\nMOD = 10**9 + 7\n\nN = int(input())\nball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())\n\n\n\n\ngraph = [set() for _ in range(N+N+1)]\nfor x,y in ball:\n graph[x].add(y+N)\n graph[y+N].add(x)\n\nvisited = [False] * (N+N+1)\ncomponents = []\nfor x in range(1,N+N+1):\n if visited[x]:\n continue\n V = set([x])\n E = []\n q = [x]\n visited[x] = True\n while q:\n y = q.pop()\n for z in graph[y]:\n if y < z:\n E.append((y,z))\n if visited[z]:\n continue\n V.add(z)\n visited[z] = True\n q.append(z)\n components.append((V,E))\n', 'import sys\ninput = sys.stdin.readline\n\nMOD = 10**9 + 7\n\nN = int(input())\nball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines())\n\n\n\n\ngraph = [set() for _ in range(N+N+1)]\nfor x,y in ball:\n graph[x].add(y+N)\n graph[y+N].add(x)\n\nvisited = [False] * (N+N+1)\ncomponents = []\nfor x in range(1,N+N+1):\n if visited[x]:\n continue\n V = set([x])\n E = []\n q = [x]\n visited[x] = True\n while q:\n y = q.pop()\n for z in graph[y]:\n if y < z:\n E.append((y,z))\n if visited[z]:\n continue\n V.add(z)\n visited[z] = True\n q.append(z)\n components.append((V,E))\n\ndef make_get_pattern(V):\n deg1 = [x for x in V if len(graph[x]) == 1]\n get = {}\n while deg1:\n x = deg1.pop()\n if not graph[x]:\n continue\n y = graph[x].pop()\n se = graph[y]; se.remove(x)\n if len(se) == 1: deg1.append(y)\n if x < y:\n get[(x,y)] = 0\n else:\n get[(y,x)] = 1\n for x in V:\n if graph[x]:\n y = graph[x].pop()\n break\n \n graph[y].remove(x)\n if x > y: x,y = y,x\n get[(x,y)] = 2\n while graph[x]:\n y = graph[x].pop()\n graph[y].remove(x)\n if x < y:\n get[(x,y)] = 3\n else:\n get[(y,x)] = 2\n x = y\n return get\n\ndef F(V,E):\n # V is connected\n if len(E) != len(V):\n return 0\n ret = 0\n E.sort()\n get = make_get_pattern(V)\n den1,den2 = 1,1\n dp1 = {x:0 for x in V}\n dp2 = {x:0 for x in V}\n for x,y in E:\n if get[(x,y)] == 0:\n k1 = dp1[x] + 1; k2 = dp2[x] + 1\n elif get[(x,y)] == 1:\n k1 = dp1[y] + 1; k2 = dp2[y] + 1\n elif get[(x,y)] == 2:\n k1 = dp1[x] + 1; k2 = dp2[y] + 1\n else:\n k1 = dp1[y] + 1; k2 = dp2[x] + 1\n dp1[x] += k1; dp1[y] += k1\n dp2[x] += k2; dp2[y] += k2\n den1 *= k1; den2 *= k2\n den1 %= MOD; den2 %= MOD\n return sum(pow(x,MOD-2,MOD) for x in (den1,den2))\n\nprob = 1\nfor c in components:\n prob *= F(*c)\n prob %= MOD\n\nanswer = prob\nfor n in range(1,N+N+1):\n answer *= n\n answer %= MOD\nprint(answer)']
['Wrong Answer', 'Accepted']
['s443299813', 's584606318']
[107224.0, 147992.0]
[1316.0, 1929.0]
[830, 2314]
p03613
u408375121
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['n = int(input())\na = list(map(int, input().split()))\nd = [0] * (10**5 + 2)\nneg_count = 0\nfor i in range(len(a)):\n d[a[i] - 1] += 1\n d[a[i]] += 1\n d[a[i] + 1] += 1\nans = max(d)', 'n = int(input())\na = list(map(int, input().split()))\nd = [0] * (10**5 + 2)\nneg_count = 0\nfor i in range(len(a)):\n d[a[i] - 1] += 1\n d[a[i]] += 1\n d[a[i] + 1] += 1\nans = max(d)\nprint(ans)']
['Wrong Answer', 'Accepted']
['s174600321', 's870084064']
[20704.0, 20696.0]
[92.0, 86.0]
[178, 189]
p03613
u543954314
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['n = int(input())\na = list(map(int, input().split()))\ncnt = 0\nfor i in range(n-1):\n if a[i] == i+1:\n a[i],a[i+1] = a[i+1],a[i]\n cnt += 1\nif a[-1] == n:\n cnt += 1\nprint(cnt)\n', 'from collections import Counter\nn = int(input())\nd = Counter(map(int, input().split()))\ncnt = 0\nfor i in d:\n new = d.get(i,0) + d.get(i-1,0) + d.get(i+1,0)\n if new > cnt:\n cnt = new\nprint(cnt)']
['Wrong Answer', 'Accepted']
['s248394262', 's915168741']
[13964.0, 16588.0]
[53.0, 98.0]
[180, 197]
p03613
u667024514
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['a = input()\nprint(a[0]+str(len(a)-2)+a[-1])', 'n = int(input())\nlis = [0 for i in range(10 ** 5 + 2)]\nli = list(map(int,input().split()))\nfor i in range(n):\n lis[li[i]-1] += 1\n lis[li[i]] += 1\n lis[li[i]+1] += 1\nprint(max(lis))']
['Wrong Answer', 'Accepted']
['s827695918', 's045218432']
[2940.0, 14792.0]
[19.0, 94.0]
[43, 183]
p03613
u682985065
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['n = int(input())\np = list(map(int, input().split()))\ncnt = 0\n\nfor idx, pi in enumerate(p):\n if (idx+1) == pi:\n if idx+1 < n:\n p[idx], p[idx+1] = p[idx+1], p[idx]\n else:\n p[idx], p[idx-1] = p[idx-1], p[idx]\n cnt += 1\n\nprint(cnt)', 'n = int(input())\na = list(map(int, input().split()))\ncnt = [0]*((10**5)+2) #-1 ~ 10**5+1\n\nfor ai in a:\n cnt[ai + 1] += 1\n cnt[ai-1 + 1] += 1\n cnt[ai+1 + 1] += 1\n\nprint(max(cnt))']
['Wrong Answer', 'Accepted']
['s715802959', 's860352386']
[13964.0, 13964.0]
[52.0, 86.0]
[273, 186]
p03613
u707870100
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['# -*- coding: utf-8 -*-\n#ARC082C\nimport copy\nimport sys\nimport math\n\nn = int(input())\ntmp = input().split()\nhoge = list(map(lambda a: int(a), tmp))\n\nhoge.sort()\nhoge.append(-1)\na=0\nb=0\nc=1\nmaxhoge=0\nfor i in range(0,n):\n\tif(hoge[i]!=hoge[i+1]):\n\t\tif(i!=n-1):\n\t\t\tif(hoge[i+1]-hoge[i]==1):\n\t\t\t\ta=b\n\t\t\t\tb=c\n\t\t\t\tc=1\n\t\t\telif(hoge[i+1]-hoge[i]==2):\n\t\t\t\ta=c\n\t\t\t\tb=0\n\t\t\t\tc=1\n\t\t\telse:\n\t\t\t\ta,b=0\n\t\t\t\tc=1\n\telse:\n\t\tc+=1\n#\tprint("i:{} | {} {} {}".format(i,a,b,c))\n\n\tmaxhoge=max(maxhoge,a+b+c)\n\n\n\n#print(hoge)\nprint(maxhoge)\n\n', '# -*- coding: utf-8 -*-\n#ARC082C\nimport copy\nimport sys\nimport math\n\nn = int(input())\ntmp = input().split()\nhoge = list(map(lambda a: int(a), tmp))\n\nhoge.sort()\nhoge.append(-1)\na=0\nb=0\nc=1\nmaxhoge=0\nfor i in range(0,n):\n\tif(hoge[i]!=hoge[i+1]):\n\t\tif(i!=n-1):\n\t\t\tif(hoge[i+1]-hoge[i]==1):\n\t\t\t\ta=b\n\t\t\t\tb=c\n\t\t\t\tc=1\n\t\t\telif(hoge[i+1]-hoge[i]==2):\n\t\t\t\ta=c\n\t\t\t\tb=0\n\t\t\t\tc=1\n\t\t\telse:\n\t\t\t\ta=0\n\t\t\t\tb=0\n\t\t\t\tc=1\n\telse:\n\t\tc+=1\n#\tprint("i:{} | {} {} {}".format(i,a,b,c))\n\n\tmaxhoge=max(maxhoge,a+b+c)\n\n\n\n#print(hoge)\nprint(maxhoge)\n\n']
['Runtime Error', 'Accepted']
['s071269757', 's759835051']
[14604.0, 14476.0]
[137.0, 173.0]
[512, 518]
p03613
u846372029
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['#Together\n\nN = int(input())\na = list(map(int, input().split()))\n\nb = []\n\nfor ai in a:\n b.append(ai-1)\n b.append(ai)\n b.append(ai+1)\n#print(b)\n\nimport collections\ncnt = collections.Counter(b)\n#print(cnt)\nmax(cnt.values())', '#Together\n\nN = int(input())\na = list(map(int, input().split()))\n\nb = []\n\nfor ai in a:\n b.append(ai-1)\n b.append(ai)\n b.append(ai+1)\n#print(b)\n\nimport collections\ncnt = collections.Counter(b)\n#print(cnt)\nprint(max(cnt.values()))']
['Wrong Answer', 'Accepted']
['s752503336', 's511438838']
[25848.0, 27232.0]
[126.0, 120.0]
[229, 236]
p03613
u855200003
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['rt numpy as np\nN = int(input())\na = [int(i) for i in input().split(" ")]\na = np.array(a,dtype=\'int\')\ndef count(a):\n return [1 if i==1 or i== 0 or i == -1 else 0 for i in a]\nif N == 1:\n print(1)\nelse:\n min_ = min(a)-1\n max_ = max(a)+1\n ans = -1\n for K in range(min_,max_):\n b = a - K\n tmp = sum(count(b))\n if ans < tmp:\n ans = tmp\n print(ans)', 'from collections import defaultdict\nN = int(input())\na = [int(i) for i in input().split(" ")]\ndic_num=defaultdict(int)\n\nfor i in a:\n dic_num[i] += 1\nans = -1\nfor X in range(min(a),max(a)+1):\n tmp = (dic_num[X-1] + dic_num[X] + dic_num[X+1])\n if ans < tmp:\n ans = tmp\nprint(ans)']
['Runtime Error', 'Accepted']
['s050676713', 's515383289']
[2940.0, 19424.0]
[17.0, 131.0]
[394, 293]
p03613
u925364229
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['\n\nimport numpy as np\n\nN = int(input())\na = list(map(int,input().split(" ")))\n\na.sort()\na2 = np.array(a)\n\nminval = a[0]\nmaxval = a[-1]\nl = (maxval - minval +1)\n\nnum = [0]*l\nnum_ans = []\n\n\nnum[0] = len(np.where(a2==a[0]))\n\nfor i in a:\n\tif num[i-minval] == 0:\n\t\tnum[i-minval] = len(np.where(a2==i))\n\nif l == 1:\n\tprint(num[0])\n\texit(0)\n\nnum_ans.append(num[0]+num[1]) \n\nif l == 2:\n\tprint(num_ans[0])\n\texit(0)\n\nfor i in range(1,l-1):\n\tnum_ans.append(num[i-1]+num[i]+num[i+1])\nnum_ans.append(num[-2]+num[-1])\n\nprint(max(num_ans))', '\n \nN = int(input())\na = list(map(int,input().split(" ")))\n \n\n \nminval = min(a)\nmaxval = max(a)\nl = (maxval - minval +1)\n \nnum = [0]*(l+2)\n\nfor i in a:\n\tnum[i-minval] += 1\n\nans = 0\nfor i in range(1,l+1):\n\tans = max(ans,num[i-1]+num[i]+num[i+1])\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s399313979', 's435215526']
[23372.0, 13964.0]
[2109.0, 107.0]
[539, 272]
p03613
u977193988
2,000
262,144
You are given an integer sequence of length N, a_1,a_2,...,a_N. For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing. After these operations, you select an integer X and count the number of i such that a_i=X. Maximize this count by making optimal choices.
['n=int(input())\nA=sorted(list(map(int,input().split())))\nL={}\nif n==1:\n print(1)\nelif n==2:\n if abs(A[0]-A[1])==1:\n print(2)\n else:\n print(1)\nelse:\n for i in A:\n if i not in L:\n L[i]=1\n else:\n L[i]+=1\n print(L)\n ans=[]\n for j in range(A[0],A[-1]+1):\n if (j in L) and (j-1 in L) and (j+1 in L):\n ans.append(L[j]+L[j+1]+L[j-1])\n elif (j in L) and (j-1 in L):\n ans.append(L[j-1]+L[j])\n elif (j in L) and (j+1 in L):\n ans.append(L[j+1]+L[j])\n elif (j-1 in L) and (j+1 in L):\n ans.append(L[j+1]+L[j-1])\n elif (j in L):\n ans.append(L[j])\nprint(max(ans))', 'n=int(input())\nA=sorted(list(map(int,input().split())))\nL={}\nif n==1:\n print(1)\nelif n==2:\n if abs(A[0]-A[1])==1:\n print(2)\n else:\n print(1)\nelse:\n for i in A:\n if i not in L:\n L[i]=1\n else:\n L[i]+=1\n ans=[]\n for j in range(A[0],A[-1]+1):\n if (j in L) and (j-1 in L) and (j+1 in L):\n ans.append(L[j]+L[j+1]+L[j-1])\n elif (j in L) and (j-1 in L):\n ans.append(L[j-1]+L[j])\n elif (j in L) and (j+1 in L):\n ans.append(L[j+1]+L[j])\n elif (j-1 in L) and (j+1 in L):\n ans.append(L[j+1]+L[j-1])\n elif (j in L):\n ans.append(L[j])\n print(max(ans))']
['Runtime Error', 'Accepted']
['s612343341', 's603099707']
[14092.0, 14164.0]
[173.0, 171.0]
[711, 702]
p03614
u026788530
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
["N = int(input())\n\np = input().split(' ')\nans = 1\nfor i in range(N):\n if int(p[i])==i):\n ans += 1\n\nprint(ans//2)\n", "N = int(input())\n\np = input().split(' ')\nans = 0\nfor i in range(N):\n if int(p[i]) == i+1:\n if not(i==N-1) and not(p[i+1] ==i+1):\n rrr = p[i]\n p[i] = p[i+1]\n p[i+1] = rrr\n ans +=1\n else:\n rrr = p[i]\n p[i]=p[i-1]\n p[i-1] =rrr\n ans +=1\n\nprint(ans)\n#print(p)\n"]
['Runtime Error', 'Accepted']
['s450445184', 's980015401']
[2940.0, 10420.0]
[17.0, 87.0]
[122, 360]
p03614
u102126195
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
['def main():\n\n S = list(input())\n checklist = [0 for i in range(26)]\n for i in S:\n checklist[ord(i) - ord("a")] += 1\n ans = True\n\n for i in checklist:\n if i > 1:\n ans = False\n\n if not ans:\n print(-1)\n return 0\n else:\n ans = False\n for i in range(len(checklist)):\n if checklist[i] == 0:\n for i in S:\n print(i, end="")\n print(chr(i + ord("a")), end = "")\n print()\n ans = True\n break\n\n if not ans:\n new_S = []\n for i in S:\n new_S.append(ord(i))\n\n for i in range(len(new_S) - 1):\n if new_S[i] > new_S[i + 1]:\n for j in range(i - 1):\n print(S[j], end = "")\n print(chr(new_S[i - 1] + 1), end = "")\n print()\n ans = True\n break\n\n if not ans:\n print(-1)\n#main()\n\ndef ABC069D():\n\n H, W = map(int, input().split())\n N = int(input())\n a = list(map(int, input().split()))\n ans = []\n for i in range(N):\n for j in range(a[i]):\n ans.append(i + 1)\n printlist = [[0 for i in range(W)] for j in range(H)]\n k = 0\n for i in range(H):\n for j in range(W):\n printlist[i][j] = ans[k]\n k += 1\n if i % 2 != 0:\n printlist[i] = printlist[i][::-1]\n\n for i in range(H):\n for j in range(W):\n print(printlist[i][j], end = "")\n if j != W:\n print(" ", end = "")\n print()\n print()\n#ABC069D()\n\nimport math\ndef cc(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\ndef ABC057D():\n\n N, A, B = map(int, input().split())\n v = list(map(int, input().split()))\n v = sorted(v)[::-1]\n\n anslist = []\n for i in range(A, B + 1):\n\n anslist.append([sum(v[0:i]) / i, i, v[i - 1]])\n anslist.sort()\n anslist = anslist[::-1]\n ans = anslist[0][0]\n key = anslist[0][2]\n long = anslist[0][1]\n print(ans)\n for i in range(1, len(anslist)):\n if anslist[i][0] == anslist[i - 1][0]:\n ans = anslist[i][0]\n key = anslist[i][2]\n long = anslist[i][1]\n else:\n break\n #print(anslist)\n #print(ans, key, long)\n cnt = 0\n for i in v:\n if i == key:\n cnt += 1\n\n c = 0\n for i in v[:long]:\n #print(i)\n if i == key:\n c += 1\n #print(c, long)\n ans = 0\n if c == long:\n for i in range(A, min(B + 1, cnt + 1)):\n ans += cc(cnt, i)\n else:\n ans = cc(cnt, c)\n #print(anslist)\n #print(cnt, c, long)\n print(ans)\n#ABC057D()\n\ndef ABC104D():\n S = list(input())\n A_cnt = 0\n B_cnt = 0\n C_cnt = 0\n Q_cnt = 0\n ans = 0\n for i in S:\n if i == "A":\n A_cnt += 1\n elif i == "B":\n B_cnt += 1\n elif i == "C":\n C_cnt += 1\n else:\n Q_cnt += 1\n for i in range(Q_cnt + 1):\n for j in range(Q_cnt - i + 1):\n k = Q_cnt - i - j\n if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:\n f_i = math.factorial(i)\n f_j = math.factorial(j)\n f_k = math.factorial(k)\n if f_i == 0:\n f_i = 1\n if f_j == 0:\n f_j = 1\n if f_k == 0:\n f_k = 1\n ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k\n print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)\n print(math.factorial(Q_cnt), f_i, f_j, f_k)\n print(ans)\n#ABC104D()\n\ndef ARC073D():\n N, W = map(int, input().split())\n wv = [list(map(int, input().split())) for i in range(N)]\n\ndef ARC075():\n N, A, B = map(int, input().split())\n h = [int(input()) for i in range(N)]\n def enogth(T):\n import copy\n this_h = copy.copy(h)\n cnt = 0\n for i in range(N):\n this_h[i] -= B\n key = 0\n if this_h[i] > 0:\n key = this_h[i] / (A - B)\n if int(key) != key:\n key += 1\n cnt += int(key)\n if cnt <= T:\n return True\n else:\n return False\n def sarch(i: object) -> object:\n print(i)\n if enogth(i):\n if i // 2 == 1:\n return i\n sarch(0 + i // 2)\n else:\n sarch(i + i // 2)\n print(sarch(10 ** 9))\n#ARC075()\n\ndef ARC082D():\n N = int(input())\n p = list(map(int, input().split()))\n cnt = 0\n\n for i in range(1, N - 1):\n if p[i] == i:\n p[i], p[i + 1] = p[i + 1], p[i]\n cnt += 1\n if p[N - 1] == N:\n p[-2], p[-1] == p[-1], p[-2]\n cnt += 1\n print(cnt)\nARC082D()', 'def main():\n\n S = list(input())\n checklist = [0 for i in range(26)]\n for i in S:\n checklist[ord(i) - ord("a")] += 1\n ans = True\n\n for i in checklist:\n if i > 1:\n ans = False\n\n if not ans:\n print(-1)\n return 0\n else:\n ans = False\n for i in range(len(checklist)):\n if checklist[i] == 0:\n for i in S:\n print(i, end="")\n print(chr(i + ord("a")), end = "")\n print()\n ans = True\n break\n\n if not ans:\n new_S = []\n for i in S:\n new_S.append(ord(i))\n\n for i in range(len(new_S) - 1):\n if new_S[i] > new_S[i + 1]:\n for j in range(i - 1):\n print(S[j], end = "")\n print(chr(new_S[i - 1] + 1), end = "")\n print()\n ans = True\n break\n\n if not ans:\n print(-1)\n#main()\n\ndef ABC069D():\n\n H, W = map(int, input().split())\n N = int(input())\n a = list(map(int, input().split()))\n ans = []\n for i in range(N):\n for j in range(a[i]):\n ans.append(i + 1)\n printlist = [[0 for i in range(W)] for j in range(H)]\n k = 0\n for i in range(H):\n for j in range(W):\n printlist[i][j] = ans[k]\n k += 1\n if i % 2 != 0:\n printlist[i] = printlist[i][::-1]\n\n for i in range(H):\n for j in range(W):\n print(printlist[i][j], end = "")\n if j != W:\n print(" ", end = "")\n print()\n print()\n#ABC069D()\n\nimport math\ndef cc(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\ndef ABC057D():\n\n N, A, B = map(int, input().split())\n v = list(map(int, input().split()))\n v = sorted(v)[::-1]\n\n anslist = []\n for i in range(A, B + 1):\n\n anslist.append([sum(v[0:i]) / i, i, v[i - 1]])\n anslist.sort()\n anslist = anslist[::-1]\n ans = anslist[0][0]\n key = anslist[0][2]\n long = anslist[0][1]\n print(ans)\n for i in range(1, len(anslist)):\n if anslist[i][0] == anslist[i - 1][0]:\n ans = anslist[i][0]\n key = anslist[i][2]\n long = anslist[i][1]\n else:\n break\n #print(anslist)\n #print(ans, key, long)\n cnt = 0\n for i in v:\n if i == key:\n cnt += 1\n\n c = 0\n for i in v[:long]:\n #print(i)\n if i == key:\n c += 1\n #print(c, long)\n ans = 0\n if c == long:\n for i in range(A, min(B + 1, cnt + 1)):\n ans += cc(cnt, i)\n else:\n ans = cc(cnt, c)\n #print(anslist)\n #print(cnt, c, long)\n print(ans)\n#ABC057D()\n\ndef ABC104D():\n S = list(input())\n A_cnt = 0\n B_cnt = 0\n C_cnt = 0\n Q_cnt = 0\n ans = 0\n for i in S:\n if i == "A":\n A_cnt += 1\n elif i == "B":\n B_cnt += 1\n elif i == "C":\n C_cnt += 1\n else:\n Q_cnt += 1\n for i in range(Q_cnt + 1):\n for j in range(Q_cnt - i + 1):\n k = Q_cnt - i - j\n if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:\n f_i = math.factorial(i)\n f_j = math.factorial(j)\n f_k = math.factorial(k)\n if f_i == 0:\n f_i = 1\n if f_j == 0:\n f_j = 1\n if f_k == 0:\n f_k = 1\n ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k\n print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)\n print(math.factorial(Q_cnt), f_i, f_j, f_k)\n print(ans)\n#ABC104D()\n\ndef ARC073D():\n N, W = map(int, input().split())\n wv = [list(map(int, input().split())) for i in range(N)]\n\ndef ARC075():\n N, A, B = map(int, input().split())\n h = [int(input()) for i in range(N)]\n def enogth(T):\n import copy\n this_h = copy.copy(h)\n cnt = 0\n for i in range(N):\n this_h[i] -= B\n key = 0\n if this_h[i] > 0:\n key = this_h[i] / (A - B)\n if int(key) != key:\n key += 1\n cnt += int(key)\n if cnt <= T:\n return True\n else:\n return False\n def sarch(i: object) -> object:\n print(i)\n if enogth(i):\n if i // 2 == 1:\n return i\n sarch(0 + i // 2)\n else:\n sarch(i + i // 2)\n print(sarch(10 ** 9))\n#ARC075()\n\ndef ARC082D():\n N = int(input())\n p = list(map(int, input().split()))\n cnt = 0\n\n for i in range(1, N - 1):\n if p[i] == i:\n p[i], p[i + 1] = p[i + 1], p[i]\n cnt += 1\n if p[N - 1] == N:\n p[-2], p[-1] = p[-1], p[-2]\n cnt += 1\n print(cnt)\nARC082D()', 'def main():\n\n S = list(input())\n checklist = [0 for i in range(26)]\n for i in S:\n checklist[ord(i) - ord("a")] += 1\n ans = True\n\n for i in checklist:\n if i > 1:\n ans = False\n\n if not ans:\n print(-1)\n return 0\n else:\n ans = False\n for i in range(len(checklist)):\n if checklist[i] == 0:\n for i in S:\n print(i, end="")\n print(chr(i + ord("a")), end = "")\n print()\n ans = True\n break\n\n if not ans:\n new_S = []\n for i in S:\n new_S.append(ord(i))\n\n for i in range(len(new_S) - 1):\n if new_S[i] > new_S[i + 1]:\n for j in range(i - 1):\n print(S[j], end = "")\n print(chr(new_S[i - 1] + 1), end = "")\n print()\n ans = True\n break\n\n if not ans:\n print(-1)\n#main()\n\ndef ABC069D():\n\n H, W = map(int, input().split())\n N = int(input())\n a = list(map(int, input().split()))\n ans = []\n for i in range(N):\n for j in range(a[i]):\n ans.append(i + 1)\n printlist = [[0 for i in range(W)] for j in range(H)]\n k = 0\n for i in range(H):\n for j in range(W):\n printlist[i][j] = ans[k]\n k += 1\n if i % 2 != 0:\n printlist[i] = printlist[i][::-1]\n\n for i in range(H):\n for j in range(W):\n print(printlist[i][j], end = "")\n if j != W:\n print(" ", end = "")\n print()\n print()\n#ABC069D()\n\nimport math\ndef cc(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\ndef ABC057D():\n\n N, A, B = map(int, input().split())\n v = list(map(int, input().split()))\n v = sorted(v)[::-1]\n\n anslist = []\n for i in range(A, B + 1):\n\n anslist.append([sum(v[0:i]) / i, i, v[i - 1]])\n anslist.sort()\n anslist = anslist[::-1]\n ans = anslist[0][0]\n key = anslist[0][2]\n long = anslist[0][1]\n print(ans)\n for i in range(1, len(anslist)):\n if anslist[i][0] == anslist[i - 1][0]:\n ans = anslist[i][0]\n key = anslist[i][2]\n long = anslist[i][1]\n else:\n break\n #print(anslist)\n #print(ans, key, long)\n cnt = 0\n for i in v:\n if i == key:\n cnt += 1\n\n c = 0\n for i in v[:long]:\n #print(i)\n if i == key:\n c += 1\n #print(c, long)\n ans = 0\n if c == long:\n for i in range(A, min(B + 1, cnt + 1)):\n ans += cc(cnt, i)\n else:\n ans = cc(cnt, c)\n #print(anslist)\n #print(cnt, c, long)\n print(ans)\n#ABC057D()\n\ndef ABC104D():\n S = list(input())\n A_cnt = 0\n B_cnt = 0\n C_cnt = 0\n Q_cnt = 0\n ans = 0\n for i in S:\n if i == "A":\n A_cnt += 1\n elif i == "B":\n B_cnt += 1\n elif i == "C":\n C_cnt += 1\n else:\n Q_cnt += 1\n for i in range(Q_cnt + 1):\n for j in range(Q_cnt - i + 1):\n k = Q_cnt - i - j\n if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:\n f_i = math.factorial(i)\n f_j = math.factorial(j)\n f_k = math.factorial(k)\n if f_i == 0:\n f_i = 1\n if f_j == 0:\n f_j = 1\n if f_k == 0:\n f_k = 1\n ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k\n print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)\n print(math.factorial(Q_cnt), f_i, f_j, f_k)\n print(ans)\n#ABC104D()\n\ndef ARC073D():\n N, W = map(int, input().split())\n wv = [list(map(int, input().split())) for i in range(N)]\n\ndef ARC075():\n N, A, B = map(int, input().split())\n h = [int(input()) for i in range(N)]\n def enogth(T):\n import copy\n this_h = copy.copy(h)\n cnt = 0\n for i in range(N):\n this_h[i] -= B\n key = 0\n if this_h[i] > 0:\n key = this_h[i] / (A - B)\n if int(key) != key:\n key += 1\n cnt += int(key)\n if cnt <= T:\n return True\n else:\n return False\n def sarch(i: object) -> object:\n print(i)\n if enogth(i):\n if i // 2 == 1:\n return i\n sarch(0 + i // 2)\n else:\n sarch(i + i // 2)\n print(sarch(10 ** 9))\n#ARC075()\n\ndef ARC082D():\n N = int(input())\n p = list(map(int, input().split()))\n cnt = 0\n\n for i in range(1, N - 2):\n if p[i] == i:\n p[i], p[i + 1] = p[i + 1], p[i]\n cnt += 1\n if p[N - 1] == N:\n p[-2], p[-1] = p[-1], p[-2]\n cnt += 1\n print(cnt)\nARC082D()', 'def main():\n\n S = list(input())\n checklist = [0 for i in range(26)]\n for i in S:\n checklist[ord(i) - ord("a")] += 1\n ans = True\n\n for i in checklist:\n if i > 1:\n ans = False\n\n if not ans:\n print(-1)\n return 0\n else:\n ans = False\n for i in range(len(checklist)):\n if checklist[i] == 0:\n for i in S:\n print(i, end="")\n print(chr(i + ord("a")), end = "")\n print()\n ans = True\n break\n\n if not ans:\n new_S = []\n for i in S:\n new_S.append(ord(i))\n\n for i in range(len(new_S) - 1):\n if new_S[i] > new_S[i + 1]:\n for j in range(i - 1):\n print(S[j], end = "")\n print(chr(new_S[i - 1] + 1), end = "")\n print()\n ans = True\n break\n\n if not ans:\n print(-1)\n#main()\n\ndef ABC069D():\n\n H, W = map(int, input().split())\n N = int(input())\n a = list(map(int, input().split()))\n ans = []\n for i in range(N):\n for j in range(a[i]):\n ans.append(i + 1)\n printlist = [[0 for i in range(W)] for j in range(H)]\n k = 0\n for i in range(H):\n for j in range(W):\n printlist[i][j] = ans[k]\n k += 1\n if i % 2 != 0:\n printlist[i] = printlist[i][::-1]\n\n for i in range(H):\n for j in range(W):\n print(printlist[i][j], end = "")\n if j != W:\n print(" ", end = "")\n print()\n print()\n#ABC069D()\n\nimport math\ndef cc(n, r):\n return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))\n\ndef ABC057D():\n\n N, A, B = map(int, input().split())\n v = list(map(int, input().split()))\n v = sorted(v)[::-1]\n\n anslist = []\n for i in range(A, B + 1):\n\n anslist.append([sum(v[0:i]) / i, i, v[i - 1]])\n anslist.sort()\n anslist = anslist[::-1]\n ans = anslist[0][0]\n key = anslist[0][2]\n long = anslist[0][1]\n print(ans)\n for i in range(1, len(anslist)):\n if anslist[i][0] == anslist[i - 1][0]:\n ans = anslist[i][0]\n key = anslist[i][2]\n long = anslist[i][1]\n else:\n break\n #print(anslist)\n #print(ans, key, long)\n cnt = 0\n for i in v:\n if i == key:\n cnt += 1\n\n c = 0\n for i in v[:long]:\n #print(i)\n if i == key:\n c += 1\n #print(c, long)\n ans = 0\n if c == long:\n for i in range(A, min(B + 1, cnt + 1)):\n ans += cc(cnt, i)\n else:\n ans = cc(cnt, c)\n #print(anslist)\n #print(cnt, c, long)\n print(ans)\n#ABC057D()\n\ndef ABC104D():\n S = list(input())\n A_cnt = 0\n B_cnt = 0\n C_cnt = 0\n Q_cnt = 0\n ans = 0\n for i in S:\n if i == "A":\n A_cnt += 1\n elif i == "B":\n B_cnt += 1\n elif i == "C":\n C_cnt += 1\n else:\n Q_cnt += 1\n for i in range(Q_cnt + 1):\n for j in range(Q_cnt - i + 1):\n k = Q_cnt - i - j\n if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:\n f_i = math.factorial(i)\n f_j = math.factorial(j)\n f_k = math.factorial(k)\n if f_i == 0:\n f_i = 1\n if f_j == 0:\n f_j = 1\n if f_k == 0:\n f_k = 1\n ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k\n print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)\n print(math.factorial(Q_cnt), f_i, f_j, f_k)\n print(ans)\n#ABC104D()\n\ndef ARC073D():\n N, W = map(int, input().split())\n wv = [list(map(int, input().split())) for i in range(N)]\n\ndef ARC075():\n N, A, B = map(int, input().split())\n h = [int(input()) for i in range(N)]\n def enogth(T):\n import copy\n this_h = copy.copy(h)\n cnt = 0\n for i in range(N):\n this_h[i] -= B\n key = 0\n if this_h[i] > 0:\n key = this_h[i] / (A - B)\n if int(key) != key:\n key += 1\n cnt += int(key)\n if cnt <= T:\n return True\n else:\n return False\n def sarch(i: object) -> object:\n print(i)\n if enogth(i):\n if i // 2 == 1:\n return i\n sarch(0 + i // 2)\n else:\n sarch(i + i // 2)\n print(sarch(10 ** 9))\n#ARC075()\n\ndef ARC082D():\n N = int(input())\n p = list(map(int, input().split()))\n cnt = 0\n\n for i in range(1, N - 2):\n if p[i] == i + 1:\n p[i], p[i + 1] = p[i + 1], p[i]\n cnt += 1\n if p[N - 1] == N + 1:\n p[-2], p[-1] = p[-1], p[-2]\n cnt += 1\n print(cnt)\nARC082D()', 'def ARC082D():\n N = int(input())\n p = list(map(int, input().split()))\n cnt = 0\n if p[N - 1] == N:\n #print(p[N - 1], N)\n p[-2], p[-1] = p[-1], p[-2]\n cnt += 1\n\n for i in range(N - 1):\n if p[i] == i + 1:\n p[i], p[i + 1] = p[i + 1], p[i]\n cnt += 1\n print(cnt)\nARC082D()']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s268571702', 's434529769', 's508158836', 's815354222', 's924891798']
[13940.0, 13940.0, 14008.0, 13940.0, 14008.0]
[46.0, 49.0, 46.0, 57.0, 56.0]
[4996, 4995, 4995, 5003, 334]
p03614
u298297089
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
['n = int(input())\nans = 0\nfor i,p in enumerate(map(int,input().split())):\n if i + 1 == p:\n ans += 1\nprint(max(ans-1, 0))', 'n = int(input())\nans = 0\nfor i,p in enumerate(map(int,input().split())):\n if i + 1 == p:\n ans += 1\nprint(max(ans-1), 0)', 'n = int(input())\nans = 0\nfor i,p in enumerate(map(int,input().split())):\n if i + 1 == p:\n ans += 1\nprint(ans-1)', 'n = int(input())\nans = 0\nfor i,p in enumerate(map(int,input().split())):\n if i + 1 == p:\n ans += 1\nprint(max(ans-1, 0))', 'from math import ceil\n\nn = int(input())\nans = 0\ntmp = 0\nfor i,p in enumerate(map(int,input().split())):\n if i + 1 == p:\n tmp += 1\n elif tmp:\n ans += ceil(tmp / 2)\n tmp = 0\nprint(ans + ceil(tmp / 2))\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s086300791', 's312818838', 's491650322', 's971088785', 's000058788']
[10612.0, 10420.0, 10420.0, 10420.0, 10420.0]
[60.0, 67.0, 61.0, 63.0, 70.0]
[123, 123, 115, 123, 226]
p03614
u375616706
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
['# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\nseq = 0\nans = 0\nfor i in range(1, N+1):\n if A[i] == i:\n seq += 1\n else:\n ans += (seq+1)//2\n seq = 0\nans += (seq+1)//2\nprint(ans)\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\nseq = 0\nans = 0\nfor i in range(N):\n A[i] -= i\n if A[i] == 0:\n seq += 1\n else:\n ans += (seq+1)//2\n seq = 0\nans += (seq+1)//2\nprint(ans)\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN = int(input())\nA = list(map(int, input().split()))\n\nseq = 0\nans = 0\nfor i in range(1, N+1):\n if A[i-1] == i:\n seq += 1\n else:\n ans += (seq+1)//2\n seq = 0\nans += (seq+1)//2\nprint(ans)\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s346060603', 's585484184', 's013445093']
[13876.0, 13876.0, 13876.0]
[68.0, 75.0, 67.0]
[309, 318, 311]
p03614
u690536347
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
['n=int(input())\nv=sum(1 for i,j in enumerate(map(int,input().split())) if i+1==j)\nif v: \n print(v-1)\nelse:\n print(0)', 'n=int(input())\n*l,=map(int,input().split())\nv=0\nfor i in range(n-1):\n if l[i]==i+1:\n l[i],l[i+1]=l[i+1],l[i]\n v+=1\nif l[N-1]==N:\n l[N-2],l[N-1]=l[N-1],l[N-2]\n v+=1\n \nprint(v)', 'n=int(input())\n*l,=map(int,input().split())\nv=0\nfor i in range(n-1):\n if l[i]==i+1:\n l[i],l[i+1]=l[i+1],l[i]\n v+=1\nif l[n-1]==n:\n l[n-2],l[n-1]=l[n-1],l[n-2]\n v+=1\n \nprint(v)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s253224058', 's780932209', 's984677061']
[10420.0, 14008.0, 14008.0]
[52.0, 69.0, 71.0]
[117, 186, 186]
p03614
u785989355
2,000
262,144
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N. You can perform the following operation any number of times (possibly zero): Operation: Swap two **adjacent** elements in the permutation. You want to have p_i ≠ i for all 1≤i≤N. Find the minimum required number of operations to achieve this.
['\nN=int(input())\np = list(map(int,input().split()))\ncount=0\nfor i in range(N):\n if i+1==p[i]:\n count+=1\n \nif count%2==0:\n print(int(count/2))\nelse:\n print(int((count+1)/2))', '\n\nN=int(input())\np = list(map(int,input().split()))\nbuf = 0\ncount = 0\nfor i in range(N):\n if i+1==p[i]:\n buf+=1\n else:\n count+=int((buf+1)/2)\n buf=0\ncount+=int((buf+1)/2) \nprint(count)']
['Wrong Answer', 'Accepted']
['s083916298', 's545260512']
[14008.0, 14008.0]
[59.0, 78.0]
[194, 213]
p03615
u985443069
2,000
262,144
You are given N points (x_i,y_i) located on a two-dimensional plane. Consider a subset S of the N points that forms a convex polygon. Here, we say a set of points S _forms a convex polygon_ when there exists a convex polygon with a positive area that has the same set of vertices as S. All the interior angles of the polygon must be strictly less than 180°. For example, in the figure above, {A,C,E} and {B,D,E} form convex polygons; {A,C,D,E}, {A,B,C,E}, {A,B,C}, {D,E} and {} do not. For a given set S, let n be the number of the points among the N points that are inside the convex hull of S (including the boundary and vertices). Then, we will define the _score_ of S as 2^{n-|S|}. Compute the scores of all possible sets S that form convex polygons, and find the sum of all those scores. However, since the sum can be extremely large, print the sum modulo 998244353.
['4\n0 0\n0 1\n1 0\n1 1\n', "import sys\nfrom collections import defaultdict\n\n\n\n\ndef read_int_list():\n return list(map(int, input().split()))\n\n\ndef read_int():\n return int(input())\n\n\ndef read_str_list():\n return input().split()\n\n\ndef read_str():\n return input()\n\n\ndef gcd(a, b):\n if b == 0:\n return a\n return gcd(b, a % b)\n\n\ndef solve():\n def collinear(x0, y0, x1, y1):\n return x0 * y1 == x1 * y0\n\n def aligned(i, j, k):\n return collinear(x[j] - x[i], y[j] - y[i], x[k] - x[i], y[k] - y[i])\n\n n = read_int()\n mod = 998244353\n res = pow(2, n, mod) - n - 1\n x, y = zip(*[read_int_list() for i in range(n)])\n lines = defaultdict(set)\n for i in range(n):\n for j in range(i + 1, n):\n a = y[i] - y[j]\n b = x[j] - x[i]\n g = gcd(a, b)\n a //= g\n b //= g\n if a < 0 or (a == 0 and b < 0):\n a, b = -a, -b\n c = -(a * x[i] + b * y[i])\n lines[(a, b, c)].add(i)\n lines[(a, b, c)].add(j)\n for k, v in lines.items():\n m = len(v)\n res -= pow(2, m, mod) - m - 1\n res %= mod\n return res\n\n\ndef main():\n res = solve()\n print(res)\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s589195155', 's353629901']
[2940.0, 11876.0]
[17.0, 95.0]
[18, 1257]
p03617
u026155812
2,000
262,144
You've come to your favorite store Infinitesco to buy some ice tea. The store sells ice tea in bottles of different volumes at different costs. Specifically, a 0.25-liter bottle costs Q yen, a 0.5-liter bottle costs H yen, a 1-liter bottle costs S yen, and a 2-liter bottle costs D yen. The store has an infinite supply of bottles of each type. You want to buy exactly N liters of ice tea. How many yen do you have to spend?
['Q, H, S, D = map(int, input().split())\nN = int(input())\nq = 8*Q\nh = 4*H\ns = 2*S\nif N%2 == 0:\n print(min(q,h,s,S)*(N//2))\nelse:\n print(min(q,h,s,S)*(N//2) + min(4*Q,2*H,S,D))', 'Q, H, S, D = map(int, input().split())\nN = int(input())\nq = 8*Q\nh = 4*H\ns = 2*S\nif N%2 == 0:\n print(min(q,h,s,D)*(N//2))\nelse:\n print(min(q,h,s,D)*(N//2) + min(4*Q,2*H,S))']
['Wrong Answer', 'Accepted']
['s700724577', 's265436831']
[3060.0, 3064.0]
[17.0, 18.0]
[179, 177]