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
p03111
u255943004
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\nINF = 10 ** 9\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c) > 0 else INF\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a,b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n']
['Wrong Answer', 'Accepted']
['s688319717', 's981932436']
[3188.0, 3064.0]
[55.0, 74.0]
[392, 454]
p03111
u269969976
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['# coding: utf-8\n\nlist = [int(i) for i in input().rstrip().split(" ")]\n\nmatsu_count = list[0]\nrequire = sorted(list[1:])\n\nmatsu_list = sorted([int(input().rstrip()) for i in range(matsu_count)])\n\ndef get_mp(matsu:list):\n ans = 0\n for i in range(3):\n ans += abs(matsu[i] - require[i])\n return ans\nmp = {}\ndef get_ans(matsu:list):\n if len(matsu) == 3:\n return get_mp(matsu)\n key = "#".join(matsu)\n if key in mp:\n return mp[key]\n ans = 80000\n for i in range(len(matsu) - 3 + 1):\n ans = min(ans, get_mp(matsu[i:]))\n for i in range(len(matsu)):\n for j in range(i + 1, len(matsu)):\n sub_matsu = []\n for k in range(len(matsu)):\n if k == i or k == j:\n continue\n else:\n sub_matsu.append(matsu[k])\n sub_matsu.append(matsu[i] + matsu[j])\n ans = min(ans, get_ans(sorted(sub_matsu)) + 10)\n\n mp[key] = ans\n return ans\n\nans = get_ans(matsu_list)\nprint(ans)\n\n', '# coding: utf-8\n\nlist = [int(i) for i in input().rstrip().split(" ")]\n\nmatsu_count = list[0]\nrequire = sorted(list[1:])\n\nmatsu_list = sorted([int(input().rstrip()) for i in range(matsu_count)])\n\ndef get_mp(matsu:list):\n ans = 0\n for i in range(3):\n ans += abs(matsu[i] - require[i])\n return ans\nmp = {}\n\ndef get_ans(matsu:list):\n if len(matsu) == 3:\n return get_mp(matsu)\n key = "#".join(map(str, matsu))\n if key in mp:\n return mp[key]\n ans = 80000\n for i in range(len(matsu) - 3 + 1):\n for j in range(i + 1, len(matsu) - 2 + 1):\n for k in range(j + 1, len(matsu) - 1 + 1):\n ans = min(ans, get_mp([matsu[i],matsu[j], matsu[k]]))\n if ans > 0:\n for i in range(len(matsu)):\n for j in range(i + 1, len(matsu)):\n sub_matsu = []\n for k in range(len(matsu)):\n if k == i or k == j:\n continue\n else:\n sub_matsu.append(matsu[k])\n sub_matsu.append(matsu[i] + matsu[j])\n ans = min(ans, get_ans(sorted(sub_matsu)) + 10)\n\n mp[key] = ans\n return ans\n\nans = get_ans(matsu_list)\nprint(ans)\n\n']
['Runtime Error', 'Accepted']
['s676243416', 's434190063']
[3064.0, 3828.0]
[18.0, 152.0]
[1022, 1223]
p03111
u286201019
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['# N A B C\n# l1\n# l2\n# ...\n\n(N, A, B, C) = int(input().split())\nL = []\nfor i in range(N):\n l = int(input())\n L.append(l)\n# N = 5\n# A = 100\n# B = 90\n# C = 80\n# L = [98, 40, 30, 21, 80]\n\ndef recur_function(a, b, c, n):\n if n == N:\n return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else 10**9\n ret0 = recur_function(a + L[n], b, c, n + 1) + 10 if a > 0 else recur_function(a + L[n], b, c, n + 1)\n ret1 = recur_function(a, b + L[n], c, n + 1) + 10 if b > 0 else recur_function(a, b + L[n], c, n + 1)\n ret2 = recur_function(a, b, c + L[n], n + 1) + 10 if c > 0 else recur_function(a, b, c + L[n], n + 1)\n ret3 = recur_function(a, b, c, n + 1)\n return min(ret0, ret1, ret2, ret3)\n\nprint(recur_function(0, 0, 0, 0))', '# N A B C\n# l1\n# l2\n# ...\n\ntmp = input().split()\n(N, A, B, C) = (int(tmp[i]) for i in range(4))\nL = []\nfor i in range(N):\n l = int(input())\n L.append(l)\n# N = 5\n# A = 100\n# B = 90\n# C = 80\n# L = [98, 40, 30, 21, 80]\n\ndef recur_function(a, b, c, n):\n if n == N:\n return abs(a - A) + abs(b - B) + abs(c - C) if min(a, b, c) > 0 else 10**9\n ret0 = recur_function(a + L[n], b, c, n + 1) + 10 if a > 0 else recur_function(a + L[n], b, c, n + 1)\n ret1 = recur_function(a, b + L[n], c, n + 1) + 10 if b > 0 else recur_function(a, b + L[n], c, n + 1)\n ret2 = recur_function(a, b, c + L[n], n + 1) + 10 if c > 0 else recur_function(a, b, c + L[n], n + 1)\n ret3 = recur_function(a, b, c, n + 1)\n return min(ret0, ret1, ret2, ret3)\n\nprint(recur_function(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s293473769', 's307479263']
[3064.0, 3064.0]
[17.0, 71.0]
[753, 786]
p03111
u288087195
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = list(map(str, input().split()))\nl = []\nfor i in range(N):\n l.append(int(input()))\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N:\n return abs(A - sum(A_list)) + abs(B - sum(B_list)) + abs(C - sum(C_list))\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([], [], [], 0)\nprint(ans)\n', 'N, A, B, C = list(map(str, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N:\n return abs(A - sum(A_list)) + abs(B - sum(B_list)) + abs(C - sum(C_list))\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([], [], [], 0)\nprint(ans)\n', 'N, A, B, C = list(map(str, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N:\n return A - sum(A_list) + B - sum(B_list) + C - sum(C_list)\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([0], [0], [0], N)\nprint(ans)\n', 'N, A, B, C = list(map(str, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N:\n return A - sum(A_list) + B - sum(B_list) + C - sum(C_list)\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([0], [0], [0], 0)\nprint(ans)\n', 'N, A, B, C = list(map(str, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N - 1:\n return A - sum(A_list) + B - sum(B_list) + C - sum(C_list)\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([0], [0], [0], 8)\nprint(ans)\n', 'N, A, B, C = list(map(str, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(A_list, B_list, C_list, i):\n if i == N:\n return A - sum(A_list) + B - sum(B_list) + C - sum(C_list)\n\n dfs_not_used = dfs(A_list, B_list, C_list, i+1)\n dfs_A = dfs(A_list.append(l[i]), B_list, C_list, i+1) + 10\n dfs_B = dfs(A_list, B_list.append(l[i]), C_list, i+1) + 10\n dfs_C = dfs(A_list, B_list, C_list.append(l[i]), i+1) + 10\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs([0], [0], [0], 8)\nprint(ans)\n', 'N, A, B, C = list(map(int, input().split()))\nl = [0]*N\nfor i in range(N):\n l[i] = int(input())\n\n\ndef dfs(a, b, c, i):\n if i == N:\n if a == 0 or b == 0 or c == 0:\n return 1e9\n\n return abs(A - a) + abs(B - b) + abs(C - c)\n\n dfs_not_used = dfs(a, b, c, i+1)\n dfs_A = dfs(a+l[i], b, c, i+1) + + 10*(a != 0)\n dfs_B = dfs(a, b+l[i], c, i+1) + 10*(b != 0)\n dfs_C = dfs(a, b, c+l[i], i+1) + 10*(c != 0)\n\n return min(dfs_not_used, dfs_A, dfs_B, dfs_C)\n\n\nans = dfs(0, 0, 0, 0)\nprint(ans)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s037907232', 's076277700', 's141191697', 's425207661', 's764674755', 's880232425', 's776390851']
[3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0, 3064.0]
[18.0, 17.0, 17.0, 17.0, 17.0, 17.0, 65.0]
[564, 564, 552, 552, 556, 552, 524]
p03111
u303059352
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import os\nimport math\nfrom itertools import permutations\nimport functools as func\nINF, MOD = float("inf"), 1e9 + 7\nMAX, MIN = -INF, INF\ndx1, dy1, dx2, dy2 = [-1, 0, 1, 0], [0, -1, 0, 1], [-1, 0, 1, -1, 1, -1, 0, 1], [-1, -1, -1, 0, 0, 1, 1, 1]\n\ndef get_int():\n return int(input())\n\ndef get_int_list():\n return list(map(int, input().split()))\n\nwhile(True):\n try:\n n, a, b, c = get_int_list()\n l = [get_int() for _ in range(n)]\n ans = 1000000000000\n for take in permutations(l, n):\n #print(take)\n take = list(take)\n cnt = 0\n i = 3\n while abs(take[0] - c) > 10 and take[0] < c and abs(take[0] + take[i] - c) < abs(take[0] - c):\n if i >= n:\n break\n take[0] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[0] - c)\n #print(take[0])\n\n while abs(take[1] - b) > 10 and take[1] < b and abs(take[1] + take[i] - b) < abs(take[1] - b):\n if i >= n:\n break\n take[1] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[1] - b)\n #print(take[1])\n\n while abs(take[2] - a) > 10 and take[2] < a and abs(take[2] + take[i] - a) < abs(take[2] - a):\n if i >= n:\n break\n take[2] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[2] - a)\n #print(take[2])\n\n ans = min(ans, cnt)\n \n # print(take[0], take[1], take[2])\n print(ans)\n except EOFError:\n exit()\n', 'from itertools import permutations\n\ndef get_int():\n return int(input())\n\ndef get_int_list():\n return list(map(int, input().split()))\n\nwhile(True):\n try:\n n, a, b, c = get_int_list()\n l = [get_int() for _ in range(n)]\n ans = 1000000000000\n for take in permutations(l, n):\n #print(take)\n take = list(take)\n cnt = 0\n i = 3\n while True:\n if i >= n:\n break\n if abs(take[2] - a) < 10:\n break\n if take[2] > a:\n break\n if abs(take[2] + take[i] - a) >= abs(take[2] - a):\n break\n if take[i] <= 10:\n break\n take[2] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[2] - a)\n #print(take[2])\n\n while True:\n if i >= n:\n break\n if abs(take[1] - b) < 10:\n break\n if take[1] > b:\n break\n if abs(take[1] + take[i] - b) >= abs(take[1] - b):\n break\n if take[i] <= 10:\n break\n take[1] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[1] - b)\n #print(take[1])\n\n while True:\n if i >= n:\n break\n if abs(take[0] - c) < 10:\n break\n if take[0] > c:\n break\n if abs(take[0] + take[i] - c) >= abs(take[0] - c):\n break\n if take[i] <= 10:\n break\n take[0] += take[i]\n i += 1\n cnt += 10\n cnt += abs(take[0] - c)\n #print(take[0])\n\n ans = min(ans, cnt)\n \n # print(take[0], take[1], take[2])\n print(ans)\n except EOFError:\n exit()\n']
['Runtime Error', 'Accepted']
['s503297073', 's219369147']
[3700.0, 3188.0]
[180.0, 300.0]
[1703, 2082]
p03111
u305965165
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n, A, B, C = (int(i) for i in input().split()) #a=1, b=3, c=5, d=7\nl = [int(input()) for i in range(n)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n \nprint(dfs(0, 0, 0, 0))', 'n, A, B, C = (int(i) for i in input().split()) #a=1, b=3, c=5, d=7\nl = [int(input()) for i in range(n)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == n:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n \nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s996220309', 's141690174']
[3064.0, 3064.0]
[17.0, 74.0]
[486, 486]
p03111
u310678820
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['def ttt (x,y,z,i,m,p,q,r):\n if i==n and (p==0 or q==0 or r==0):\n print(p,q,r)\n return 10000000\n if i==n:\n m+=abs(x-a)+abs(y-b)+abs(z-c)\n return m\n else:\n return min(ttt(x,y,z,i+1,m,p,q,r), ttt(x+l[i],y,z,i+1,m+10,p+1,q,r), \n ttt(x,y+l[i],z,i+1,m+10,p,q+1,r), ttt(x,y,z+l[i],i+1,m+10,p,q,r+1))\nn,a,b,c=[5, 100, 90, 80]\nl=[98,40,30,21,80]\nprint(ttt(0,0,0,0,0,0,0,0)-30)', 'def ttt (x,y,z,i,m,p,q,r):\n if i==n and (p==0 or q==0 or r==0):\n return 10000000\n if i==n:\n m+=abs(x-a)+abs(y-b)+abs(z-c)\n return m\n else:\n return min(ttt(x,y,z,i+1,m,p,q,r), ttt(x+l[i],y,z,i+1,m+10,p+1,q,r), \n ttt(x,y+l[i],z,i+1,m+10,p,q+1,r), ttt(x,y,z+l[i],i+1,m+10,p,q,r+1))\nn,a,b,c=map(int, input().split())\nl=[int(input()) for i in range(n)]\nprint(ttt(0,0,0,0,0,0,0,0)-30)\n']
['Wrong Answer', 'Accepted']
['s092837335', 's703578024']
[3316.0, 3064.0]
[19.0, 70.0]
[399, 408]
p03111
u316322317
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,a,b,c=map(int,input().split())\nl=[]\nfor _ in range(n):\n x=int(input())\n l.append(x)\n\ndef dfs(cur,x,y,z):\n if cur==n and min(x,y,z)>0:\n return abs(a-x)+abs(b-y)+abs(c-z)-30\n elif cur==n:\n return inf\n ret0=dfs(cur+1,x,y,z)\n ret1=dfs(cur+1,x+l[cur],y,z)+10\n ret2=dfs(cur+1,x,y+l[cur],z)+10\n ret3=dfs(cur+1,x,y,z+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))\n', 'n,a,b,c=map(int,input().split())\nl=[]\nfor _ in range(n):\n d=int(input())\n l.append(d)\n\ndef dfs(cur,x,y,z):\n if cur==n and min(x,y,z)>0:\n return abs(a-x)+abs(b-y)+abs(c-z)-30\n elif cur==n:\n return 100000000000000000000\n ret0=dfs(cur+1,x,y,z)\n ret1=dfs(cur+1,x+l[cur],y,z)+10\n ret2=dfs(cur+1,x,y+l[cur],z)+10\n ret3=dfs(cur+1,x,y,z+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))']
['Runtime Error', 'Accepted']
['s722842208', 's058817931']
[3064.0, 3064.0]
[18.0, 76.0]
[391, 408]
p03111
u316386814
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n, a, b, c = list(map(int, input().split()))\ngoals = [a, b, c]\nbamboos = []\nfor _ in range(n):\n bamboos.append(int(input()))\n\ndef get_best(li, goal):\n bam_mp_lis = {0: (-10, tuple())}\n li.sort()\n for i, v in enumerate(li):\n tmp = bam_mp_lis.copy()\n for bam, (mp, lis) in tmp.items():\n b0 = bam + v\n m0 = mp + 10\n l0 = lis + (i,)\n if b0 not in bam_mp_lis or m0 < bam_mp_lis[b0][0]:\n bam_mp_lis[b0] = (m0, l0)\n del bam_mp_lis[0]\n best = 10 ** 9\n for bam, (mp, lis) in bam_mp_lis.items():\n cost = mp + abs(goal - bam)\n if cost < best:\n best = cost\n beslis = lis\n return best, beslis\n\nans = 10 ** 9\nfrom itertools import permutations\nfor junjo in permutations(goals):\n tmp = 0\n bambooo = bamboos.copy()\n for ju in junjo:\n be, beli = get_best(bambooo, ju)\n beli = sorted(beli, reverse=True)\n for beli0 in beli:\n del bambooo[beli0]\n tmp += be\n if len(bambooo) == 0:\n tmp = 10 ** 9\n break\n if tmp < ans:\n ans = tmp\n\nprint(ans)\n', 'N, A, B, C = map(int, input().split())\nGoals = [A, B, C]\nbamboos = []\nfor _ in range(N):\n bamboos.append(int(input()))\nINF = 10 ** 9\n\ndef dfs(cur, bs):\n if cur == N:\n return sum(abs(x - y) for x, y in zip(bs, Goals)) - 30 if min(bs) > 0 else INF\n ret = dfs(cur + 1, bs)\n for i in range(len(bs)):\n bs0 = bs.copy()\n bs0[i] += bamboos[cur]\n ret = min(ret, dfs(cur + 1, bs0) + 10)\n return ret\n\nans = dfs(0, [0, 0, 0])\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s655040627', 's558248391']
[3064.0, 3064.0]
[19.0, 140.0]
[1140, 469]
p03111
u332906195
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["# -*- coding: utf-8 -*-\n\nimport itertools\nINF = 1e10\n\nN, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\nans = INF\nfor prod in itertools.product('NABC', repeat=N):\n if not ('A' in prod and 'B' in prod and 'C' in prod):\n continue\n\n D = {'A': [], 'B': [], 'C': [], 'N': []}\n for i in range(N):\n D[prod[i]].append(L[i])\n\n tmp = (len(D['A']) - 1) * 10 + abs(sum(D['A']) - A)\n tmp += (len(D['B']) - 1) * 10 + abs(sum(D['B']) - A)\n tmp += (len(D['C']) - 1) * 10 + abs(sum(D['C']) - A)\n ans = min(ans, tmp)\n\nprint(ans)\n", "# -*- coding: utf-8 -*-\n\nimport itertools\nINF = 1e10\n\nN, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\nans = INF\nfor prod in itertools.product('NABC', repeat=N):\n if not ('A' in prod and 'B' in prod and 'C' in prod):\n continue\n\n D = {'A': [], 'B': [], 'C': [], 'N': []}\n for i in range(N):\n D[prod[i]].append(L[i])\n\n tmp = (len(D['A']) - 1) * 10 + abs(sum(D['A']) - A)\n tmp += (len(D['B']) - 1) * 10 + abs(sum(D['B']) - B)\n tmp += (len(D['C']) - 1) * 10 + abs(sum(D['C']) - C)\n ans = min(ans, tmp)\n\nprint(ans)\n"]
['Wrong Answer', 'Accepted']
['s493688878', 's361894102']
[3064.0, 3064.0]
[240.0, 250.0]
[573, 573]
p03111
u340010271
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\ndef dfs(d,a,b,c):\n if d==n:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf \n ret0=dfs(d+1,a,b,c)\n ret1=dfs(d+1,a+l[d],b,c)+10\n ret2=dfs(d+1,a,b+l[d],c)+10\n ret3=dfs(d+1,a,b,c+l[d])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))', 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\ndef dfs(d,a,b,c):\n if d==n:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf\n ret0=def(d+1,a,b,c)\n ret1=def(d+1,a+l[d],b,c)+10\n ret2=def(d+1,a,b+l[d],c)+10\n ret3=def(d+1,a,b,c+l[d])+10\n return min(ret0,ret1,ret2,ret3)\nprint(def(0,0,0,0))', 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\ndef dfs(d,a,b,c):\n if d==n:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf \n ret0=dfs(d+1,a,b,c)\n ret1=dfs(d+1,a+l[d],b,c)+10\n ret2=dfs(d+1,a,b+l[d],c)+10\n ret3=dfs(d+1,a,b,c+l[d])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))', 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\ndef dfs(d,a,b,c):\n if d==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf \n ret0=dfs(d+1,a,b,c)\n ret1=dfs(d+1,a+l[d],b,c)+10\n ret2=dfs(d+1,a,b+l[d],c)+10\n ret3=dfs(d+1,a,b,c+l[d])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s142442922', 's206842330', 's779893337', 's107280414']
[3064.0, 2940.0, 3064.0, 3064.0]
[18.0, 18.0, 18.0, 76.0]
[449, 423, 498, 498]
p03111
u346527636
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["tgt_b = int(str_in[2])\ntgt_c = int(str_in[3])\n\nsource = [int(input()) for i in range(num)]\n\nmp = float('inf')\n\nfor i in range(1,2**num):\n\n sum_a = 0\n len_a = 0\n \n bin_i = format(i,'0256b') \n for t in range(1,num+1):\n sum_a += int(bin_i[-t])\n len_a += int(bin_i[-t]) * source[t-1]\n \n for j in range(1,2**num):\n \n sum_b = 0\n len_b = 0\n\n if (i & j) > 0:\n continue\n \n bin_j = format(j,'0256b')\n for t in range(1,num+1):\n sum_b += int(bin_j[-t])\n len_b += int(bin_j[-t]) * source[t-1]\n\n for k in range(1,2**num):\n\n sum_c = 0\n len_c = 0\n \n if (i & k) > 0:\n continue\n elif(j & k) > 0:\n continue\n \n bin_k = format(k,'08b') \n \n for t in range(1,num+1):\n sum_c += int(bin_k[-t])\n len_c += int(bin_k[-t]) * source[t-1]\n \n mp_try = abs(len_a - tgt_a) + abs(len_b - tgt_b) + abs(len_c - tgt_c) + (sum_a + sum_b + sum_c - 3) * 10 \n if(mp > mp_try):\n mp = mp_try\n\nprint (mp)\n", "str_in = input().split()\nnum = int(str_in[0])\ntgt_a = int(str_in[1])\ntgt_b = int(str_in[2])\ntgt_c = int(str_in[3])\n\nsource = [int(input()) for i in range(num)]\n\nmp = float('inf')\n\nfor i in range(1,2**num):\n\n sum_a = 0\n len_a = 0\n \n bin_i = format(i,'08b') \n for t in range(1,num+1):\n sum_a += int(bin_i[-t])\n len_a += int(bin_i[-t]) * source[t-1]\n \n for j in range(1,2**num):\n \n sum_b = 0\n len_b = 0\n\n if (i & j) > 0:\n continue\n \n bin_j = format(j,'08b')\n for t in range(1,num+1):\n sum_b += int(bin_j[-t])\n len_b += int(bin_j[-t]) * source[t-1]\n\n for k in range(1,2**num):\n\n sum_c = 0\n len_c = 0\n \n if (i & k) > 0:\n continue\n elif(j & k) > 0:\n continue\n \n bin_k = format(k,'08b') \n \n for t in range(1,num+1):\n sum_c += int(bin_k[-t])\n len_c += int(bin_k[-t]) * source[t-1]\n \n mp_try = abs(len_a - tgt_a) + abs(len_b - tgt_b) + abs(len_c - tgt_c) + (sum_a + sum_b + sum_c - 3) * 10 \n if(mp > mp_try):\n mp = mp_try\n\nprint (mp)\n"]
['Runtime Error', 'Accepted']
['s289254727', 's297589188']
[3064.0, 3064.0]
[17.0, 687.0]
[1018, 1085]
p03111
u366959492
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(n)]\ninf=10**9\n\ndef dfs(cur,a,b,c):\n if cur==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf\n ret0=dfs(cur+1,a,b,c)\n ret1=dfs(cur+1,a+l[cur],b,c)+10\n ret2=dfs(cur+1,a,b+l[cur],c)+10\n ret3=dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))\n', 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\n\ndef dfs(cur,a,b,c):\n if cur==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf\n ret0=dfs(cur+1,a,b,c)\n ret1=dfs(cur+1,a+l[cur],b,c)+10\n ret2=dfs(cur+1,a,b+l[cur],c)+10\n ret3=dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))\n']
['Runtime Error', 'Accepted']
['s573851376', 's630489040']
[3064.0, 3064.0]
[17.0, 74.0]
[375, 375]
p03111
u367130284
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from itertools import*\nn,a,b,c,*l=map(int,open(0).read().split())\nwant=[a,b,c]\nans=0\n\nfor s in range(3):\n if want[s] in l:\n l.remove(want[s])\n want[s]=0\n\nwant=list(filter(lambda x:x!=0,want))\nfor s in range(3):\n for t in l:\n if abs(want[s]-t)<10:\n ans+=abs(want[s]-t)\n l.remove(t)\n want[s]=0\nwant=list(filter(lambda x:x!=0,want))\n\nx=[]\ny=[]\nz=[]\nfor s in range(1,len(l)+1):\n x.extend(list(combinations(l,s)))\n#print(x)\nfor s in want:\n for t in range(len(x)):\n y.append(abs(s-sum(x[t]))+(len(x[t])-1)*10)\n z.append(x[t])\n ans+=min(y)\n# print(x[y.count(min(y))])\n x[y.count(min(y))]=(999999,9999999)\nprint(ans)', 'from itertools import*\nn,a,b,c,*l=map(int,open(0).read().split())\nans=float("inf")\nfor i in product(range(4),repeat=n): \n take=[[],[],[]]\n for k,j in enumerate(i):\n if j==3:\n continue\n take[j].append(l[k])\n *tmp,=map(len,take)\n if all(tmp):\n x,y,z=map(sum,take)\n ans=min(ans, (sum(tmp)-3)*10 + abs(x-a) + abs(y-b) + abs(z-c) )\nprint(ans)']
['Runtime Error', 'Accepted']
['s830360597', 's346717941']
[3064.0, 3188.0]
[18.0, 325.0]
[693, 402]
p03111
u371467115
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF=10**9\n\ndef dfs(cur, a, b, c):\nif cur == N:\nreturn abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\nret0 = dfs(cur + 1, a, b, c)\nret1 = dfs(cur + 1, a + l[cur], b, c) + 10\nret2 = dfs(cur + 1, a, b + l[cur], c) + 10\nret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\nreturn min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n#example answer', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF=10**9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n#example answer\n']
['Runtime Error', 'Accepted']
['s374196425', 's355568380']
[2940.0, 3064.0]
[18.0, 72.0]
[433, 450]
p03111
u371763408
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,A,B,C=(map(int,input().split()))\nl=[int(input()) for i in range(n)]\nans=10**9\na=b=c=[]\nfor i in range(1<<n):\n for j in range(1<<n):\n res=0\n a=b=c=[]\n for k in range(n):\n if i&(1<<k):\n if j&(1<<k):\n b.append(l[k])\n else:\n a.append(l[k])\n elif j&(1<<k):\n c.append(l[k])\n if a and b and c:\n res = 10*(len(a)-1)+abs(A-sum(a))+10*(len(b)-1)+abs(B-sum(b))+10*(len(c)-1)+abs(C-sum(c))\n ans=min(ans,res)\nprint(ans)', 'import itertools\nn,a,b,c=(map(int,input().split()))\nl=[int(input()) for i in range(n)]\nans=10**9\nfor k in itertools.product(range(4),repeat=n):\n A=[[] for i in range(4)]\n for i in range(n):\n A[k[i]]+=[l[i]]\n print(A)\n if A[1] and A[2] and A[3]:\n tmp=10*(n-len(A[0])-3) \n tmp+=abs(a-sum(A[1]))\n tmp+=abs(b-sum(A[2]))\n tmp+=abs(c-sum(A[3]))\n ans=min(tmp,ans)\nprint(ans)', 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\ninf=10**9\ndef dfs(cur,a,b,c):\n if cur==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else inf\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s344616381', 's530760586', 's271644574']
[3064.0, 6260.0, 3316.0]
[365.0, 555.0, 68.0]
[566, 550, 364]
p03111
u373274281
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from copy import copy\nN, A, B, C = map(int, input().split())\nL = []\nfor _ in range(N):\n L.append(int(input()))\n\nINF = 10 ** 9\ndef dfs(cur, a, b, c, m):\n if cur == N-1:\n if min(a, b, c) == 0:\n return INF\n return abs(A-a)+abs(B-b)+abs(C-c)+(m-3)*10\n\n res0 = dfs(cur+1, a, b, c, m)\n res1 = dfs(cur+1, a+L[cur], b, c, m+1)\n res2 = dfs(cur+1, a, b+L[cur], c, m+1)\n res3 = dfs(cur+1, a, b, c+L[cur], m+1)\n\n return min(res0, res1, res2, res3)\n\nprint(dfs(0, 0, 0, 0, 0))\n', 'from copy import copy\nN, A, B, C = map(int, input().split())\nL = []\nfor _ in range(N):\n L.append(int(input()))\n\nINF = 10 ** 9\ndef dfs(cur, a, b, c, m):\n if cur == N:\n if min(a, b, c) == 0:\n return INF\n return abs(A-a)+abs(B-b)+abs(C-c)+(m-3)*10\n\n res0 = dfs(cur+1, a, b, c, m)\n res1 = dfs(cur+1, a+L[cur], b, c, m+1)\n res2 = dfs(cur+1, a, b+L[cur], c, m+1)\n res3 = dfs(cur+1, a, b, c+L[cur], m+1)\n\n return min(res0, res1, res2, res3)\n\nprint(dfs(0, 0, 0, 0, 0))\n']
['Wrong Answer', 'Accepted']
['s491765863', 's236233370']
[3444.0, 3444.0]
[38.0, 79.0]
[481, 479]
p03111
u374103100
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['\nimport copy\n\ndef solve(t, l, c):\n \n min_cost = 100000\n cand = []\n\n ptn = 1 << len(l)\n # print(l)\n # print("ptn = {}".format(ptn))\n for i in range(1, ptn):\n answers = []\n for j in range(0, len(l)):\n if (i >> j) & 1:\n answers.append(l[j])\n temp_cost = abs(t - sum(answers)) + (10 * (len(answers) - 1) if len(answers) > 1 else 0)\n if temp_cost < min_cost:\n min_cost = temp_cost\n cand = answers\n\n # print("cand = {}".format(cand))\n for d in cand:\n del l[l.index(d)]\n return min_cost, l\n\ndef main():\n N, A, B, C = map(int, input().split())\n L = [int(input()) for _ in range(N)]\n L.sort()\n\n answer = 1000000\n for targets in [[A, B, C], [A, C, B],[B, A, C],[B, C, A], [C,B,A],[C,A,B]]:\n is_done = [False] * 3\n L2 = copy.copy(L)\n total_cost = 0\n for i in range(len(targets)):\n if targets[i] in L:\n del L[L.index(targets[i])]\n is_done[i] = True\n\n for i in range(3):\n if is_done[i]:\n continue\n\n \n # print("try target = {}".format(targets[i]))\n cost, L2 = solve(targets[i], L2, 0)\n # print("cost = {}".format(cost))\n total_cost += cost\n\n answer = min(answer, total_cost)\n\n print(answer)\n\n\nif __name__ == \'__main__\':\n main()\n', '\nimport copy\n\ndef solve(t, l, c):\n \n min_cost = 100000\n cand = []\n\n ptn = 1 << len(l)\n # print(l)\n # print("ptn = {}".format(ptn))\n for i in range(1, ptn):\n answers = []\n for j in range(0, len(l)):\n if (i >> j) & 1:\n answers.append(l[j])\n temp_cost = abs(t - sum(answers)) + (10 * (len(answers) - 1) if len(answers) > 1 else 0)\n if temp_cost < min_cost:\n min_cost = temp_cost\n cand = answers\n\n # print("cand = {}".format(cand))\n for d in cand:\n del l[l.index(d)]\n return min_cost, l\n\ndef main():\n N, A, B, C = map(int, input().split())\n target = [A, B, C]\n\n is_done = [False] * 3\n\n L = [int(input()) for _ in range(N)]\n L.sort()\n\n for i in range(len(target)):\n if target[i] in L:\n del L[L.index(target[i])]\n is_done[i] = True\n\n answer = 1000000\n for targets in [[A, B, C], [A, C, B],[B, A, C],[B, C, A], [C,B,A],[C,A,B]]:\n L2 = copy.copy(L)\n total_cost = 0\n for i in range(3):\n if is_done[i]:\n continue\n\n \n # print("try target = {}".format(targets[i]))\n cost, L2 = solve(targets[i], L2, 0)\n # print("cost = {}".format(cost))\n total_cost += cost\n\n answer = min(answer, total_cost)\n\n print(answer)\n\n\nif __name__ == \'__main__\':\n main()\n', "\nimport itertools\nimport collections\nfrom bisect import bisect\n\n\n\ndef main():\n N, A, B, C = map(int, input().split())\n L = [int(input()) for _ in range(N)]\n\n def solve(i, a, b, c):\n if i == N:\n \n \n return abs(A-a) + abs(B-b) + abs(C-c) - 30 if min(a, b, c) > 0 else int(1e15)\n ret0 = solve(i + 1, a, b, c)\n ret1 = solve(i + 1, a + L[i], b, c) + 10\n ret2 = solve(i + 1, a, b + L[i], c) + 10\n ret3 = solve(i + 1, a, b, c + L[i]) + 10\n return min(ret0, ret1, ret2, ret3)\n\n print(solve(0, 0, 0, 0))\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s527464343', 's919207958', 's063570411']
[3444.0, 3444.0, 3436.0]
[27.0, 27.0, 84.0]
[1598, 1600, 809]
p03111
u379692329
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(index, a, b, c):\n if index == N:\n return abs(a-A)+abs(b-B)+abs(c+C)-30 if min(a, b, c) > 0 else float('inf')\n \n val1 = dfs(index+1, a, b, c)\n val2 = dfs(index+1, a+l[index], b, c) + 10\n val3 = dfs(index+1, a, b+l[index], c) + 10\n val4 = dfs(index+1, a, b, c+l[index]) + 10\n return min(val1, val2, val3, val4)\n\nprint(dfs(0, 0, 0, 0))", "N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(index, a, b, c):\n if index == N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a, b, c) > 0 else float('inf')\n \n val1 = dfs(index+1, a, b, c)\n val2 = dfs(index+1, a+l[index], b, c) + 10\n val3 = dfs(index+1, a, b+l[index], c) + 10\n val4 = dfs(index+1, a, b, c+l[index]) + 10\n return min(val1, val2, val3, val4)\n\nprint(dfs(0, 0, 0, 0))"]
['Wrong Answer', 'Accepted']
['s884082137', 's202521514']
[3064.0, 3064.0]
[81.0, 80.0]
[445, 445]
p03111
u379959788
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a-A)+abs(b-B)+abs(c-C)-30\n else:\n return INF\n ret1 = dfs(cur+1, a, b, c)\n ret2 = dfs(cur+1, a+L[cur], b, c) + 10\n ret3 = dfs(cur+1, a, b+L[cur], c) + 10\n ret4 = dfs(cur+1, a, b, c+L[cur]) + 10\n return min(ret1 + ret2 + ret3 + ret4)\n\nprint(dfs(0,0,0,0))\n', 'N, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a-A)+abs(b-B)+abs(c-C)-30\n else:\n return INF\n ret1 = dfs(cur+1, a, b, c)\n ret2 = dfs(cur+1, a+L[cur], b, c) + 10\n ret3 = dfs(cur+1, a, b+L[cur], c) + 10\n ret4 = dfs(cur+1, a, b, c+L[cur]) + 10\n return min(ret1, ret2, ret3, ret4)\n\nprint(dfs(0,0,0,0))\n']
['Runtime Error', 'Accepted']
['s342562602', 's623920862']
[3064.0, 3064.0]
[18.0, 71.0]
[470, 467]
p03111
u382639013
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nfrom itertools import product\nl = [int(input()) for i in range(N)]\nans = []\nfor i in product(range(4), repeat=N):\n a = 0\n b = 0\n c = 0\n d = 0\n for j in range(N):\n if i[j]:\n d += 1\n if i[j] == 1:\n a += l[j]\n elif i[j] == 2:\n b += l[j]', 'N, A, B, C = map(int, input().split())\nfrom itertools import product\nl = [int(input()) for i in range(N)]\nans = []\nfor i in product(range(4), repeat=N):\n a = 0\n b = 0\n c = 0\n d = 0\n for j in range(N):\n if i[j]:\n d += 1\n if i[j] == 1:\n a += l[j]\n elif i[j] == 2:\n b += l[j]\n else:\n c += l[j]\n if a * b * c:\n ans += [abs(A - a) + abs(B - b) + abs(C - c) + (d - 3) * 10]\nprint(min(ans))']
['Wrong Answer', 'Accepted']
['s833193084', 's402862615']
[9204.0, 10916.0]
[151.0, 190.0]
[309, 436]
p03111
u384261199
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A,B,C = map(int, input().split())\nl = sorted([int(input()) for _ in range(N)])[-1::-1]\n\nINF = 1e+10\n\ndef DFS(depth, current_a, current_b, current_c):\n if depth == N:\n if min(current_a, current_b, current_c) > 0:\n return abs(current_a - A) + abs(current_b - B) + abs(current_c - C) -30\n else:\n return INF\n \n ret0 = DFS(depth+1, current_a, current_b, current_c)\n ret1 = DFS(depth+1, current_a + l[depth], current_b, current_c)\n ret2 = DFS(depth+1, current_a , current_b+ l[depth], current_c)\n ret3 = DFS(depth+1, current_a, current_b, current_c + l[depth])\n \n return min(ret0, ret1, ret2, ret3)\n\nprint(DFS(0, 0, 0, 0))', 'N, A,B,C = map(int, input().split())\nl = sorted([int(input()) for _ in range(N)])[-1::-1]\n\nINF = 1e+10\n\ndef DFS(depth, current_a, current_b, current_c):\n if depth == N:\n if min(current_a, current_b, current_c) > 0:\n return abs(current_a - A) + abs(current_b - B) + abs(current_c - C) -30\n else:\n return INF\n \n ret0 = DFS(depth+1, current_a, current_b, current_c)\n ret1 = DFS(depth+1, current_a + l[depth], current_b, current_c) + 10\n ret2 = DFS(depth+1, current_a , current_b+ l[depth], current_c) + 10\n ret3 = DFS(depth+1, current_a, current_b, current_c + l[depth]) + 10\n \n return min(ret0, ret1, ret2, ret3)\n\nprint(DFS(0, 0, 0, 0))']
['Wrong Answer', 'Accepted']
['s887858080', 's290611976']
[3064.0, 3064.0]
[73.0, 74.0]
[679, 694]
p03111
u389910364
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import bisect\nimport heapq\nimport itertools\nimport math\nimport os\nimport re\nimport string\nimport sys\nfrom collections import Counter, deque, defaultdict\nfrom fractions import gcd\nfrom functools import lru_cache, reduce\n\nimport numpy as np\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(2147483647)\nINF = float("inf")\n\nN, A, B, C = list(map(int, sys.stdin.readline().split()))\nL = [int(sys.stdin.readline()) for _ in range(N)]\n\nL = np.array(L)\n\n\nchoosing = list(itertools.product([0, 1, 2, 3], repeat=N))\n\n\n\n\nans = INF\nfor choose in np.array(choosing):\n a = L[choose == 1]\n b = L[choose == 2]\n c = L[choose == 3]\n if len(a) == 0 or len(b) == 0 or len(c) == 0:\n continue\n s = 0\n s += abs(A - a.sum()) + (len(a) - 1) * 10\n s += abs(B - b.sum()) + (len(b) - 1) * 10\n s += abs(C - c.sum()) + (len(c) - 1) * 10\n ans = min(ans, s)\nprint(ans)\n', 'import itertools\nimport os\nimport sys\n\nif os.getenv("LOCAL"):\n sys.stdin = open("_in.txt", "r")\n\nsys.setrecursionlimit(10 ** 9)\nINF = float("inf")\nIINF = 10 ** 18\nMOD = 10 ** 9 + 7\n# MOD = 998244353\n\n\nN, A, B, C = list(map(int, sys.stdin.buffer.readline().split()))\nL = [int(sys.stdin.buffer.readline()) for _ in range(N)]\n\n\nans = INF\nfor choices in itertools.product(range(4), repeat=N):\n a = []\n b = []\n c = []\n\n for i, choice in enumerate(choices):\n if choice:\n [a, b, c][choice - 1].append(L[i])\n\n if a and b and c:\n mp = 0\n mp += (len(a) - 1) * 10 + abs(A - sum(a))\n mp += (len(b) - 1) * 10 + abs(B - sum(b))\n mp += (len(c) - 1) * 10 + abs(C - sum(c))\n ans = min(mp, ans)\nprint(ans)\n']
['Time Limit Exceeded', 'Accepted']
['s100340250', 's002431672']
[27376.0, 3064.0]
[2109.0, 281.0]
[997, 790]
p03111
u405256066
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from sys import stdin\nimport itertools\nN,A,B,C=[int(x) for x in stdin.readline().rstrip().split()]\ndata=[]\n\nfor i in range(N):\n data.append(int(input()))\ntarget=[A,B,C]\n\nans=0\n\nif A in data:\n data.remove(A)\n target.remove(A)\n\nif B in data:\n data.remove(B)\n target.remove(B)\n \nif C in data:\n data.remove(C)\n target.remove(C)\n\nif target==[]:\n print(ans)\n\nelse:\n for k in sorted(target):\n sa=float("inf")\n for l in range(1,len(data)):\n for j in itertools.combinations(data,l):\n if abs(k-sum(j)) < sa:\n sa= abs(k-sum(j))\n ansj=j\n if len(ansj)==1:\n ans+=sa\n else:\n ans=ans+sa+10*(len(ansj)-1)\n for m in ansj:\n data.remove(m)\n print(ans)', 'from sys import stdin\nimport itertools\n\ndef get_index(l,x):\n return [i for i, _x in enumerate(l) if _x == x]\n\nN,A,B,C=[int(x) for x in stdin.readline().rstrip().split()]\ndata=[]\nfor i in range(N):\n data.append(int(input()))\ntarget=[A,B,C]\n\nans=float("inf")\nfor j in (list(itertools.product(["none","A","B","C"],repeat=N))):\n if set(j) >= {"A","B","C"}:\n score=(j.count("A")-1)*10 + (j.count("B")-1)*10 + (j.count("C")-1)*10\n score_a=sum([data[k] for k in (get_index(j,"A"))])\n score_b=sum([data[l] for l in (get_index(j,"B"))])\n score_c=sum([data[m] for m in (get_index(j,"C"))])\n score=abs(A-score_a)+abs(B-score_b)+abs(C-score_c)+score\n if score < ans:\n ans=score\nprint(ans) ']
['Runtime Error', 'Accepted']
['s657468122', 's389018671']
[3064.0, 10996.0]
[19.0, 358.0]
[796, 741]
p03111
u416758623
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["N,A,B,C = map(int, input().split())\nls = [int(input()) for i in range(N)]\nINF = float('inf')\n\ndef dfs(cur, a,b,c):\n print(cur,a,b,c)\n if cur == N:\n print(abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF)\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+ls[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+ls[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+ls[cur])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))", 'N,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(N)]\nINF=10**9\n\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n ret0=dfs(cur+1,a,b,c)\n ret1=dfs(cur+1,a+l[cur],b,c)+10\n ret2=dfs(cur+1,a,b+l[cur],c)+10\n ret3=dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))']
['Wrong Answer', 'Accepted']
['s812480588', 's995128072']
[4976.0, 3064.0]
[354.0, 69.0]
[493, 376]
p03111
u417365712
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from collections import defaultdict\nfrom operator import itemgetter\n\nn, a, b, c, *L = map(int, open(0).read().split())\nL.sort()\nA = [a, b, c]\ndicts = [defaultdict(lambda: 10**5) for _ in range(3)]\nfor i in range(n-2):\n for x in combinations(enumerate(L), i+1):\n k = tuple(i for i, l in x)\n v = sum(l for i, l in x)\n for d, x in zip(dicts, A):\n d[k] = min(d[k], abs(x-v) + 10*i)\nscores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]\n\nans = 10**5\nfor p1, p2, p3 in permutations(range(3)):\n k1, v1 = scores[p1][0]\n k1 = set(k1)\n for k2, v2 in scores[p2]:\n k2 = set(k2)\n if len(k1 & k2) == 0:\n break\n for k3, v3 in scores[p3]:\n k3 = set(k3)\n if len(k1 & k3) + len(k2 & k3) == 0:\n break\n ans = min(ans, sum([v1, v2, v3]))\nprint(ans)', 'from collections import defaultdict\nfrom itertools import combinations, permutations\nfrom operator import itemgetter\nn, a, b, c, *L = map(int, open(0).read().split())\nL.sort()\nA = [a, b, c]\ndicts = [defaultdict(lambda: 10**5) for _ in range(3)]\nfor i in range(n-2):\n for x in combinations(enumerate(L), i+1):\n k = tuple(i for i, l in x)\n v = sum(l for i, l in x)\n for d, x in zip(dicts, A):\n d[k] = min(d[k], abs(x-v) + 10*i)\nscores = [sorted(d.items(), key=itemgetter(1)) for d in dicts]\n\nans = 10**5\nfor p1, p2, p3 in permutations(range(3)):\n k1, v1 = scores[p1][0]\n k1 = set(k1)\n for k2, v2 in scores[p2]:\n k2 = set(k2)\n if len(k1 & k2) == 0:\n break\n for k3, v3 in scores[p3]:\n k3 = set(k3)\n if len(k1 & k3) + len(k2 & k3) == 0:\n break\n ans = min(ans, sum([v1, v2, v3]))\nprint(ans)']
['Runtime Error', 'Accepted']
['s922400840', 's087283512']
[3316.0, 3436.0]
[21.0, 23.0]
[836, 884]
p03111
u422886513
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from itertools import product\n\nimport numpy as np\n\nN, A, B, C = (int(i) for i in input().split())\nl = []\n\nfor i in range(N):\n l.append(int(input()))\n\nl = np.array(l)\n\n###########\n\n\n\nmin_cost = 1e10\n\nfor i in product(np.arange(4), repeat=N):\n i = np.array(i)\n\n if(len(np.unique(i)) != 4):\n continue\n\n for_a = l[i == 0]\n for_b = l[i == 1]\n for_c = l[i == 2]\n\n A_diff = np.abs(np.sum(for_a) - A) + (len(for_a) - 1) * 10\n B_diff = np.abs(np.sum(for_b) - B) + (len(for_b) - 1) * 10\n C_diff = np.abs(np.sum(for_c) - C) + (len(for_c) - 1) * 10\n\n cost = A_diff + B_diff + C_diff\n\n if(cost < min_cost):\n min_cost = cost\n\nprint(min_cost)', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))\n']
['Wrong Answer', 'Accepted']
['s894912490', 's102365285']
[14452.0, 3064.0]
[2109.0, 72.0]
[778, 455]
p03111
u426397594
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\nl = [input() for i in range(N)]\nINF = 10 ** 9\n\ndef ans(cur,a,b,c):\n \n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c) > 0 else INF\n \n ret0 = ans(cur + 1,a,b,c) \n ret1 = ans(cur + 1,a + l[cur],b,c) + 10\n ret2 = ans(cur + 1,a,b + l[cur],c) + 10\n ret3 = ans(cur + 1,a,b,c + l[cur]) + 10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(ans(0,0,0,0))\n\n\n\n\n\n', 'N,A,B,C = map(int,input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef ans(cur,a,b,c):\n \n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a,b,c) > 0 else INF\n \n ret0 = ans(cur + 1,a,b,c) \n ret1 = ans(cur + 1,a + l[cur],b,c) + 10\n ret2 = ans(cur + 1,a,b + l[cur],c) + 10\n ret3 = ans(cur + 1,a,b,c + l[cur]) + 10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(ans(0,0,0,0))\n\n\n\n\n\n']
['Runtime Error', 'Accepted']
['s375806656', 's760788411']
[3064.0, 3064.0]
[20.0, 71.0]
[433, 438]
p03111
u437638594
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF\n \n \n ret0 = dfs(cur + 1, A, B, C)\n \n ret1 = dfs(cur + 1, A + l[cur], B, C) + 10\n \n ret2 = dfs(cur + 1, A, B + l[cur], C) + 10\n \n ret3 = dfs(cur + 1, A, B, C + l[cur]) + 10\n \n return min(ret0, ret1, ret2, ret3)\n \nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF\n \n \n ret0 = dfs(cur + 1, A, B, C)\n \n ret1 = dfs(cur + 1, A + l[cur], B, C) + 10\n \n ret2 = dfs(cur + 1, A, B + l[cur], C) + 10\n \n ret3 = dfs(cur + 1, A, B, C + l[cur]) + 10\n \n return min(ret0, ret1, ret2, ret3)\n \nprint(defs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF\n \n \n ret0 = dfs(cur + 1, a, b, c)\n \n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n \n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n \n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n \n return min(ret0, ret1, ret2, ret3)\n \nprint(dfs(0, 0, 0, 0))']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s011897607', 's395798836', 's513713890']
[3064.0, 3064.0, 3064.0]
[76.0, 17.0, 76.0]
[528, 529, 528]
p03111
u466331465
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['def rec (i,a,b,c):\n if i==N:\n if a==0 and b==0 and c==0:\n return INF\n else:\n return abs(a-A)+abs(b-B)+abs(c-C)\n res = rec(i+1,a,b,c)\n \n res = min(res,rec(i+1,a+L[i],b,c)+(10 if a>0 else 0))\n res = min(res,rec(i+1,a,b+L[i],c)+(10 if b>0 else 0))\n res = min(res,rec(i+1,a,b,c+L[i])+(10 if c>0 else 0))\n \n return res\nN,A,B,C = list(map(int,input().split()))\nL = [int(input()) for _ in range(N)]\nprint(rec(0,0,0,0))', 'def rec (i,a,b,c):\n if i==N:\n if a==0 or b==0 or c==0:\n return INF\n else:\n return abs(a-A)+abs(b-B)+abs(c-C)\n res = rec(i+1,a,b,c)\n \n res = min(res,rec(i+1,a+L[i],b,c)+(10 if a>0 else 0))\n res = min(res,rec(i+1,a,b+L[i],c)+(10 if b>0 else 0))\n res = min(res,rec(i+1,a,b,c+L[i])+(10 if c>0 else 0))\n \n return res\nN,A,B,C = list(map(int,input().split()))\nINF=10**8\nL = [int(input()) for _ in range(N)]\nprint(rec(0,0,0,0))']
['Runtime Error', 'Accepted']
['s601017116', 's951925498']
[3064.0, 3064.0]
[18.0, 73.0]
[471, 479]
p03111
u476124554
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from itertools import combinations\nN,A,B,C=map(int,input().split())\nl = []\nfor i in range(N):\n l.append(int(input()))\ninput_l = list(map(list,combinations(l,3)))\nexcept_l = [l[:] for _ in range(len(input_l))]\nfor i in range(len(input_l)):\n except_l[i].remove(input_l[i][0])\n except_l[i].remove(input_l[i][1])\n except_l[i].remove(input_l[i][2])\nprint(input_l)\nprint(except_l)', 'n,a,b,c = list(map(int,input().split()))\nl = []\nans = []\nfor i in range(n):\n l.append(int(input()))\n\ndef f(x,y,z,arr,cnt):\n global a\n global b\n global c\n global ans\n if arr:\n f(x + arr[0], y, z, arr[1:],cnt+1)\n f(x, y + arr[0], z, arr[1:],cnt+1)\n f(x, y, z + arr[0], arr[1:],cnt+1)\n f(x, y, z, arr[1:],cnt)\n else:\n if x > 0 and y > 0 and z > 0:\n ans.append(abs(a-x) + abs(b-y) + abs(c-z) + 10 * (cnt - 3))\nf(0,0,0,l,0)\nprint(min(ans))']
['Wrong Answer', 'Accepted']
['s176609432', 's411541484']
[3064.0, 4992.0]
[18.0, 67.0]
[386, 501]
p03111
u476604182
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nls = [int(input()) for i in range(N)]\n\ndef dfs(cur, a, b, c):\n if cur==N:\n return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else 10**9\n ret0 = dfs(cur+1, a+ls[cur], b, c)\n ret1 = dfs(cur+1, a, b+ls[cur], c)\n ret2 = dfs(cur+1, a, b, c+ls[cur])\n ret3 = dfs(cur+1, a, b, c)\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nls = [int(input) for i in range(N)]\n\ndef dfs(cur, a, b, c):\n if cur==N:\n return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else 10**9\n ret0 = dfs(cur+1, a+ls[cur], b, c)\n ret1 = dfs(cur+1, a, b+ls[cur], c)\n ret2 = dfs(cur+1, a, b, c+ls[cur])\n ret3 = dfs(cur+1, a, b, c)\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0,0,0,0))', "N, A, B, C, *L = map(int, open('0').read().split())\nans = float('inf')\nfor i in range(4**N):\n a = 0\n b = 0\n c = 0\n m = 0\n for j in range(N):\n if i%4==0:\n if a!=0:\n m += 10\n a += L[j]\n elif i%4==1:\n if b!=0:\n m += 10\n b += L[j]\n elif i%4==2:\n if c!=0:\n m += 10\n c += L[j]\n i //= 4\n if a==0 or b==0 or c==0:\n continue\n ans = min(ans, m+abs(A-a)+abs(B-b)+abs(C-c))\nprint(ans)", "N, A, B, C, *L = map(int, open(0).read().split())\nans = float('inf')\nfor i in range(4**N):\n a = 0\n b = 0\n c = 0\n m = 0\n for j in range(N):\n if i%4==0:\n if a!=0:\n m += 10\n a += L[j]\n elif i%4==1:\n if b!=0:\n m += 10\n b += L[j]\n elif i%4==2:\n if c!=0:\n m += 10\n c += L[j]\n i //= 4\n if a==0 or b==0 or c==0:\n continue\n ans = min(ans, m+abs(A-a)+abs(B-b)+abs(C-c))\nprint(ans)"]
['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted']
['s284167471', 's359326921', 's544262769', 's765451230']
[3064.0, 3064.0, 3064.0, 3064.0]
[66.0, 18.0, 17.0, 326.0]
[378, 376, 445, 443]
p03111
u492030100
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['\nN, A, B, C = map(int, input().split())\nL = [int(input()) for i in range(N)]\n\nINF = 10 ** 9\n\n\ndef dfs(cursor, a, b, c): \n if cursor == N: \n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n \n # dfs(0,0,0)\n \n \n \n \n\n \n \n no_compound_pattern = dfs(cursor, a, b, c)\n compound_a_pattern = dfs(cursor, a + L[cursor], b, c)\n compound_b_pattern = dfs(cursor, a, b + L[cursor], c)\n compound_c_pattern = dfs(cursor, a, b, c + L[cursor])\n\n \n \n return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)\n\n\nprint(dfs(0, 0, 0, 0))\n', '\nN, A, B, C = map(int, input().split())\nL = [int(input()) for i in range(N)]\n\nINF = 10 ** 9\n\n\ndef dfs(cursor, a, b, c): \n if cursor == N: \n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n \n # dfs(0,0,0)\n \n \n \n \n\n \n \n no_compound_pattern = dfs(cursor, a, b, c)\n compound_a_pattern = dfs(cursor, a+L[cursor], b, c)\n compound_b_pattern = dfs(cursor, a, b+L[cursor], c)\n compound_c_pattern = dfs(cursor, a, b, c+L[cursor])\n\n \n \n return min(no_compound_pattern,compound_a_pattern,compound_b_pattern,compound_c_pattern)\n\n', '\n\nN, A, B, C = map(int, input().split())\nL = [int(input()) for i in range(N)]\n\nINF = 10 ** 9\n\n\ndef dfs(cursor, a, b, c): \n if cursor == N: \n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n \n # dfs(0,0,0)\n \n \n \n \n\n \n \n no_compound_pattern = dfs(cursor+1, a, b, c)\n compound_a_pattern = dfs(cursor+1, a + L[cursor], b, c)+10\n compound_b_pattern = dfs(cursor+1, a, b + L[cursor], c)+10\n compound_c_pattern = dfs(cursor+1, a, b, c + L[cursor])+10\n\n \n \n return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)\n\n\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s159461881', 's420308422', 's363033006']
[3940.0, 3064.0, 3064.0]
[83.0, 17.0, 72.0]
[1660, 1627, 1678]
p03111
u503228842
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C)-30 if min(a,b,c) > 0 else 10**9\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)\n ret2 = dfs(cur+1,a,b+l[cur],c)\n ret3 = dfs(cur+1,a,b,c+l[cur])\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))', 'N,A,B,C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C)-30 if min(a,b,c) > 0 else 10**9\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c) + 10\n ret2 = dfs(cur+1,a,b+l[cur],c) + 10\n ret3 = dfs(cur+1,a,b,c+l[cur]) + 10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))']
['Wrong Answer', 'Accepted']
['s058181640', 's520316014']
[3064.0, 3064.0]
[70.0, 69.0]
[376, 391]
p03111
u513844316
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=map(int,input().split())\n\nl=[int(input()) for i in range(N)]\n\nINF=3000\n\ndef mp(co,a,b,c):\n if co==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n\n ret0=mp(co+1,a,b,c)\n ret1=mp(co+1,a+1,b,c)+10\n ret2=mp(co+1,a,b+1,c)+10\n ret3=mp(co+1,a,b,c+1)+10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(mp(0,0,0,0))\nN,A,B,C=map(int,input().split())\n\nl=[int(input()) for i in range(N)]\n\nINF=3000\n\ndef mp(co,a,b,c):\n if co==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n\n ret0=mp(co+1,a,b,c)\n ret1=mp(co+1,a+1,b,c)+10\n ret2=mp(co+1,a,b+1,c)+10\n ret3=mp(co+1,a,b,c+1)+10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(mp(0,0,0,0))\n', 'N,A,B,C=map(int,input().split())\n\nl=[int(input()) for i in range(N)]\n\nINF=3000\n\ndef mp(c,a,b,c):\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n\n ret0=mp(c+1,a,b,c)\n ret1=mp(c+1,a+1,b,c)+10\n ret2=mp(c+1,a,b+1,c)+10\n ret3=mp(c+1,a,b,c+1)+10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(mp(0,0,0,0))\n', 'N,A,B,C=map(int,input().split())\n\nl=[int(input()) for i in range(N)]\n\nINF=3000\n\ndef mp(c,a,b,c):\n if c==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n\n ret0=mp(c+1,a,b,c)\n ret1=mp(c+1,a+1,b,c)+10\n ret2=mp(c+1,a,b+1,c)+10\n ret3=mp(c+1,a,b,c+1)+10\n\n return min(ret0,ret1,ret2,ret3)\n\nprint(mp(0,0,0,0))\n', 'N,A,B,C=map(int,input().split())\n\nl=[int(input()) for i in range(N)]\n\ninf=3000\n\ndef mp(g,a,b,c,):\n if g==N:\n return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c)>0 else inf\n\n l0=mp(g+1,a+l[g],b,c)+10\n l1=mp(g+1,a,b+l[g],c)+10\n l2=mp(g+1,a,b,c+l[g])+10\n l3=mp(g+1,a,b,c)\n \n return min(l0,l1,l2,l3)\n\nprint(mp(0,0,0,0))\n\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s095905604', 's482494250', 's527581422', 's271260861']
[3064.0, 3064.0, 3188.0, 3064.0]
[69.0, 17.0, 18.0, 71.0]
[702, 328, 345, 344]
p03111
u514118270
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\ndef s(): return input()\ndef i(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef L(): return list(map(int,input().split()))\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nINF = 10**9\nmod = 10**9+7\n\nN,A,B,C = I()\nl = [i() for _ in range(N)]\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else INF\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))', 'import sys\nimport math\nimport itertools\nimport bisect\nfrom copy import copy\nfrom collections import deque,Counter\nfrom decimal import Decimal\ndef s(): return input()\ndef i(): return int(input())\ndef S(): return input().split()\ndef I(): return map(int,input().split())\ndef L(): return list(map(int,input().split()))\ndef l(): return list(map(int,input().split()))\ndef lcm(a,b): return a*b//math.gcd(a,b)\nsys.setrecursionlimit(10 ** 9)\nINF = 10**9\nmod = 10**9+7\n\nN,A,B,C = I()\nl = [i() for _ in range(N)]\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else INF\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\nprint(dfs(0,0,0,0))']
['Wrong Answer', 'Accepted']
['s582350606', 's036770378']
[10028.0, 10040.0]
[35.0, 72.0]
[828, 808]
p03111
u518042385
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,a,b,c=map(int,input().split())\nl=[]\nfor i in range(n):\n l.append(int(input()))\nlist2=[]\ns=0\nfor i in range(4):\n list=[0,0,0,0]\n list[i]+=l[0]\n if i!=3:\n s+=10\n for j in range(4):\n list[j]+=l[1]\n if j!=3:\n s+=10\n for o in range(4):\n list[o]+=l[2]\n if o!=3:\n s+=10\n for p in range(4):\n list[p]+=l[3]\n if p!=3:\n s+=10\n for u in range(4):\n list[u]+=l[4]\n if u!=3:\n s+=10 \n for t in range(4):\n list[t]+=l[5]\n if t!=3:\n s+=10\n for r in range(4):\n list[r]+=l[6]\n if r!=3:\n s+=10\n for q in range(4):\n list[q]+=l[7]\n if q!=3:\n s+=10\n if list[0]==0 or list[1]==0 or list[2]==0:\n pass\n else:\n list2.append(abs(a-list[0])+abs(b-list[1])+abs(c-list[2]))\nprint(min(list2))\n \n \n\n \n\n \n \n\n\n ', 'n,a,b,c=map(int,input().split())\nl=[]\nfor i in range(n):\n l.append(int(input()))\nbit=[]\nfor i in range(1,4**n):\n bl=[]\n num=i\n while num!=0:\n bl.append(num%4)\n num=num//4\n while len(bl)<n:\n bl.append(0)\n bit.append(bl)\nmin=10**10\nfor i in bit:\n bit1=i\n l1=0\n l2=0\n l3=0\n c1,c2,c3=0,0,0\n for j in range(n):\n if bit1[j]==0:\n l1+=l[j]\n c1+=1\n elif bit1[j]==1:\n l2+=l[j]\n c2+=1\n elif bit1[j]==2: \n l3+=l[j]\n c3+=1\n if l1==0 or l2==0 or l3==0:\n pass\n else:\n ans=0\n ans+=(c1+c2+c3-3)*10\n ans+=abs(a-l1)+abs(b-l2)+abs(c-l3)\n if min>ans:\n min=ans\nprint(min)']
['Runtime Error', 'Accepted']
['s246828266', 's939195571']
[3440.0, 12788.0]
[33.0, 436.0]
[1288, 631]
p03111
u529012223
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int,input().split())\nl = [int(input()) for i in range(N)]\ninf = 10**9\n\ndef magic(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a - A) + abs(b - B) + abs (c - C) - 30\n else:\n return inf\n \n ret0 = magic(cur+1, a, b, c)\n ret1 = magic(cur+1, a+l[cur], b, c) + 10\n ret2 = magic(cur+1, a, b+l[cur], c) + 10\n ret3 = magic(cur+1, a, b, c+l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(magic(ret0, ret1, ret2, ret3)', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n \n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s317720686', 's765089276']
[3064.0, 3064.0]
[18.0, 68.0]
[506, 457]
p03111
u543954314
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n, a, b, c = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ncnt = 0\nfor k in [a,b,c]:\n ans = 0\n for i in range(1, 257):\n s = 0\n for j in range(n):\n if i & 2**j:\n if s > 0:\n s += 10\n s += l[j]\n v = abs(k - s)\n if v < ans:\n ans = v\n x = i\n cnt += ans\n for j in range(n):\n if x & 2**j:\n l[j] = 0\nprint(cnt)', 'n,a,b,c = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ndef dfs(k,p,q,r):\n if k == n:\n if min(a,b,c) > 0:\n return abs(p-a)+abs(q-b)+abs(r-c)-30\n else:\n return 10**5\n t1 = dfs(k+1,p,q,r)\n t2 = dfs(k+1,p+l[k],q,r)+10\n t3 = dfs(k+1,p,q+l[k],r)+10\n t2 = dfs(k+1,p,q,r+l[k])+10\n return min(t1,t2,t3,t4)\n\nprint(dfs(0,0,0,0))', 'n, a, b, c = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ncnt = 0\nfor k in [a,b,c]:\n ans = 100000\n for i in range(1, 2**n+1):\n s = 0\n for j in range(n):\n if i & 2**j:\n if s > 0:\n s += 10\n s += l[j]\n v = abs(k - s)\n if v < ans:\n ans = v\n mast = i\n cnt += ans\n for j in range(n):\n if mast & 2**j:\n l[j] = 0\nprint(cnt)', 'n, a, b, c = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ncnt = 0\nfor k in [a,b,c]:\n ans = 0\n for i in range(1, 257):\n s = 0\n for j in range(7):\n if i & 2**j:\n if s > 0:\n s += 10\n s += l[j]\n v = abs(k - s)\n if v < ans:\n ans = v\n x = i\n cnt += ans\n for j in range(7):\n if x & 2**j:\n l[j] = 0\nprint(cnt)', 'n,a,b,c = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ndef dfs(k,p,q,r):\n if k == n:\n if min(p,q,r) > 0:\n return abs(p-a)+abs(q-b)+abs(r-c)-30\n else:\n return 10**7\n t1 = dfs(k+1,p,q,r)\n t2 = dfs(k+1,p+l[k],q,r)+10\n t3 = dfs(k+1,p,q+l[k],r)+10\n t4 = dfs(k+1,p,q,r+l[k])+10\n return min(t1,t2,t3,t4)\n\nprint(dfs(0,0,0,0))\n']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s155924495', 's722532422', 's728905701', 's888206051', 's731127404']
[3064.0, 3064.0, 3188.0, 3064.0, 3064.0]
[18.0, 18.0, 23.0, 18.0, 71.0]
[459, 357, 473, 459, 358]
p03111
u545368057
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import numpy as np\n\nN, A, B, C = map(int,input().split())\ngoals = [A,B,C]\nfor i in range(N):\n ls.append(int(input()))\n\n\n# ls = [300,333,400,444,500,555,600,666]\n\n# ls = [98, 40,30,21,80]\n\ndef count(x,ls):\n try:\n x.index(0)\n x.index(1)\n x.index(2) \n except:\n return False\n A = np.zeros(len(goals))\n for i,l in enumerate(ls):\n add_ind = x[i]\n if add_ind==3:\n pass\n else:\n A[add_ind] += l\n combine_MP = 0\n for i in range(3):\n combine_MP += 10*(x.count(i)-1)\n return A, combine_MP\n \n \nscore_min = 100000\nfor N in range(4**8):\n x = []\n for j in range(len(ls)):\n x.append(N % 4)\n N = N // 4 \n try:\n A, combine_MP = count(x,ls)\n score = np.abs(A-np.array(goals)).sum() + combine_MP\n if score_min >= score:\n score_min = score\n except:\n pass\nprint(score_min)', 'import numpy as np\n\nN, A, B, C = map(int,input().split())\ngoals = [A,B,C]\nfor i in range(N):\n ls.append(int(input()))\n\ndef count(x,ls):\n try:\n x.index(0)\n x.index(1)\n x.index(2) \n except:\n return False\n A = np.zeros(len(goals))\n for i,l in enumerate(ls):\n add_ind = x[i]\n if add_ind==3:\n pass\n else:\n A[add_ind] += l\n combine_MP = 0\n for i in range(3):\n combine_MP += 10*(x.count(i)-1)\n return A, combine_MP\n \n \nscore_min = 100000\nfor N in range(4**8):\n x = []\n for j in range(len(ls)):\n x.append(N % 4)\n N = N // 4 \n try:\n A, combine_MP = count(x,ls)\n score = np.abs(A-np.array(goals)).sum() + combine_MP\n if score_min >= score:\n score_min = score\n except:\n pass\nprint(score_min)', 'import numpy as np\n\nN, A, B, C = map(int,input().split())\ngoals = [A,B,C]\nfor i in range(N):\n ls.append(int(input()))\n\n\n# ls = [300,333,400,444,500,555,600,666]\n\n# ls = [98, 40,30,21,80]\n\ndef count(x,ls):\n try:\n x.index(0)\n x.index(1)\n x.index(2) \n except:\n return False\n A = np.zeros(len(goals))\n for i,l in enumerate(ls):\n add_ind = x[i]\n if add_ind==3:\n pass\n else:\n A[add_ind] += l\n combine_MP = 0\n for i in range(3):\n combine_MP += 10*(x.count(i)-1)\n return A, combine_MP\n \n \nscore_min = 100000\nfor N in range(4**8):\n x = []\n for j in range(len(ls)):\n x.append(N % 4)\n N = N // 4 \n try:\n A, combine_MP = count(x,ls)\n score = np.abs(A-np.array(goals)).sum() + combine_MP\n if score_min >= score:\n score_min = score\n except:\n pass\nprint(score_min)', 'import numpy as np\n\nN, A, B, C = map(int,input().split())\ngoals = [A,B,C]\nls = []\nfor i in range(N):\n ls.append(int(input()))\n\n\n# ls = [300,333,400,444,500,555,600,666]\n\n# ls = [98, 40,30,21,80]\n\ndef count(x,ls):\n try:\n x.index(0)\n x.index(1)\n x.index(2) \n except:\n return False\n A = np.zeros(len(goals))\n for i,l in enumerate(ls):\n add_ind = x[i]\n if add_ind==3:\n pass\n else:\n A[add_ind] += l\n combine_MP = 0\n for i in range(3):\n combine_MP += 10*(x.count(i)-1)\n return A, combine_MP\n \n \nscore_min = 100000\nfor N in range(4**8):\n x = []\n for j in range(len(ls)):\n x.append(N % 4)\n N = N // 4 \n try:\n A, combine_MP = count(x,ls)\n score = np.abs(A-np.array(goals)).sum() + combine_MP\n if score_min >= score:\n score_min = score\n except:\n pass\nprint(score_min)', '\n\n\nN,A,B,C = map(int, input().split())\nls = [int(input()) for i in range(N)]\n\nimport sys\nsys.setrecursionlimit(100000)\n\n\nminMP = 10**9 + 7\ndef dfs(i,MP,a,b,c):\n global minMP\n \n if i+1 >= N:\n if a>0 and b>0 and c>0:\n cnt = MP + abs(A-a)+abs(B-b)+abs(C-c) - 30 \n minMP = min(cnt,minMP)\n return 0\n l = ls[i+1]\n \n dfs(i+1,MP,a,b,c) \n dfs(i+1,MP+10,a+l,b,c) \n dfs(i+1,MP+10,a,b+l,c) \n dfs(i+1,MP+10,a,b,c+l) \n\ndfs(-1,0,0,0,0)\nprint(minMP)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s021865922', 's365318351', 's401464926', 's964969163', 's758244351']
[13164.0, 12516.0, 12516.0, 14516.0, 3064.0]
[153.0, 151.0, 149.0, 1983.0, 68.0]
[976, 860, 976, 984, 819]
p03111
u548303713
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,A,B,C=map(int,input().split())\nbam=[]\nfor i in range(n):\n bam.append(int(input()))\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == n: \n print(str(cur)+" "+str(a)+" "+str(b)+" "+str(c))\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF \n \n \n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + bam[cur], b, c) + 10 \n ret2 = dfs(cur + 1, a, b + bam[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + bam[cur]) + 10\n print(min(ret0, ret1, ret2, ret3))\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'n,A,B,C=map(int,input().split())\nbam=[]\nfor i in range(n):\n bam.append(int(input()))\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == n: \n #print(str(cur)+" "+str(a)+" "+str(b)+" "+str(c))\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF \n \n \n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + bam[cur], b, c) + 10 \n ret2 = dfs(cur + 1, a, b + bam[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + bam[cur]) + 10\n #print(min(ret0, ret1, ret2, ret3))\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Wrong Answer', 'Accepted']
['s948201087', 's330380223']
[4208.0, 3188.0]
[205.0, 70.0]
[977, 979]
p03111
u552357043
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int, input().split())\nl = list(map(int, input().split()))\ndef dfs(cur,a,b,c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n return 10**9\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a + l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b + l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c + l[cur]) + 10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N,A,B,C = map(int, input().split())\nl = [int(input()) for i in range(N) ]\ndef dfs(cur,a,b,c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n return 10**9\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a + l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b + l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c + l[cur]) + 10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s400330011', 's732782604']
[3064.0, 3064.0]
[18.0, 71.0]
[465, 467]
p03111
u556225812
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(C-C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a+l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b+l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c+l[cur]) + 10\n return min(rest0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a+l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b+l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c+l[cur]) + 10\n return min(rest0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a+l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b+l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c+l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s769998675', 's898690016', 's638263903']
[3064.0, 3064.0, 3064.0]
[18.0, 19.0, 70.0]
[434, 434, 433]
p03111
u556326496
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['many, A, B, C = map(int, input().split())\nbamboos = [int(input()) for i in range(many)]\n\n\n\n\n\n\n\ninfinity = 1e10\n\ndef dfs(depth, a, b, c):\n if depth == many:\n \n if min(a, b, c) > 0:\n \n \n \n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n ret0 = dfs(depth+1, a, b, c)\n ret1 = dfs(depth+1, a+bamboos[depth], b, c) + 10\n ret2 = dfs(depth+1, a, b+bamboos[depth], c) + 10\n ret3 = dfs(depth+1, a, b, c+bamboos[depth]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n', 'many, A, B, C = map(int, input().split())\nbamboos = [int(input()) for i in range(many)]\n\n\n\n\n\n\n\ninfinity = 1e10\n\ndef dfs(depth, a, b, c):\n if depth == many:\n \n if min(a, b, c) > 0:\n \n \n \n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n return infinity\n else:\n ret0 = dfs(depth+1, a, b, c)\n ret1 = dfs(depth+1, a+bamboos[depth], b, c) + 10\n ret2 = dfs(depth+1, a, b+bamboos[depth], c) + 10\n ret3 = dfs(depth+1, a, b, c+bamboos[depth]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Accepted']
['s731145308', 's418166132']
[3064.0, 3064.0]
[19.0, 75.0]
[1108, 1150]
p03111
u572142121
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["N,a,b,c=map(int,input().split())\nL=[int(input()) for i in range(N)]\nimport itertools \nans=300000\nfor i in itertools.product('ABCD',repeat=N):\n cst=0\n A=[]\n B=[]\n C=[]\n for j in range(N):\n if i[j]=='A':\n A.append(L[j])\n elif i[j]=='B':\n B.append(L[j]) \n elif i[j]=='C':\n C.append(L[j])\n if len(A)>0 and len(B)>0 and len(C)>0:\n if len(A)>1:\n cst+=len(A)-1\n cst+=abs(sum(A)-a)\n if len(B)>1:\n cst+=len(B)-1\n cst+=abs(sum(B)-b)\n if len(C)>1:\n cst+=len(C)-1\n cst+=abs(sum(C)-c)\n ans=min(ans,cst)\n \nprint(ans)\n ", "N,a,b,c=map(int,input().split())\nL=[int(input()) for i in range(N)]\nimport itertools \nans=300000\nfor i in itertools.product('ABCD',repeat=N):\n cst=0\n A=[]\n B=[]\n C=[]\n for j in range(N):\n if i[j]=='A':\n A.append(L[j])\n elif i[j]=='B':\n B.append(L[j]) \n elif i[j]=='C':\n C.append(L[j])\n if len(A)>0 and len(B)>0 and len(C)>0:\n if len(A)>1:\n cst+=(len(A)-1)*10\n cst+=abs(sum(A)-a)\n if len(B)>1:\n cst+=(len(B)-1)*10\n cst+=abs(sum(B)-b)\n if len(C)>1:\n cst+=(len(C)-1)*10\n cst+=abs(sum(C)-c)\n ans=min(ans,cst)\n \nprint(ans)\n "]
['Wrong Answer', 'Accepted']
['s708946144', 's694263108']
[3064.0, 3064.0]
[315.0, 328.0]
[572, 587]
p03111
u576432509
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['l=[]\n\ndef detain(n,a,b,c,l):\n \n n,a,b,c=map(int,input().split())\n for i in range(n):\n li=int(input())\n l.append(li)\n return\n\n\ndetain(n,a,b,c,l)\nd=[a,b,c]\nd.sort()\n\nmpmin=sum(l)*4+len(l)*10\nfor i in range(4**n):\n k=[]\n kj=i%4\n k.append(kj)\n b=int((i-kj)/4)\n l0=[]\n l1=[]\n l2=[]\n l3=[]\n if kj==0:\n l0.append(l[0])\n elif kj==1:\n l1.append(l[0])\n elif kj==2:\n l2.append(l[0])\n elif kj==3:\n l3.append(l[0])\n \n for j in range(n-1):\n kj=b%4\n k.append(kj)\n b=int((b-kj)/4)\n if kj==0:\n l0.append(l[j+1])\n elif kj==1:\n l1.append(l[j+1])\n elif kj==2:\n l2.append(l[j+1])\n elif kj==3:\n l3.append(l[j+1])\n mp=0\n if len(l0)>=1:\n mp=mp+(len(l0)-1)*10\n if len(l1)>=1:\n mp=mp+(len(l1)-1)*10\n if len(l2)>=1:\n mp=mp+(len(l2)-1)*10\n ls=[]\n ls=[sum(l0),sum(l1),sum(l2)]\n ls.sort()\n mp=mp+abs(d[0]-ls[0])+abs(d[1]-ls[1])+abs(d[2]-ls[2]) \n if mpmin>mp and len(l0)>=1 and len(l1)>=1 and len(l2)>=1:\n mpmin=mp\nprint(mpmin) \n ', '\nn,a,b,c=map(int,input().split())\nl=[0]*n\nfor i in range(n):\n l[i]=int(input())\n\ninf=10**9\n\ndef dfs(cur,aa,bb,cc):\n if cur==n:\n if min(aa,bb,cc)>0:\n return abs(a-aa)+abs(b-bb)+abs(c-cc)-30\n else:\n return inf\n ret0=dfs(cur+1,aa,bb,cc)\n ret1=dfs(cur+1,aa+l[cur],bb,cc)+10\n ret2=dfs(cur+1,aa,bb+l[cur],cc)+10\n ret3=dfs(cur+1,aa,bb,cc+l[cur])+10\n# print(cur,l[cur],aa,bb,cc,ret0,ret1,ret2,ret3)\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0)) \n ']
['Runtime Error', 'Accepted']
['s286323641', 's101518942']
[3192.0, 3064.0]
[18.0, 76.0]
[1164, 510]
p03111
u578489732
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['# -*- coding: utf-8 -*-\nimport sys\n# ----------------------------------------------------------------\n# Use Solve Function\n\ndef solve(lines):\n def dfs(depth, l):\n if depth == 0:\n calc(l)\n return\n for i in range(4):\n dfs( depth - 1, l + str(i) )\n\n def calc(l):\n res = 0\n if not \'1\' in l or not \'2\' in l or not \'3\' in l:\n return\n aa = [[] for i in range(3)]\n for i,x in enumerate(list(l)):\n x = int(x)\n if x == 3:\n continue\n take = NLIST[i]\n aa[x].append(take)\n for i, a in enumerate(aa):\n if len(a) > 1:\n res += 10 * (len(a) - 1)\n res += abs(ABC[i] - sum(a))\n RESULT.append(res)\n\n\n\n\n RESULT = []\n N,A,B,C = map(int, lines.pop(0).split(\' \'))\n ABC = [A,B,C]\n NLIST = []\n for i in range(N):\n NLIST.append(int(lines.pop(0)))\n dfs(N, "")\n print(min(RESULT))\n\nlines = [x.strip() for x in sys.stdin.readlines()]\n\n#\n# solve !!\n#\nsolve(lines)', '# -*- coding: utf-8 -*-\nimport sys\n# ----------------------------------------------------------------\n# Use Solve Function\n\ndef solve(lines):\n def dfs(depth, l):\n if depth == 0:\n calc(l)\n return\n for i in range(4):\n dfs( depth - 1, l + str(i) )\n\n def calc(l):\n res = 0\n if not \'0\' in l or not \'1\' in l or not \'2\' in l:\n return\n aa = [[] for i in range(3)]\n for i,x in enumerate(list(l)):\n x = int(x)\n if x == 3:\n continue\n take = NLIST[i]\n aa[x].append(take)\n for i, a in enumerate(aa):\n if len(a) > 1:\n res += 10 * (len(a) - 1)\n res += abs(ABC[i] - sum(a))\n RESULT.append(res)\n\n\n\n\n RESULT = []\n N,A,B,C = map(int, lines.pop(0).split(\' \'))\n ABC = [A,B,C]\n NLIST = []\n for i in range(N):\n NLIST.append(int(lines.pop(0)))\n dfs(N, "")\n print(min(RESULT))\n \nlines = [x.strip() for x in sys.stdin.readlines()]\n\n#\n# solve !!\n#\nsolve(lines)']
['Wrong Answer', 'Accepted']
['s194577642', 's479385950']
[4996.0, 5008.0]
[377.0, 388.0]
[1062, 1066]
p03111
u580697892
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['#coding: utf-8\nimport numpy as np\n\nN, A, B, C = map(int, input().split())\nbumboo = np.array([int(input()) for _ in range(N)])\nmagic = 0\nfor i in [A, B, C]:\n bumboo_diff = bumboo - i\n bumboo_diff = np.where(bumboo_diff >= 0)\n if np.sum(bumboo_diff) >= 2:\n magic += 10\n else:\n magic += np.min(bumboo_diff)\nprint(magic)', '#coding: utf-8\nimport numpy as np\n\nN, A, B, C = map(int, input().split())\nbumboo = np.array([int(input()) for _ in range(N)])\nmagic = 0\nfor i in [A, B, C]:\n bumboo_diff = bumboo - i\n bumboo_diff = np.where(bumboo_diff >= 0)\n if np.sum(bumboo_diff) == 2:\n magic += 10\n else:\n magic += np.min(bumboo_diff)\nprint(magic)', "# coding: utf-8\nimport sys\nsys.setrecursionlimit(10**9)\ndef Base_10_to_n(X, n):\n X_dumy = X\n out = ''\n while X_dumy>0:\n out = str(X_dumy%n)+out\n X_dumy = int(X_dumy/n)\n return out\nN, A, B, C = map(int, input().split())\nL = []\nfor i in range(N):\n L.append(int(input()))\n# L.sort()\ndef dfs(cnt, a, b, c):\n if cnt == N:\n return abs(A - a) + abs(B - b) + abs(C - c) - 30 if min(a,b,c) > 0 else 10**9\n r0 = dfs(cnt+1, a, b, c)\n r1 = dfs(cnt+1, a+L[cnt], b, c) + 10\n r2 = dfs(cnt+1, a, b+L[cnt], c) + 10\n r3 = dfs(cnt+1, a, b, c+L[cnt]) + 10\n return min(r0, r1, r2, r3)\n \nprint(dfs(0,0,0,0))"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s159538611', 's357924251', 's805846705']
[12504.0, 12504.0, 3064.0]
[150.0, 149.0, 75.0]
[342, 342, 642]
p03111
u584174687
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["\nnow_ans = 100000\n\n\ndef kotae(A, a_tree, a_tree_sum):\n ans = (a_tree - 1) * 10 + abs(a_tree_sum - A)\n if a_tree == 0:\n ans = 100000\n return ans\n\ndef calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum):\n global now_ans\n ans = 0\n ans += kotae(A, a_tree, a_tree_sum)\n ans += kotae(B, b_tree, b_tree_sum)\n ans += kotae(C, c_tree, c_tree_sum)\n if ans < now_ans:\n now_ans = ans\n\ndef calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index, a_tree_sum, b_tree_sum, c_tree_sum ):\n if a_tree_sum >= A and b_tree_sum >= B and c_tree_sum >= C:\n calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)\n return\n if index == len(tree_data) - 1 or tree_data[i + 1] <= 10:\n calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)\n return\n if a_tree_sum < A:\n calc_data(tree_data, A, B, C, a_tree + 1, b_tree, c_tree, index + 1, a_tree_sum + tree_data[index + 1], b_tree_sum, c_tree_sum)\n if b_tree_sum < B:\n calc_data(tree_data, A, B, C, a_tree, b_tree + 1, c_tree, index + 1, a_tree_sum, b_tree_sum + tree_data[index + 1], c_tree_sum)\n\n if c_tree_sum < C:\n calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree + 1, index + 1, a_tree_sum, b_tree_sum, c_tree_sum + tree_data[index + 1])\n\n calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index + 1, a_tree_sum, b_tree_sum, c_tree_sum)\n\n\ndef main():\n global now_ans\n num, A, B, C = list(map(int, input().split()))\n tree_data = [int(input()) for i in range(num)]\n tree_data.sort(reverse=True)\n\n calc_data(tree_data, A, B, C, 1, 0, 0, 0, tree_data[0], 0, 0)\n calc_data(tree_data, A, B, C, 0, 1, 0, 0, 0, tree_data[0], 0)\n calc_data(tree_data, A, B, C, 0, 0, 1, 0, 0, 0, tree_data[0])\n calc_data(tree_data, A, B, C, 0, 0, 0, 0, 0, 0, 0)\n\n print(now_ans)\n\nif __name__ == '__main__':\n main()", "\nnow_ans = 100000\n\n\ndef kotae(A, a_tree, a_tree_sum):\n ans = (a_tree - 1) * 10 + abs(a_tree_sum - A)\n if a_tree == 0:\n ans = 100000\n return ans\n\ndef calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum):\n global now_ans\n\n ans = 0\n ans += kotae(A, a_tree, a_tree_sum)\n ans += kotae(B, b_tree, b_tree_sum)\n ans += kotae(C, c_tree, c_tree_sum)\n if ans < now_ans:\n now_ans = ans\n\n\n\ndef calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index, a_tree_sum, b_tree_sum, c_tree_sum ):\n if a_tree_sum >= A and b_tree_sum >= B and c_tree_sum >= C:\n calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)\n return\n if index == len(tree_data) - 1:\n calc_final(A, B, C, a_tree, b_tree, c_tree, a_tree_sum, b_tree_sum, c_tree_sum)\n return\n if a_tree_sum < A:\n calc_data(tree_data, A, B, C, a_tree + 1, b_tree, c_tree, index + 1, a_tree_sum + tree_data[index + 1], b_tree_sum, c_tree_sum)\n if b_tree_sum < B:\n calc_data(tree_data, A, B, C, a_tree, b_tree + 1, c_tree, index + 1, a_tree_sum, b_tree_sum + tree_data[index + 1], c_tree_sum)\n\n if c_tree_sum < C:\n calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree + 1, index + 1, a_tree_sum, b_tree_sum, c_tree_sum + tree_data[index + 1])\n\n calc_data(tree_data, A, B, C, a_tree, b_tree, c_tree, index + 1, a_tree_sum, b_tree_sum, c_tree_sum)\n\n\ndef main():\n global now_ans\n num, A, B, C = list(map(int, input().split()))\n tree_data = [int(input()) for i in range(num)]\n tree_data.sort(reverse=True)\n\n\n calc_data(tree_data, A, B, C, 1, 0, 0, 0, tree_data[0], 0, 0)\n calc_data(tree_data, A, B, C, 0, 1, 0, 0, 0, tree_data[0], 0)\n calc_data(tree_data, A, B, C, 0, 0, 1, 0, 0, 0, tree_data[0])\n calc_data(tree_data, A, B, C, 0, 0, 0, 0, 0, 0, 0)\n\n\n\n print(now_ans)\n\nif __name__ == '__main__':\n main()"]
['Runtime Error', 'Accepted']
['s024692877', 's845264821']
[3316.0, 3192.0]
[19.0, 117.0]
[1941, 1921]
p03111
u603234915
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c)\n ret2 = dfs(cur + 1, a, b + l[cur], c)\n ret3 = dfs(cur + 1, a, b, c + l[cur])\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(ret0, ret1, ret2, ret3))\n', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Accepted']
['s444630367', 's017908737']
[3064.0, 3064.0]
[17.0, 70.0]
[452, 455]
p03111
u606878291
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["from itertools import product, permutations\n\nN, A, B, C = map(int, input().split(' '))\nL = [int(input()) for _ in range(N)]\n\nans = 10 ** 9\nfor groups in product(range(4), repeat=N):\n items = []\n group_a = []\n group_b = []\n group_c = []\n\n for group, length in zip(groups, L):\n if group == 0:\n items.append((length, 0))\n elif group == 1:\n group_a.append(length)\n elif group == 2:\n group_b.append(length)\n elif group == 3:\n group_c.append(length)\n\n if len(items) < 3:\n continue\n\n if group_a:\n items.append((sum(group_a), (len(group_a) - 1) * 10))\n if group_b:\n items.append((sum(group_b), (len(group_b) - 1) * 10))\n if group_c:\n items.append((sum(group_c), (len(group_c) - 1) * 10))\n\n for one, two, three in permutations((A, B, C), r=3):\n cost = 0\n _items = list(items)\n\n _items = sorted(_items, key=lambda x: (abs(x[0] - one), x[1]))\n cost += abs(_items[0][0] - one) + _items[0][1]\n _items.pop(0)\n\n _items = sorted(_items, key=lambda x: (abs(x[0] - two), x[1]))\n cost += abs(_items[0][0] - two) + _items[0][1]\n _items.pop(0)\n\n _items = sorted(_items, key=lambda x: (abs(x[0] - three), x[1]))\n cost += abs(_items[0][0] - three) + _items[0][1]\n\n ans = min(ans, cost)\n\nprint(ans)\n", "from itertools import product\n\nN, A, B, C = map(int, input().split(' '))\nL = [int(input()) for _ in range(N)]\n\nans = 10 ** 9\nfor groups in product(range(4), repeat=N):\n length_a = 0\n length_b = 0\n length_c = 0\n cost_a = -10\n cost_b = -10\n cost_c = -10\n\n for group, length in zip(groups, L):\n if group == 1:\n length_a += length\n cost_a += 10\n elif group == 2:\n length_b += length\n cost_b += 10\n elif group == 3:\n length_c += length\n cost_c += 10\n\n if 0 in {length_a, length_b, length_c}:\n continue\n\n ans = min(ans, sum([\n abs(A - length_a),\n abs(B - length_b),\n abs(C - length_c),\n cost_a,\n cost_b,\n cost_c,\n ]))\n\nprint(ans)\n"]
['Wrong Answer', 'Accepted']
['s143046020', 's437097956']
[9292.0, 9204.0]
[737.0, 188.0]
[1382, 790]
p03111
u620600011
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['@n, @a, @b, @c = gets.chomp.split(" ").map(&:to_i)\n\n@l = []\n@n.times do\n @l << gets.chomp.to_i\nend\nINF = 10**9\n\ndef dfs(cur, a, b, c)\n if cur == @n\n if [a, b, c].min > 0\n return (a - @a).abs + (b - @b).abs + (c - @c).abs - 30\n else\n return INF\n end\n end\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + @l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a , b + @l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + @l[cur]) + 10\n return [ret0, ret1, ret2, ret3].min\nend\n\nputs dfs(0, 0, 0, 0)', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Accepted']
['s263876764', 's075959773']
[2940.0, 3064.0]
[17.0, 72.0]
[509, 437]
p03111
u623065116
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = list(int(input()) for i in range(N))\ninf = 10**9\n\n def dfs(cur,a,b,c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c) + 10\n ret2 = dfs(cur+1,a,b+l[cur],c) + 10\n ret3 = dfs(cur+1,a,b,c+l[cur]) + 10\n \n return min(ret0,ret1,ret2,ret3)\n \nprint(dfs(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = list(int(input()) for i in range(n))\ninf = 10**9\n\n def dfs(cur,a,b,c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c) + 10\n ret2 = dfs(cur+1,a,b+l[cur],c) + 10\n ret3 = dfs(cur+1,a,b,c+l[cur]) + 10\n \n return min(ret0,ret1,ret2,ret3)\n \nprint(dfs(0,0,0,0))', 'N,A,B,C = map(int,input().split())\nl = [int(input()) for i in range(N)]\ninf = 10**9\ndef dfs(cur,a,b,c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else inf\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c) + 10\n ret2 = dfs(cur+1,a,b+l[cur],c) + 10\n ret3 = dfs(cur+1,a,b,c+l[cur]) + 10\n \n return min(ret0,ret1,ret2,ret3)\n \nprint(dfs(0,0,0,0))']
['Runtime Error', 'Runtime Error', 'Accepted']
['s040094973', 's050751973', 's228993554']
[2940.0, 2940.0, 3064.0]
[17.0, 17.0, 74.0]
[458, 458, 417]
p03111
u637170240
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nL = [int(input()) for i in range(N)]\nprint(L)\n\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) else 1000000000\n\n path_null = dfs(cur+1, a, b, c)\n path_a = dfs(cur+1, a+L[cur], b, c) + 10\n path_b = dfs(cur+1, a, b+L[cur], c) + 10\n path_c = dfs(cur+1, a, b, c+L[cur]) + 10\n\n return min(path_null, path_a, path_b, path_c)\n\nprint(dfs(0,0,0,0))\n', 'N, A, B, C = map(int, input().split())\nL = [int(input()) for i in range(N)]\n\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) else 1000000000\n\n path_null = dfs(cur+1, a, b, c)\n path_a = dfs(cur+1, a+L[cur], b, c) + 10\n path_b = dfs(cur+1, a, b+L[cur], c) + 10\n path_c = dfs(cur+1, a, b, c+L[cur]) + 10\n\n return min(path_null, path_a, path_b, path_c)\n\nprint(dfs(0,0,0,0))\n']
['Wrong Answer', 'Accepted']
['s831718444', 's613843320']
[3064.0, 3064.0]
[71.0, 74.0]
[454, 445]
p03111
u652656291
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nINF=10**9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'n,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nINF=10**9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N,A,B,C = map(int,input().split())\nl = [int(input()) for i in range(N)]\nINF = 100000000\ndef rec(i,a,b,c):\n if(i==N):\n return(abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF)\n ret0 = rec(i+1,a,b,c)\n ret1 = rec(i+1,a+l[i],b,c)+10\n ret2 = rec(i+1,a,b+l[i],c)+10\n ret3 = rec(i+1,a,b,c+l[i])+10\n return min(ret0,ret1,ret2,ret3)\nprint(rec(0,0,0,0))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s100861001', 's132935140', 's787999715']
[3064.0, 3064.0, 3064.0]
[17.0, 19.0, 75.0]
[429, 429, 375]
p03111
u653807637
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n, a, b, c = list(map(int, input().split()))\nls = [int(input()) for _ in range(n)]\n\nmin_ans = 10 ** 10\nfor i in range(4 ** n):\n\tmm = [[], [], [],[]]\n\ttmp = i\n\tfor i2 in range(n):\n\t\tg = tmp // (4 ** (n - i2 - 1))\n\t\ttmp = tmp % (4 ** (n - i2 - 1))\n\t\tmm[g%4].append(ls[i2])\n\t\n\tif len(mm[0]) * len(mm[1]) * len(mm[2]) == 0:\n\t\tcontinue\n\n\tprint(mm)\n\tans = abs(sum(mm[0]) - a) + abs(sum(mm[1]) - b) + abs(sum(mm[2]) - c) + (len(mm[0]) - 1) * 10 + (len(mm[1]) - 1) * 10 + (len(mm[2]) - 1) * 10\n\tmin_ans = min(ans, min_ans)\n\nprint(min_ans)', 'n, a, b, c = list(map(int, input().split()))\nls = [int(input()) for _ in range(n)]\n\nmin_ans = 10 ** 10\nfor i in range(4 ** n):\n\tmm = [[], [], [],[]]\n\ttmp = i\n\tfor i2 in range(n):\n\t\tg = tmp // (4 ** (n - i2 - 1))\n\t\ttmp = tmp % (4 ** (n - i2 - 1))\n\t\tmm[g%4].append(ls[i2])\n\t\n\tif len(mm[0]) * len(mm[1]) * len(mm[2]) == 0:\n\t\tcontinue\n\n\t#print(mm)\n\tans = abs(sum(mm[0]) - a) + abs(sum(mm[1]) - b) + abs(sum(mm[2]) - c) + (len(mm[0]) - 1) * 10 + (len(mm[1]) - 1) * 10 + (len(mm[2]) - 1) * 10\n\tmin_ans = min(ans, min_ans)\n\nprint(min_ans)']
['Wrong Answer', 'Accepted']
['s985077307', 's513655916']
[5364.0, 3064.0]
[822.0, 646.0]
[530, 531]
p03111
u664796535
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["import numpy as np\n\nn, a, b, c = map(int, input().split(' '))\nls = []\nfor _ in range(n):\n ls.append(int(input()))\nn = 0\n\n\ndef solve(obj):\n c = len(ls)\n dp = np.zeros((obj + 1, c + 1), dtype=int)\n dp[1:, 0] = 10000\n for j in range(1, c + 1):\n dp[0, j] = min(ls[:j])\n for i in range(1, obj + 1):\n for j in range(1, c + 1):\n dp[i, j] = min(dp[i - 1, j] + 1, dp[i, j - 1], abs(ls[j - 1] - i))\n if i >= ls[j - 1]:\n dp[i, j] = min(dp[i, j], dp[i - ls[j - 1], j - 1] + 10)\n \n return dp[obj, c]\n\n\nfor obj in [a, b, c]:\n if obj in ls:\n continue\n else:\n n += solve(obj)\nprint(n)", "import numpy as np\n\nn, a, b, c = map(int, input().split(' '))\nls = []\nfor _ in range(n):\n ls.append(int(input()))\nn = 0\ndef solve(obj):\n c = len(ls)\n dp = np.zeros((obj+1, c+1), dtype=int)\n dp[1:, 0] = np.inf\n for j in range(1, c+1):\n dp[0, j] = min(ls[:j])\n for i in range(1, obj+1):\n for j in range(1, c+1):\n dp[i, j] = min(dp[i-1, j] + 1, dp[i, j-1], dp[i-ls[j-1], j-1] + 10, abs(ls[j-1]) - i)\n return dp[obj, c]\n\nfor obj in [a, b, c]:\n if obj in ls:\n continue\n else:\n n += solve(obj)\nprint(n)", "\nimport numpy as np\n\nN, A, B, C = map(int, input().split(' '))\nls = []\nfor _ in range(N):\n ls.append(int(input()))\nn = 0\nINF = 10 ** 9\n\ndef dfs(n, a, b, c):\n if n == N:\n return INF if min(a, b, c) == 0 else abs(a-A) + abs(b-B) + abs(c-C) - 30\n res0 = dfs(n+1, a, b, c)\n res1 = dfs(n+1, a+ls[n], b, c) + 10\n res2 = dfs(n+1, a, b+ls[n], c) + 10\n res3 = dfs(n+1, a, b, c+ls[n]) + 10\n return min(res0, res1, res2, res3)\n\nprint(dfs(0, 0, 0, 0))"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s143650742', 's956267070', 's437943514']
[14556.0, 21732.0, 12508.0]
[275.0, 326.0, 203.0]
[661, 524, 467]
p03111
u668503853
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\nif cur == N:\nreturn abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\nret0 = dfs(cur + 1, a, b, c)\nret1 = dfs(cur + 1, a + l[cur], b, c) + 10\nret2 = dfs(cur + 1, a, b + l[cur], c) + 10\nret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\nreturn min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', '\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\nret0 = dfs(cur + 1, a, b, c)\nret1 = dfs(cur + 1, a + l[cur], b, c) + 10\nret2 = dfs(cur + 1, a, b + l[cur], c) + 10\nret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\nreturn min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n', '\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s024443075', 's998948221', 's677696995']
[2940.0, 2940.0, 3064.0]
[17.0, 17.0, 70.0]
[433, 438, 450]
p03111
u672494157
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import sys\nimport math\nfrom collections import deque\n\nsys.setrecursionlimit(4100000)\n\n\ndef inputs(num_of_input):\n ins = [input() for i in range(num_of_input)]\n return ins\n\n\ndef solve(N, A, B, C, inputs):\n bamboos = [int(i) for i in inputs]\n\n def cost(cursor, a, b, c):\n if cursor == N:\n if min(a, b, c) > 0:\n return abs(A-a) + abs(B-b) + abs(C-c) - 30\n else:\n return 1000000000\n\n t = bamboos[cursor]\n results = []\n results.append(cost(cursor+1, a, b, c))\n results.append(cost(cursor+1, a + t, b, c) + 10)\n results.append(cost(cursor+1, a, b + t, c) + 10)\n results.append(cost(cursor+1, a, b, c + t) + 10)\n\n return min(results)\n\n return cost(0, 0, 0, 0)\n\n\ndef string_to_int(string):\n return list(map(lambda x: int(x), string.split()))\n\n\nif __name__ == "__main__":\n [N, A, B, C] = string_to_int(inputs(1))\n ret = solve(N, A, B, C, inputs(N))\n print(ret)\n', 'import sys\nimport math\nfrom collections import deque\n\nsys.setrecursionlimit(4100000)\n\n\ndef inputs(num_of_input):\n ins = [input() for i in range(num_of_input)]\n return ins\n\n\ndef solve(N, A, B, C, inputs):\n bamboos = [int(i) for i in inputs]\n\n def cost(cursor, a, b, c):\n if cursor == N:\n if min(a, b, c) > 0:\n return abs(A-a) + abs(B-b) + abs(C-c) - 30\n else:\n return 1000000000\n\n t = bamboos[cursor]\n results = []\n results.append(cost(cursor+1, a, b, c))\n results.append(cost(cursor+1, a + t, b, c) + 10)\n results.append(cost(cursor+1, a, b + t, c) + 10)\n results.append(cost(cursor+1, a, b, c + t) + 10)\n\n return min(results)\n\n return cost(0, 0, 0, 0)\n\n\ndef string_to_int(string):\n return list(map(lambda x: int(x), string.split()))\n\n\nif __name__ == "__main__":\n [N, A, B, C] = string_to_int(input())\n ret = solve(N, A, B, C, inputs(N))\n print(ret)\n']
['Runtime Error', 'Accepted']
['s413494333', 's918618227']
[3316.0, 3316.0]
[21.0, 82.0]
[987, 985]
p03111
u677121387
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['from itertools import product \nn,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\ntar = [a,b,c]\nans = float("inf")\nfor p in product(range(4),repeat=8):\n mp = 0\n length = [0]*3\n for i,j in enumerate(p):\n if j == 3: continue\n if length[j] > 0: mp += 10\n length[j] += l[i]\n for i in range(3):\n if length[i] == 0: break\n mp += abs(length[i]-tar[i])\n else:\n ans = min(ans, mp)\nprint(ans)', 'from itertools import product \nn,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\ntar = [a,b,c]\nans = float("inf")\nfor p in product(range(4),repeat=n):\n mp = 0\n length = [0]*3\n for i,j in enumerate(p):\n if j == 3: continue\n if length[j] > 0: mp += 10\n length[j] += l[i]\n for j in range(3):\n if length[j] == 0: break\n mp += abs(length[j]-tar[j])\n else:\n ans = min(ans, mp)\nprint(ans)']
['Runtime Error', 'Accepted']
['s826195614', 's050813751']
[3064.0, 3064.0]
[352.0, 358.0]
[460, 460]
p03111
u677440371
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['{\n "cells": [\n {\n "cell_type": "code",\n "execution_count": 4,\n "metadata": {},\n "outputs": [\n {\n "name": "stdout",\n "output_type": "stream",\n "text": [\n "5 100 90 80\\n"\n ]\n }\n ],\n "source": [\n "N,A,B,C = map(int, input().split())"\n ]\n },\n {\n "cell_type": "code",\n "execution_count": 5,\n "metadata": {},\n "outputs": [\n {\n "name": "stdout",\n "output_type": "stream",\n "text": [\n "98\\n",\n "40\\n",\n "30\\n",\n "21\\n",\n "80\\n"\n ]\n }\n ],\n "source": [\n "l = []\\n",\n "for i in range(n):\\n",\n " l.append(int(input()))"\n ]\n },\n {\n "cell_type": "code",\n "execution_count": 13,\n "metadata": {},\n "outputs": [\n {\n "name": "stdout",\n "output_type": "stream",\n "text": [\n "23\\n"\n ]\n }\n ],\n "source": [\n "INF = 10 ** 9\\n",\n "def dfs(cur, a, b, c):\\n",\n " if cur == n:\\n",\n " return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a,b,c) > 0 else INF\\n",\n " ret0 = dfs(cur + 1, a, b, c)\\n",\n " ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\\n",\n " ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\\n",\n " ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\\n",\n " return min(ret0, ret1, ret2, ret3)\\n",\n "\\n",\n "print(dfs(0, 0, 0, 0))"\n ]\n },\n {\n "cell_type": "code",\n "execution_count": null,\n "metadata": {},\n "outputs": [],\n "source": []\n }\n ],\n "metadata": {\n "kernelspec": {\n "display_name": "Python 3",\n "language": "python",\n "name": "python3"\n },\n "language_info": {\n "codemirror_mode": {\n "name": "ipython",\n "version": 3\n },\n "file_extension": ".py",\n "mimetype": "text/x-python",\n "name": "python",\n "nbconvert_exporter": "python",\n "pygments_lexer": "ipython3",\n "version": "3.7.2"\n }\n },\n "nbformat": 4,\n "nbformat_minor": 2\n}\n', 'N, A, B, C = map(int, input().split())\nL = []\nfor i in range(N):\n L.append(int(input()))\n \nimport itertools\nm = 4\nbit_list = list(itertools.product([i for i in range(m)], repeat=N))\nans = 10 ** 18\nfor bit in bit_list:\n retA = 0\n retB = 0\n retC = 0\n checkA = False\n checkB = False\n checkC = False\n cost = 0\n for i,j in enumerate(bit):\n if j == 1:\n retA += L[i]\n if checkA:\n cost += 10\n checkA = True\n if j == 2:\n retB += L[i]\n if checkB:\n cost += 10\n checkB = True\n if j == 3:\n retC += L[i]\n if checkC:\n cost += 10\n checkC = True\n if min(retA,retB,retC) != 0:\n ans = min(ans, abs(A-retA)+abs(B-retB)+abs(C-retC)+cost)\nprint(ans) ']
['Runtime Error', 'Accepted']
['s056169006', 's291301168']
[3064.0, 10996.0]
[18.0, 282.0]
[1868, 833]
p03111
u693378622
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['def dfs(a, b, c, k)\n \n if k == N\n nil if [a, b, c].min == 0\n return (A-a).abs + (B-b).abs + (C-c).abs - 10 * 3\n end\n \n x = dfs(a+L[k], b, c, k+1) + 10\n y = dfs(a, b+L[k], c, k+1) + 10\n z = dfs(a, b, c+L[k], k+1) + 10\n w = dfs(a, b, c, k+1)\n \n [x, y, z, w].compact.min\nend\n\nN, A, B, C = gets.split.map(&:to_i)\n\nL = Array.new(N)\nN.times{ |i| L[i] = gets.to_i }\n\np dfs(0, 0, 0, 0)\n', '\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s687044193', 's130995556']
[2940.0, 3064.0]
[17.0, 76.0]
[394, 454]
p03111
u693716675
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=[int(i) for i in input().split()]\nl=[int(input()) for _ in range(n)]\nINF=10**18\n\ndef dfs(cur, a, b, c):\n if cur==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 \n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10 \n ret3 = dfs(cur+1,a,b,c+l[cur])+10 \n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))', 'N,A,B,C=[int(i) for i in input().split()]\nl=[int(input()) for _ in range(N)]\nINF=10**18\n\ndef dfs(cur, a, b, c):\n if cur==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n ret0 = dfs(cur+1,a,b,c)\n ret1 = dfs(cur+1,a+l[cur],b,c)+10\n ret2 = dfs(cur+1,a,b+l[cur],c)+10\n ret3 = dfs(cur+1,a,b,c+l[cur])+10\n return min(ret0,ret1,ret2,ret3)\n\nprint(dfs(0,0,0,0))\n']
['Runtime Error', 'Accepted']
['s650572762', 's241339842']
[3064.0, 3064.0]
[17.0, 75.0]
[379, 396]
p03111
u698176039
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\n\nl = [int(input()) for _ in range(N)]\n\nans = 2 ** 20 -1\nfor i in range(N):\n for j in range(N):\n if i == j: continue\n for k in range(N):\n if i == k or j == k : continue\n \n x,y,z = l[i],l[j],l[k]\n cnt = 0\n \n for t in range(N):\n if t == i or t == j or t == k : continue\n\n if l[t] > 10:\n cnt += l[t]\n x += l[t]\n if l[t] > 10:\n cnt += l[t]\n y += l[t]\n if l[t] > 10:\n cnt += l[t]\n z += l[t]\n cnt += abs(x-A) \n cnt += abs(y-B) \n cnt += abs(z-C) \n ans = min(ans,cnt)\n \n \nprint(ans)\n ', 'N,A,B,C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\nlnum = [0] * N\nAlist = [A,B,C]\nans = 2**30+1\nfor i in range(4**N):\n cnt = -30\n tmp = i\n for j in range(N):\n lnum[j] = tmp%4\n tmp //= 4\n \n if not(1 in lnum and 2 in lnum and 3 in lnum):\n continue\n x = [0] * 3\n for j in range(N):\n if lnum[j] != 0:\n x[lnum[j]-1] += l[j]\n cnt += 10\n for j in range(3):\n cnt += abs(Alist[j]-x[j])\n \n ans = min(ans,cnt)\n \nprint(ans)\n \n ']
['Wrong Answer', 'Accepted']
['s650319061', 's470745661']
[3064.0, 3064.0]
[21.0, 424.0]
[844, 536]
p03111
u706929073
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['\n(N, A, B, C) = map(int, input().split())\nl = [int(input()) for _ in range(N)]\n\n\ndef dfs(index, a, b, c):\n if N == index:\n if 0 < min(a, b, c):\n return abs(a - A) + abs(b - B) + abs(c - C) - 30\n else:\n return 1 ** 9\n costs = []\n costs.append(dfs(index + 1, a, b, c))\n costs.append(dfs(index + 1, a + l[index], b, c))\n costs.append(dfs(index + 1, a, b + l[index], c))\n costs.append(dfs(index + 1, a, b, c + l[index]))\n return min(costs)\n\n\nprint(dfs(0, 0, 0, 0))\n', 'vn, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ninf = 10 ** 18\n\n\ndef dfs(i, a, b, c):\n if i == n:\n if a < 1 or b < 1 or c < 1:\n return inf\n return abs(A - a) + abs(B - b) + abs(C - c)\n res = dfs(i + 1, a, b, c)\n res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a > 0 else 0)])\n res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b > 0 else 0)])\n res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)])\n return res\n\n\nprint(dfs(0, 0, 0, 0))\n', 'n, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(n)]\n\n\ndef dfs(i, a, b, c):\n if i == n:\n if a < 1 or b < 1 or c < 1:\n return 10 ** 18\n return abs(A - a) + abs(B - b) + abs(C - c)\n res = dfs(i + 1, a, b, c)\n res = min([res, dfs(i + 1, a + l[i], b, c)])\n res = min([res, dfs(i + 1, a, b + l[i], c)])\n res = min([res, dfs(i + 1, a, b, c + l[i])])\n return res\n\n\nprint(dfs(0, 0, 0, 0))\n', 'n, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(n)]\n\n\ndef dfs(i, a, b, c):\n if i == n:\n if a < 1 or b < 1 or c < 1:\n return 10 ** 18\n return abs(A - a) + abs(B - b) + abs(C - c)\n res = dfs(i + 1, a, b, c)\n res = max([res, dfs(i + 1, a + l[i], b, c)])\n res = max([res, dfs(i + 1, a, b + l[i], c)])\n res = max([res, dfs(i + 1, a, b, c + l[i])])\n return res\n\n\nprint(dfs(0, 0, 0, 0))\n', 'n, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(n)]\n\n\ndef recur(n, i, a, b, c):\n if i == n:\n if a < 1 or b < 1 or c < 1:\n return 10 ** 18\n return abs(A-a) + abs(B-b) + abs(C-c)\n return min([\n recur(n, i + 1, a, b, c),\n recur(n, i + 1, a + l[i], b, c) + (10 if a > 0 else 0),\n recur(n, i + 1, a, b + l[i], c) + (10 if b > 0 else 0),\n recur(n, i + 1, a, b, c + l[i]) + (10 if c > 0 else 0)\n ])\n\n\nprint(recur(n, 0, 0, 0, 0))\n']
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s031773521', 's669385878', 's977422219', 's985237886', 's676426573']
[3064.0, 3192.0, 3064.0, 3064.0, 3064.0]
[72.0, 21.0, 71.0, 72.0, 63.0]
[1326, 529, 447, 447, 508]
p03111
u716043626
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a,b,c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n print(ret0)\n print(ret1)\n print(ret2)\n print(ret3)\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a,b,c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0,0,0,0))']
['Wrong Answer', 'Accepted']
['s820895711', 's127654440']
[3952.0, 3064.0]
[137.0, 73.0]
[514, 450]
p03111
u720636500
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\ninf = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a - A) + abs(b - B) + abs(c - C) \n else:\n return inf\n else: \n ret0 = dfs(cur + 1, a, b, c) \n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\nif cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))\n', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\ninf = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 \n else:\n return inf\n else: \n ret0 = dfs(cur + 1, a, b, c) \n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s112200751', 's577220615', 's492136843']
[2940.0, 2940.0, 3064.0]
[17.0, 17.0, 75.0]
[468, 434, 484]
p03111
u721316601
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import bisect\n\nans = 10**20\n\nN, K = list(map(int, input().split()))\nx = [-10**20] + list(map(int, input().split())) + [10**20]\n\nzero = bisect.bisect_left(x, 0)\n\nleft = x[:zero] + [0] \nright = [0] + x[zero:]\nleft.reverse()\nl = len(left)\nr = len(right)\n\nidxs = [[K-i, i] for i in range(K+1) if K-i < l and i < r]\n\nfor l, r in idxs:\n n = abs(left[l]) + right[r] + min(abs(left[l]), right[r])\n ans = min(ans, n)\nprint(ans)', 'def search(idx, a, b, c):\n if idx == N:\n if min(a, b, c) > 0:\n return abs(A-a) + abs(B-b) + abs(C-c) - 30\n else:\n return 10**20\n \n n0 = search(idx+1, a, b, c)\n n1 = search(idx+1, a+l[idx], b, c) + 10\n n2 = search(idx+1, a, b+l[idx], c) + 10\n n3 = search(idx+1, a, b, c+l[idx]) + 10\n \n return min(n0, n1, n2, n3)\n \nN, A, B, C = list(map(int, input().split()))\nl = [int(input()) for i in range(N)]\n\nprint(search(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s586229855', 's483823996']
[3064.0, 3064.0]
[18.0, 69.0]
[424, 493]
p03111
u729938879
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\ndef calc(take, a, b, c):\n if take == N:\n return abs(a-A)+abs(b-B)+abs(c-C) \n ret0 = calc(take+1, a, b, c)\n ret1 = calc(take+1, a+l[take], b, c) + 10\n ret2 = calc(take+1, a, b+l[take], c) + 10\n ret3 = calc(take+1, a, b, c+l[take]) + 10\n return min(ret0, ret1, ret2, ret3)\n \nprint(calc(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef calc(take, a, b, c):\n if take == N:\n return abs(a-A)+abs(b-B)+abs(c-C) -30 if min(a,b,c)>0 else INF\n ret0 = calc(take+1, a, b, c)\n ret1 = calc(take+1, a+l[take], b, c) + 10\n ret2 = calc(take+1, a, b+l[take], c) + 10\n ret3 = calc(take+1, a, b, c+l[take]) + 10\n return min(ret0, ret1, ret2, ret3)\n \nprint(calc(0,0,0,0))']
['Wrong Answer', 'Accepted']
['s371762138', 's004839256']
[3064.0, 3064.0]
[59.0, 69.0]
[397, 439]
p03111
u731368968
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666', 'N, A, B, C = map(int, input().split())\nl = []\nfor i in range(N):\n l.append(int(input()))\nans = 100000000\n\n\ndef rec(a, b, c, d):\n if d == N:\n if a[1] > 0 and b[1] > 0 and c[1] > 0:\n global ans\n ans = min(\n ans,\n abs(\n a[0] - A) + abs(b[0] - B) + abs(c[0] - C)\n + 10 * (a[1] + b[1] + c[1] - 3)\n )\n return\n rec((a[0] + l[d], a[1] + 1), b, c, d + 1)\n rec(a, (b[0] + l[d], b[1] + 1), c, d + 1)\n rec(a, b, (c[0] + l[d], c[1] + 1), d + 1)\n rec(a, b, c, d + 1)\n\n\nrec((0, 0), (0, 0), (0, 0), 0)\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s092673436', 's914191421']
[2940.0, 3064.0]
[17.0, 81.0]
[46, 626]
p03111
u754022296
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import sys\nsys.setrecursionlimit("10**7")\n\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))\n', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))', 'import sys\nsys.setrecursionlimit("10**7")\n\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))\n', 'import sys\nsys.setrecursionlimit(10**7)\n\nN, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s240401520', 's302399244', 's876804087', 's371168216']
[3064.0, 2940.0, 2940.0, 3064.0]
[17.0, 17.0, 18.0, 74.0]
[479, 433, 477, 476]
p03111
u762557532
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["\n\nimport numpy as np\nfrom copy import deepcopy\n\nN, A, B, C = map(int,input().split())\nL = [list(map(int,input().split())) for i in range(N)]\n\nL = np.array(L)\nmax_merge = N-3\n#min_MP = float('Inf')\n\n\n\ndef bamboo2MP_nomerge(bamboo, A, B, C):\n arr = deepcopy(bamboo)\n n_bamboo = len(arr)\n bamboo_A = np.argmin(np.abs(arr-A))\n MP_A = np.abs(arr[bamboo_A]-A)\n np.delete(arr, MP_A)\n bamboo_B = np.argmin(np.abs(arr-B))\n MP_B = np.abs(arr[bamboo_B]-B)\n np.delete(arr, MP_B)\n bamboo_C = np.argmin(np.abs(arr-C))\n MP_C = np.abs(arr[bamboo_C]-C)\n #np.delete(arr, MP_C)\n return int(MP_A + MP_B + MP_C)\n \n\n\nmin_MP = bamboo2MP_nomerge(L, A, B, C)\n \n\n\n \nprint(min_MP)\n ", 'import itertools\n\nN, A, B, C = map(int,input().split())\nL = [int(input()) for _ in range(N)]\n\nA, B, C = sorted([A,B,C], reverse=True)\n\nans = 100000000 ## =Inf\nfor state in itertools.product(range(4), repeat=N): \n bamboo = [0]*4\n for i in range(len(state)): \n if state[i] < 3:\n bamboo[state[i]] += L[i]\n if 0 in bamboo[0:3]: \n continue\n cost_0 = max(state.count(0) - 1, 0) * 10\n cost_1 = max(state.count(1) - 1, 0) * 10\n cost_2 = max(state.count(2) - 1, 0) * 10\n cost = cost_0 + cost_1 + cost_2\n bamboo.sort(reverse=True)\n cost += abs(bamboo[0]-A) + abs(bamboo[1]-B) + abs(bamboo[2]-C)\n ans = min(ans, cost)\n \nprint(ans)\n ']
['Wrong Answer', 'Accepted']
['s029334311', 's561044026']
[12660.0, 3064.0]
[152.0, 353.0]
[950, 823]
p03111
u764956288
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int, input().split())\n\nbms = [int(input()) for _ in Range(N)]\n\ndef dfs(cur,a,b,c):\n if cur == N:\n s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9\n return s\n s_0 = dfs(cur+1,a,b,c)\n s_a = dfs(cur+1,a+bms[cur],b,c) + 10\n s_b = dfs(cur+1,a,b+bms[cur],c) + 10\n s_c = dfs(cur+1,a,b,c+bms[cur]) + 10\n return min(s_0,s_a,s_b,s_c)\n\nprint(dfs(0,0,0,0))', 'N,A,B,C = map(int, input().split())\nbamboos = [int(input()) for _ in range(N)]\n\ntargets = [A,B,C]\nbamboos.sort(reverse=True)\ntargets.sort(reverse=True)\n\nfor target in targets:\n if target in bamboos:\n targets.remove(target)\n bamboos.remove(target)\n\nif not len(targets):\n print(0)', 'import numpy as np\nprint(np.nan)', 'N,A,B,C = map(int, input().split())\n \nbms = [int(input()) for _ in Range(N)]\n \ndef dfs(cur,a,b,c):\n if cur == N:\n s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9\n return s\n s_0 = dfs(cur+1,a,b,c)\n s_a = dfs(cur+1,a+bms[cur],b,c) + 10\n s_b = dfs(cur+1,a,b+bms[cur],c) + 10\n s_c = dfs(cur+1,a,b,c+bms[cur]) + 10\n return min(s_0,s_a,s_b,s_c)\n\nprint(dfs(0,0,0,0))', 'N,A,B,C = map(int, input().split())\n\nbms = [int(input()) for _ in range(N)]\n\ndef dfs(cur,a,b,c):\n if cur == N:\n s = abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a,b,c) > 0 else 10**9\n return s\n s_0 = dfs(cur+1,a,b,c)\n s_a = dfs(cur+1,a+bms[cur],b,c) + 10\n s_b = dfs(cur+1,a,b+bms[cur],c) + 10\n s_c = dfs(cur+1,a,b,c+bms[cur]) + 10\n return min(s_0,s_a,s_b,s_c)\n\nprint(dfs(0,0,0,0))']
['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s064925562', 's392507167', 's963033480', 's984021878', 's573676194']
[3064.0, 3064.0, 13200.0, 3064.0, 3064.0]
[18.0, 17.0, 147.0, 18.0, 76.0]
[404, 296, 32, 406, 404]
p03111
u778814286
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\n\n\n\n\ninitialSum = []\nfor i in range(2**N): \n nowsum = 0\n nowbamboocnt = 0\n for j in range(N): \n if i % (2**(j+1)) >= 2**j:\n nowbamboocnt += 1\n nowsum += L[j] \n initialSum.append([nowsum, nowbamboocnt])\n\n\n\n\nbambooset = {i for i in range(N)} \nmin = 3000 \n\nlestbamboo = bambooset.copy() \n\nfor i, initSumA in enumerate(initialSum): \n\n if initSumA[1] ==0 or N - initSumA[1] < 2: continue \n lestbamboo = bambooset.copy() \n for j in range(N): \n if i % (2**(j+1)) >= 2**j: \n lestbamboo.remove(j)\n necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 \n\n \n for b in range(len(lestbamboo)**2): \n \n lestbambooList = list(lestbamboo) \n \n bamboocntB = 0 \n nowsumB = 0\n lestbambooforC = lestbamboo.copy() \n for k in range(len(lestbambooList)): \n if b % (2**(k+1)) >= 2**k: \n bamboocntB += 1\n nowsumB += lestbambooList[k] \n lestbambooforC.remove(lestbambooList[k])\n if bamboocntB == 0: continue \n\n for m in range(len(lestbambooforC)**2): \n \n \n lestbambooforCList = list(lestbambooforC) \n bamboocntC = 0\n nowsumC = 0\n for n in range(len(lestbambooforCList)):\n if m % (2**(n+1)) >= 2**n: \n bamboocntC += 1\n nowsumC += lestbambooforCList[n] \n if bamboocntC == 0: continue \n\n nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10\n \n if nowTotalSum < min: min = nowTotalSum\n\nprint(min)', 'N, A, B, C = map(int, input().split())\nL = [int(input()) for _ in range(N)]\n\n\n\ninitialSum = []\nfor i in range(2**N): \n nowsum = 0\n nowbamboocnt = 0\n for j in range(N): \n if i % (2**(j+1)) >= 2**j:\n nowbamboocnt += 1\n nowsum += L[j] \n initialSum.append([nowsum, nowbamboocnt])\n\n\n\nbambooset = {i for i in range(N)} \nmin = 3000 \n\nlestbamboo = bambooset.copy() \n\nfor i, initSumA in enumerate(initialSum): \n\n if initSumA[1] ==0 or N - initSumA[1] < 2: continue \n lestbamboo = bambooset.copy() \n for j in range(N): \n if i % (2**(j+1)) >= 2**j: \n lestbamboo.remove(j)\n necesMPforA = abs(A - initSumA[0]) + (initSumA[1]-1)*10 \n\n \n for b in range(2**len(lestbamboo)): \n \n lestbambooList = list(lestbamboo) \n \n bamboocntB = 0 \n nowsumB = 0\n lestbambooforC = lestbamboo.copy() \n for k in range(len(lestbambooList)): \n if b % (2**(k+1)) >= 2**k: \n bamboocntB += 1\n nowsumB += L[lestbambooList[k]] \n lestbambooforC.remove(lestbambooList[k])\n if bamboocntB == 0: continue \n\n for m in range(2**len(lestbambooforC)): \n \n \n lestbambooforCList = list(lestbambooforC) \n bamboocntC = 0\n nowsumC = 0\n for n in range(len(lestbambooforCList)):\n if m % (2**(n+1)) >= 2**n: \n bamboocntC += 1\n nowsumC += L[lestbambooforCList[n]] \n if bamboocntC == 0: continue \n\n nowTotalSum = necesMPforA + abs(B - nowsumB) + (bamboocntB-1)*10 + abs(C - nowsumC) + (bamboocntC-1)*10\n \n if nowTotalSum < min: min = nowTotalSum\n\nprint(min)']
['Wrong Answer', 'Accepted']
['s750895264', 's195799866']
[3188.0, 3316.0]
[186.0, 268.0]
[3708, 3544]
p03111
u788068140
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import math\n\nN, A, B, C = 5, 100, 90, 80\nARR = [\n 98,\n 40,\n 30,\n 21,\n 80\n]\n\n# N, A, B, C = map(int, input().split())\n# ARR = []\n\n# ARR.append(int(input()))\nresult = []\n\n\ndef dfs(deep, crr):\n if deep == N:\n ok, res = calculate(crr)\n if ok:\n result.append(int(res))\n else:\n for i in range(4):\n crr[deep] = i\n dfs(deep + 1, crr)\n\n\ndef calculate(crr):\n sA = set()\n sB = set()\n sC = set()\n sN = set()\n for index, cr in enumerate(crr):\n if cr == 0:\n sN.add(ARR[index])\n if cr == 1:\n sA.add(ARR[index])\n if cr == 2:\n sB.add(ARR[index])\n if cr == 3:\n sC.add(ARR[index])\n\n if len(sN) == N:\n return False,-1\n if len(sA) == 0:\n return False, -1\n if len(sB) == 0:\n return False, -1\n if len(sC) == 0:\n return False, -1\n\n print(crr)\n\n s1 = (len(sA) - 1) * 10 + math.fabs(sum(sA) - A)\n s2 = (len(sB) - 1) * 10 + math.fabs(sum(sB) - B)\n s3 = (len(sC) - 1) * 10 + math.fabs(sum(sC) - C)\n\n return True, s1 + s2 + s3\n\n\ndfs(0, [0 for i in range(N)])\n\nprint(min(result))\n', 'import math\n# N, A, B, C = 7, 100, 90, 80\n# ARR = [\n# 98,\n# 40,\n# 30,\n# 21,\n# 80,\n# 25,\n# 100\n# ]\n\nN, A, B, C = map(int, input().split())\nARR = []\nfor i in range(N):\n ARR.append(int(input()))\nresult = []\n\n\ndef dfs(deep, crr):\n if deep == N:\n ok, res = calculate(crr)\n if ok:\n result.append(int(res))\n else:\n for i in range(4):\n crr[deep] = i\n dfs(deep + 1, crr)\n\n\ndef calculate(crr):\n sA = []\n sB = []\n sC = []\n sN = []\n for index, cr in enumerate(crr):\n if cr == 0:\n sN.append(ARR[index])\n if cr == 1:\n sA.append(ARR[index])\n if cr == 2:\n sB.append(ARR[index])\n if cr == 3:\n sC.append(ARR[index])\n\n if len(sA) == 0:\n return False, -1\n if len(sB) == 0:\n return False, -1\n if len(sC) == 0:\n return False, -1\n\n\n s1 = (len(sA) - 1) * 10 + math.fabs(sum(sA) - A)\n s2 = (len(sB) - 1) * 10 + math.fabs(sum(sB) - B)\n s3 = (len(sC) - 1) * 10 + math.fabs(sum(sC) - C)\n\n return True, s1 + s2 + s3\n\n\ndfs(0, [0 for i in range(N)])\n\nprint(min(result))']
['Wrong Answer', 'Accepted']
['s024952290', 's654300935']
[3188.0, 5020.0]
[31.0, 314.0]
[1191, 1158]
p03111
u791082321
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n\tif cur == N:\n\t\treturn abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n\tret0 = dfs(cur + 1, a, b, c)\n \tret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n\tret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n\tret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n\treturn min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s654777849', 's840152383']
[2940.0, 3064.0]
[17.0, 73.0]
[430, 437]
p03111
u807772568
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,a,b,c = map(int,input().spilt())\n\nko = [int(input()) for i in range(n)]\nINF = 10**9\n\n def dfs(q,w,e,r):\n \tif q == n:\n \t\t return abs(a-w) + abs(b-e) + abs(c-r) - 30 if min(a,b,c) > 0 else INF\n \tre0 = dfs(q+1,w,e,r)\n \tre1 = dfs(q+1,w+ko[q],e,r) + 10\n \tre2 = dfs(q+1,w,e+ko[ko],r) + 10\n \tre3 = dfs(q+1,w,e,r+ko[q]) + 10\n \treturn min(re0,re1,re2,re3)\n\nprint(dfs(0,0,0,0))', 'n,a,b,c = int(input().spilt())\n\nko = [int(input()) for i in range(n)]\nINF = 10**9\n\n def dfs(q,w,e,r):\n \tif q == n:\n \t\t return abs(a-w) + abs(b-e) + abs(c-r) - 30 if min(a,b,c) > 0 else INF\n \tre0 = dfs(q+1,w,e,r)\n \tre1 = dfs(q+1,w+ko[q],e,r) + 10\n \tre2 = dfs(q+1,w,e+ko[ko],r) + 10\n \tre3 = dfs(q+1,w,e,r+ko[q]) + 10\n \treturn min(re0,re1,re2,re3)\n\nprint(dfs(0,0,0,0))', 'n,a,b,c = map(int,input().split())\n\nko = [int(input()) for i in range(n)]\nINF = 10**9\n\ndef dfs(q,w,e,r):\n \tif q == n:\n \t\t return abs(a-w) + abs(b-e) + abs(c-r) - 30 if min(w,e,r) > 0 else INF\n \tre0 = dfs(q+1,w,e,r)\n \tre1 = dfs(q+1,w+ko[q],e,r) + 10\n \tre2 = dfs(q+1,w,e+ko[q],r) + 10\n \tre3 = dfs(q+1,w,e,r+ko[q]) + 10\n \treturn min(re0,re1,re2,re3)\n\nprint(dfs(0,0,0,0))\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s523191056', 's876687903', 's803832675']
[2940.0, 2940.0, 3064.0]
[18.0, 17.0, 71.0]
[369, 365, 368]
p03111
u811132356
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=map(int,input().split())\nl=[]\n\nfor i in range(N):\nl.append(int(input()))\nINF=100000\n\ndef mp(j,a,b,c):\n if j==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n ret0=mp(j+1,a,b,c)\n ret1=mp(j+1,a+l[j],b,c)+10\n ret2=mp(j+1,a,b+l[j],c)+10\n ret3=mp(j+1,a,b,c+l[j])+10\n return min(ret0,ret1,ret2,ret3)\nprint(mp(0,0,0,0))', 'N,A,B,C=map(int,input().split())\nl=[]\n \nfor i in range(N):\n l.append(int(input()))\nINF=100000\n \ndef mp(j,a,b,c):\n if j==N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c)>0 else INF\n ret0=mp(j+1,a,b,c)\n ret1=mp(j+1,a+l[j],b,c)+10\n ret2=mp(j+1,a,b+l[j],c)+10\n ret3=mp(j+1,a,b,c+l[j])+10\n return min(ret0,ret1,ret2,ret3)\nprint(mp(0,0,0,0))']
['Runtime Error', 'Accepted']
['s758319437', 's401639198']
[2940.0, 3188.0]
[18.0, 72.0]
[361, 367]
p03111
u815659544
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['#%%\nimport sys\nINPUT = sys.stdin.readline\n\ndef SINGLE_INT(): return int(INPUT())\ndef MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))\ndef MULTIPLE_INT_MAP(): return map(int, INPUT().split())\ndef SINGLE_STRING(): return INPUT()\ndef MULTIPLE_STRING(): return INPUT().split()\n\n#%%\n\nN, A, B, C = MULTIPLE_INT_MAP()\nmaterials = MULTIPLE_INT_LIST()\nINF = 10 ** 9\n\n#%%\n\ndef dfs(cursor, a, b, c): \n if cursor == N: \n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) != 0 else INF\n \n \n\n \n\n \n \n no_compound = dfs(cursor+1, a, b, c)\n compound_to_a = dfs(cursor+1, a + materials[cursor], b, c) + 10\n compound_to_b = dfs(cursor+1, a, b + materials[cursor], c) + 10\n compound_to_c = dfs(cursor+1, a, b, c + materials[cursor]) + 10\n\n return min(no_compound, compound_to_a, compound_to_b, compound_to_c)\n\nprint(dfs(0, 0, 0, 0))', '#%%\nimport sys\nINPUT = sys.stdin.readline\n\ndef SINGLE_INT(): return int(INPUT())\ndef MULTIPLE_INT_LIST(): return list(map(int, INPUT().split()))\ndef MULTIPLE_INT_MAP(): return map(int, INPUT().split())\ndef SINGLE_STRING(): return INPUT()\ndef MULTIPLE_STRING(): return INPUT().split()\n\n#%%\n\nN, A, B, C = MULTIPLE_INT_MAP()\nmaterials = [int(input()) for _ in range(N)]\nINF = 10 ** 9\n\n#%%\n\ndef dfs(cursor, a, b, c): \n if cursor == N: \n return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) != 0 else INF\n \n \n\n \n\n \n \n no_compound = dfs(cursor+1, a, b, c)\n compound_to_a = dfs(cursor+1, a + materials[cursor], b, c) + 10\n compound_to_b = dfs(cursor+1, a, b + materials[cursor], c) + 10\n compound_to_c = dfs(cursor+1, a, b, c + materials[cursor]) + 10\n\n return min(no_compound, compound_to_a, compound_to_b, compound_to_c)\n\nprint(dfs(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s986055138', 's935661663']
[3064.0, 3064.0]
[18.0, 73.0]
[1467, 1480]
p03111
u818349438
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,A,B,C = map(int,input().split())\nl = list(int(input())for _ in range(n))\ndef dfs(depth,a,b,c):\n if depth == n:\n return abs(a-A)+abs(b-B)*abs(c-C)-30 if min(a,b,c) >0 else 10**9\n x = dfs(depth+1,a,b,c)\n y = dfs(depth+1,a+l[depth],b,c) +10\n z = dfs(depth+1,a,b+l[depth],c) +10\n w = dfs(depth+1,a,b,c+l[depth]) +10\n return min(x,y,z,w)\nprint(dfs(0,0,0,0))\n \n ', 'n,A,B,C = map(int,input().split())\nl = list(int(input())for _ in range(n))\ndef dfs(depth,a,b,c):\n if depth == n:\n return abs(a-A)+abs(b-B)*abs(c-C)-30 if min(a,b,c) >0 else 10**9\n x = dfs(depth+1,a,b,c)\n y = dfs(depth+1,a+l[depth],b,c) +10\n z = dfs(depth+1,a,b+l[depth],c) +10\n w = dfs(depth+1,a,b,c+l[depth]) +10\n return min(x,y,z,w)\ndfs(0,0,0,0)\n \n ', 'n,A,B,C = map(int,input().split())\nl = list(int(input())for _ in range(n))\ndef dfs(depth,a,b,c):\n if depth == n:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) >0 else 10**9\n x = dfs(depth+1,a,b,c)\n y = dfs(depth+1,a+l[depth],b,c) +10\n z = dfs(depth+1,a,b+l[depth],c) +10\n w = dfs(depth+1,a,b,c+l[depth]) +10\n return min(x,y,z,w)\nprint(dfs(0,0,0,0))\n \n ']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s007767576', 's805594482', 's987365546']
[3064.0, 3064.0, 3064.0]
[75.0, 74.0, 74.0]
[394, 387, 394]
p03111
u826263061
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import itertools as itr\n\nn, a, b, c = list(map(int, input().split()))\nl = []\nfor _ in range(n):\n l.append(int(input()))\n \nl.sort()\n\ncost = 10**9\nfor cr in range(1, n-2):\n for ccomb in itr.combinations(l, cr):\n ccosti = abs(c-sum(ccomb)) + (cr-1)*10\n cl = l[:]\n for icomb in ccomb:\n cl.remove(icomb)\n for br in range(1, n-2-cr):\n for bcomb in itr.combinations(cl, br):\n bcosti = abs(b-sum(bcomb)) + (br-1)*10\n bl = cl[:]\n for icomb in bcomb:\n bl.remove(icomb)\n for ar in range(1, n-2-cr-br):\n for acomb in itr.combinations(bl, ar):\n acosti = abs(a-sum(acomb)) + (ar-1)*10\n if cost > ccosti + bcosti + acosti:\n cost = ccosti + bcosti + acosti\n\nprint(cost)', 'import itertools as itr\n\nn, a, b, c = list(map(int, input().split()))\nl = []\nfor _ in range(n):\n l.append(int(input()))\n \nl.sort()\n\ncost = 10**9\nfor cr in range(1, n-1):\n for ccomb in itr.combinations(l, cr):\n ccosti = abs(c-sum(ccomb)) + (cr-1)*10\n cl = l[:]\n for icomb in ccomb:\n cl.remove(icomb)\n for br in range(1, n-cr):\n for bcomb in itr.combinations(cl, br):\n bcosti = abs(b-sum(bcomb)) + (br-1)*10\n bl = cl[:]\n for icomb in bcomb:\n bl.remove(icomb)\n for ar in range(1, n+1-cr-br):\n for acomb in itr.combinations(bl, ar):\n acosti = abs(a-sum(acomb)) + (ar-1)*10\n if cost > ccosti + bcosti + acosti:\n cost = ccosti + bcosti + acosti\n\nprint(cost)']
['Wrong Answer', 'Accepted']
['s399576672', 's015431407']
[3064.0, 3064.0]
[29.0, 60.0]
[883, 881]
p03111
u835482198
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\n\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30\n else:\n return float('inf')\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + [cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\n\nprint(dfs(0, 0, 0, 0))\n", "N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\n\n\ndef dfs(cur, a, b, c):\n if cur == N:\n if min(a, b, c) > 0:\n return abs(a - A) + abs(b - B) + abs(c - C) - 30\n else:\n return float('inf')\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\n\nprint(dfs(0, 0, 0, 0))\n"]
['Runtime Error', 'Accepted']
['s101216109', 's103565758']
[3188.0, 3188.0]
[18.0, 76.0]
[491, 492]
p03111
u842964692
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C=map(int,input().split())\nL=[int(input()) for _ in range(N)]\n\n\n# L.append(int(input())\n\nans=10**18\ndef cost_calc(pp,TAKEs):\n if TAKEs==[]:\n return 10**8\n \n else:\n ans=0\n ans+=(len(TAKEs)-1)*10\n ans+=abs(pp-sum(TAKEs))\n return ans\n\nassign=[]#[A,B,C,none]\n\nfor pattern in product([0,1,2,3],repeat=N):\n MP=0\n take=[0]*3\n for index,length in zip(pattern,l):\n if index==3:\n continue\n if take[index]!=0:\n MP+=10\n take[index]+=length\n if take[0]!=0 and take[1]!=0 and take[2]!=0:\n MP+=abs(A-take[0])\n MP+=abs(B-take[1])\n MP+=abs(C-take[2])\n ans=min(MP,ans)\nprint(ans)', 'N,A,B,C=map(int,input().split())\nL=[int(input()) for _ in range(N)]\nfrom itertools import product\n\nans=10**18\n\nfor pattern in product(range(4),repeat=N):\n MP=0\n take=[0]*3\n for index,length in zip(pattern,L):\n if index==3:\n continue\n if take[index]!=0:\n MP+=10\n take[index]+=length\n if take[0]!=0 and take[1]!=0 and take[2]!=0:\n MP+=abs(A-take[0])\n MP+=abs(B-take[1])\n MP+=abs(C-take[2])\n ans=min(MP,ans)\nprint(ans)']
['Runtime Error', 'Accepted']
['s618374398', 's101045429']
[3064.0, 3064.0]
[19.0, 290.0]
[716, 498]
p03111
u863150907
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['\n\n\n# A = 90, L! = [40,30,21] -> 20 + 1\nimport copy as cp\ninf = 10**9\ndef cost(li, length):\n if len(li)==0:\n return inf\n return (len(li)-1)*10 + abs(sum(li)-length)\n\ndef search_cost(ln,assignment,length):\n# from IPython.core.debugger import Pdb; Pdb().set_trace()\n if len(ln)==0:\n costA = cost(assignment["A"], length[0])\n costB = cost(assignment["B"], length[1])\n costC = cost(assignment["C"], length[2])\n return costA + costB + costC\n val = ln[-1]\n candidate = []\n for take in assignment.keys():\n nextdic = cp.deepcopy(assignment)\n nextdic[take].append(val)\n print(nextdic)\n cand = search_cost(ln[:-1],nextdic,length)\n candidate.append(cand)\n return min(candidate)\n \n \n\nN, A, B, C =map(int,input().split())\nlength = [A,B,C]\nln = []\nassignment = {"A":[],"B":[],"C":[],"D":[]}\n\nfor i in range(N):\n a = int(input())\n ln.append(a)\n \nsearch_cost(ln,assignment,length)', '\nN, A, B, C =map(int,input().split())\nl = []\nfor i in range(N):\n a = int(input())\n l.append(a)\nprint(l)\n\ninfty = 1000000\n\ndef DFS(i,uselist0,uselista,uselistb,uselistc):\n if i == N:\n return calc_mp(uselista,uselistb,uselistc)\n mplist = []\n u0 = uselist0 + [l[i]]\n ua = uselista + [l[i]]\n ub = uselistb + [l[i]]\n uc = uselistc + [l[i]]\n mplist.append(DFS(i+1, u0,uselista,uselistb,uselistc))\n mplist.append(DFS(i+1, uselist0,ua,uselistb,uselistc))\n mplist.append(DFS(i+1, uselist0,uselista,ub,uselistc))\n mplist.append(DFS(i+1, uselist0,uselista,uselistb,uc))\n return min(mplist)\n\n\ndef calc_mp(uselista,uselistb,uselistc):\n mp = 0\n \n mp += (max(len(uselista) - 1, 0)) * 10\n mp += (max(len(uselistb) - 1, 0)) * 10\n mp += (max(len(uselistc) - 1, 0)) * 10\n\n \n mp += abs(A - sum(uselista))\n mp += abs(B - sum(uselistb))\n mp += abs(C - sum(uselistc))\n\n if len(uselista)==0:\n mp += infty\n if len(uselistb)==0:\n mp += infty\n if len(uselistc)==0:\n mp += infty\n return mp\n\nprint(DFS(0,[],[],[],[]))', '\nN, A, B, C =map(int,input().split())\nl = []\nfor i in range(N):\n a = input()\n l.append(a)\n\ndef DFS(i,uselist0,uselista,uselistb,uselistc):\n if i == N:\n uselist = [uselist0,uselista,uselistb,uselistc]\n return calc_mp(uselist)\n mplist = []\n u0 = uselist0 + [l[i]]\n ua = uselista + [l[i]]\n ub = uselistb + [l[i]]\n uc = uselistc + [l[i]]\n mplist.append(DFS(i+1, u0,uselista,uselistb,uselistc))\n mplist.append(DFS(i+1, uselist0,ua,uselistb,uselistc))\n mplist.append(DFS(i+1, uselist0,uselista,ub,uselistc))\n mplist.append(DFS(i+1, uselist0,uselista,uselistb,uc))\n return min(mplist)\n\n\ndef calc_mp(uselist):\n mp = 0\n\n \n mp += (max(len(uselist[1]) - 1, 0)) * 10\n mp += (max(len(uselist[2]) - 1, 0)) * 10\n mp += (max(len(uselist[3]) - 1, 0)) * 10\n\n \n mp += abs(A - sum(uselist[1]))\n mp += abs(B - sum(uselist[2]))\n mp += abs(C - sum(uselist[3]))\n\n return mp\n\nprint(DFS(0,[],[],[],[]))', '\n\n\n# A = 90, L! = [40,30,21] -> 20 + 1\nimport copy as cp\ninf = 10**9\ndef cost(li, length):\n if len(li)==0:\n return inf\n return (len(li)-1)*10 + abs(sum(li)-length)\n\ndef search_cost(ln,assignment,length):\n# from IPython.core.debugger import Pdb; Pdb().set_trace()\n if len(ln)==0:\n costA = cost(assignment["A"], length[0])\n costB = cost(assignment["B"], length[1])\n costC = cost(assignment["C"], length[2])\n return costA + costB + costC\n val = ln[-1]\n candidate = []\n for take in assignment.keys():\n nextdic = cp.deepcopy(assignment)\n nextdic[take].append(val)\n cand = search_cost(ln[:-1],nextdic,length)\n candidate.append(cand)\n return min(candidate)\n \n \n\nN, A, B, C =map(int,input().split())\nlength = [A,B,C]\nln = []\nassignment = {"A":[],"B":[],"C":[],"D":[]}\n\nfor i in range(N):\n a = int(input())\n ln.append(a)\n \nprint(search_cost(ln,assignment,length))\n\n']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s497534545', 's626296828', 's982305622', 's797984681']
[9332.0, 3064.0, 3152.0, 3700.0]
[2089.0, 192.0, 18.0, 1676.0]
[1170, 1123, 988, 1153]
p03111
u875361824
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['def main():\n N, A, B, C = map(int, input().split())\n ls = [int(input()) for _ in range(N)]\n\n tmp = []\n from itertools import permutations\n for a, b, c in permutations([A, B, C]):\n x = f(N, a, b, c, ls)\n tmp.append(x)\n\n ans = min(tmp)\n print(ans)\n\n\ndef f(N, A, B, C, ls):\n \n ls = ls[:]\n abc = [A, B, C]\n\n ans = 0\n for x in abc[:]:\n if x in ls:\n abc.remove(x)\n ls.remove(x)\n\n while abc:\n x = abc[0]\n diffs = [l - x for l in ls]\n # print(abc, ans, ls, diffs)\n \n if x in ls:\n ls.remove(x)\n abc.remove(x)\n continue\n\n \n i, diff = min(enumerate(diffs), key=lambda a: abs(a[0]))\n min_cost = abs(diff)\n if min_cost <= 10:\n ans += min_cost\n del ls[i]\n del abc[0]\n continue\n\n \n if len(ls) < 2:\n ans += abs(ls[0] - x)\n abc.remove(x)\n del ls[0]\n continue\n\n \n comb = []\n n_ls = len(ls)\n for i in range(n_ls):\n for j in range(i+1, n_ls):\n comb.append((i, j, ls[i] + ls[j]))\n\n 前後のコスト比較\n i, j, new_l = min(comb, key=lambda b: abs(b[2] - x))\n # print("\\t", [c[2] for c in comb])\n \n cost = abs(x - new_l)\n if cost >= min_cost:\n del_idx = min(i, j, key=lambda idx: abs(ls[idx]) - x)\n ans += min_cost\n del ls[del_idx]\n del abc[0]\n else:\n ls[i] = new_l\n del ls[j]\n ans += 10\n\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n', 'def main():\n N, A, B, C = map(int, input().split())\n ls = [int(input()) for _ in range(N)]\n\n ans = editorial(N, A, B, C, ls)\n print(ans)\n\n\ndef editorial(N, A, B, C, ls):\n def dfs(cur, a, b, c):\n if cur == N:\n if min([a, b, c]) > 0:\n \n tmp = abs(a - A) + abs(b - B) + abs(c - C) - 30\n else:\n tmp = float("inf")\n # print(tmp, a, b, c, sep="\\t")\n return tmp\n\n \n d = ls[cur]\n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + d, b, c) + 10\n ret2 = dfs(cur + 1, a, b + d, c) + 10\n ret3 = dfs(cur + 1, a, b, c + d) + 10\n\n return min([ret0, ret1, ret2, ret3])\n\n ans = dfs(0, 0, 0, 0)\n return ans\n\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Accepted']
['s505763746', 's834175008']
[3192.0, 3064.0]
[19.0, 86.0]
[2111, 943]
p03111
u879870653
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N,A,B,C = map(int,input().split())\nL = list(int(input()) for i in range(N))\n\ndef f(cur,a,b,c) :\n if cur == N :\n if min(a,b,c) > 0 :\n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else :\n return float("inf")\n ret0 = f(cur+1,a,b,c)\n ret1 = f(cur+1,a+L[cur],b,c) + 10\n ret2 = f(cur+1,a,b+L[cur],c) + 10\n ret3 = f(cur+1,a,b,c+L[cur]) + 10\n return min(ret0,ret1,ret2,ret3)\n \nprint(f(0,\n ', 'from itertools import *\n\nN,a,b,c = map(int,input().split())\nL = [int(input()) for i in range(N)]\n\nans = float("inf")\n\nproducts = product(range(4), repeat=N)\n\nfor prod in products :\n A = []\n B = []\n C = []\n \n for i,v in enumerate(prod) :\n if v == 1 :\n A.append(L[i])\n elif v == 2 :\n B.append(L[i])\n elif v == 3 :\n C.append(L[i])\n \n if len(A) * len(B) * len(C) == 0 :\n continue\n \n cost = 0\n \n for li in [A, B, C] :\n cost += (len(li)-1) * 10\n \n cost += abs(a-sum(A))\n cost += abs(b-sum(B))\n cost += abs(c-sum(C))\n \n ans = min(ans, cost)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s523072206', 's229995380']
[3064.0, 3192.0]
[17.0, 305.0]
[444, 665]
p03111
u883203948
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['data = input().split()\nN = int(data[0])\nA = int(data[1])\nB = int(data[2])\nC = int(data[3])\n\ni = 0\nkd = []\nwhile i < N:\n kd.append(int(input()))\n i += 1\n\n\ncur = 0 \nsc = 0\ndef ans(n,a,b,c):\n if cur == N:\n return abs(a-A) + abs(b-B)+ abs(c-C) - 30 if min(a,b,c) > 0 else 1000000\n ret0 = ans(cur+1,a,b,c)\n ret1 = ans(cur+1,a+kd[cur],b,c) + 10\n ret2 = ans(cur + 1,a,b+kd[cur],c) +10 \n ret3 = ans(cur+1,a,b,c+kd[cur])+ 10\n return min(ret0,ret1,ret2,ret3)\n\nprint(ans(0,0,0,0))\n \n \n\n \n ', 'data = input().split()\nN = int(data[0])\nA = int(data[1])\nB = int(data[2])\nC = int(data[3])\n\ni = 0\nkd = []\nwhile i < N:\n kd.append(int(input()))\n i += 1\n\n\ncur = 0 \nsc = 0\ndef ans(cur,a,b,c):\n if cur == N:\n return abs(a-A) + abs(b-B)+ abs(c-C) - 30 if min(a,b,c) > 0 else 1000000\n ret0 = ans(cur+1,a,b,c)\n ret1 = ans(cur+1,a+kd[cur],b,c) + 10\n ret2 = ans(cur + 1,a,b+kd[cur],c) +10 \n ret3 = ans(cur+1,a,b,c+kd[cur])+ 10\n return min(ret0,ret1,ret2,ret3)\n\nprint(ans(0,0,0,0))\n \n \n\n \n \n']
['Runtime Error', 'Accepted']
['s886240217', 's091070112']
[3960.0, 3064.0]
[79.0, 74.0]
[503, 506]
p03111
u887207211
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(x, a, b, c):\n if x == N:\n if min(a, b, c) >= 30:\n print(a, b, c)\n return abs(a-A)+abs(b-B)+abs(c-C)-30\n else:\n return float("inf")\n \n ret0 = dfs(x+1, a, b, c)\n ret1 = dfs(x+1, a+l[x], b, c)+10\n ret2 = dfs(x+1, a, b+l[x], c)+10\n ret3 = dfs(x+1, a, b, c+l[x])+10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'N, A, B, C = map(int,input().split())\nl = [int(input()) for _ in range(N)]\n\ndef dfs(x, a, b, c):\n if x == N:\n if min(a, b, c) > 0:\n return abs(a-A)+abs(b-B)+abs(c-C)-30\n else:\n return float("inf")\n \n ret0 = dfs(x+1, a, b, c)\n ret1 = dfs(x+1, a+l[x], b, c)+10\n ret2 = dfs(x+1, a, b+l[x], c)+10\n ret3 = dfs(x+1, a, b, c+l[x])+10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Wrong Answer', 'Accepted']
['s251841821', 's696207194']
[4044.0, 3064.0]
[150.0, 79.0]
[432, 409]
p03111
u909991537
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import numpy as np\nN, A, B, C = (int(i) for i in input().split()) \nl = [int(input()) for i in range(N)] \n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else np.inf\n \n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n if cur == 1:\n print(a, b, c, ret0, ret1, ret2, ret3)\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))', 'import numpy as np\nN, A, B, C = (int(i) for i in input().split()) \nl = [int(input()) for i in range(N)] \n\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A) + abs(b-B) + abs(c-C) - 30 if min(a, b, c) > 0 else np.inf\n \n ret0 = dfs(cur + 1, a, b, c)\n ret1 = dfs(cur + 1, a + l[cur], b, c) + 10\n ret2 = dfs(cur + 1, a, b + l[cur], c) + 10\n ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0, 0, 0, 0))']
['Wrong Answer', 'Accepted']
['s510387464', 's765658970']
[12148.0, 12260.0]
[208.0, 207.0]
[511, 453]
p03111
u917733926
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef cost(index, a,b,c):\n if index == N:\n return (abs(a-A) + abs(b-B) + abs(c-C) - 30) if min(a,b,c) > 0 else INF\n ret0 = cost(index+1, a,b,c)\n ret1 = cost(index+1, a+l[index],b,c) + 10\n ret2 = cost(index+1, a,b+l[index],c) + 10\n ret3 = cost(index+1, a,b,c+l[index]) + 10\n return min(ret0, ret1, ret2, ret3) + 10\n\nprint(cost(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef cost(index, a,b,c):\n if index == N:\n return (abs(a-A) + abs(b-B) + abs(c-C) - 30) if min(a,b,c) > 0 else INF\n ret0 = cost(index+1, a,b,c)\n ret1 = cost(index+1, a+l[index],b,c)\n ret2 = cost(index+1, a,b+l[index],c)\n ret3 = cost(index+1, a,b,c+l[index])\n return min(ret0, ret1, ret2, ret3)\n\nprint(cost(0,0,0,0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\nINF = 10 ** 9\n\ndef cost(index, a,b,c):\n if index == N:\n return (abs(a-A) + abs(b-B) + abs(c-C) - 30) if min(a,b,c) > 0 else INF\n ret0 = cost(index+1, a,b,c)\n ret1 = cost(index+1, a+l[index],b,c) + 10\n ret2 = cost(index+1, a,b+l[index],c) + 10\n ret3 = cost(index+1, a,b,c+l[index]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(cost(0,0,0,0))']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s847427926', 's872895066', 's223496701']
[3064.0, 3064.0, 3064.0]
[72.0, 73.0, 72.0]
[449, 429, 444]
p03111
u923270446
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,a,b,c=map(int,input().split())\nl=[int(input())for i in range(n)]\ndef dfs(i,x,y,z):\n if i==n:return abs(a-x)+abs(b-y)+abs(c-z)-30if a+b+c>=3else 10**9+7\n A,B,C,D=dfs(i+1,x,y,z),dfs(i+1,x+l[i],y,z)+10,dfs(i+1,x,y+l[i],z)+10,dfs(i+1,x,y,z+l[i])+10\n return min(A,B,C,D)\nprint(dfs(0,0,0,0)', 'n,a,b,c=map(int,input().split())\nl=[int(input())for _ in range(n)]\ndef dfs(i,x,y,z):\n if i==n:return abs(a-x)+abs(b-y)+abs(c-z)-30if min(x,y,z)>0else 10**9\n return min(dfs(i+1,x,y,z),dfs(i+1,x+l[i],y,z)+10,dfs(i+1,x,y+l[i],z)+10,dfs(i+1,x,y,z+l[i])+10)\nprint(dfs(0,0,0,0))']
['Runtime Error', 'Accepted']
['s666381530', 's252371409']
[8864.0, 9160.0]
[24.0, 67.0]
[286, 272]
p03111
u932719058
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['# review\nimport copy\nn, a, b, c = map(int, input().split())\nlList = []\n\nfor _ in range(n) :\n lList.append(int(input()))\n\nlList.sort()\ngoal = [a, b, c]\ngoal.sort()\n\ndef removed(i,j) :\n goal.remove(i)\n lList.remove(j)\n\nmp = 0\ndef pick(x, y) : # if same value & goal < lList\n mp = 0\n for i in copy.copy(x) :\n for j in copy.copy(y) :\n if i == j and i in goal:\n removed(i,j)\n for i in copy.copy(x) :\n for j in copy.copy(y) :\n if i < j and i in goal:\n mp += j - i \n removed(i,j)\n\npick(goal,lList) \n\n\ndiffList = []\ndiff = 10\nfor j in lList :\n for i in goal :\n if abs(i-j) < 10 :\n diff = min(diff, abs(i-j))\n if diff != 10 :\n diffList.append([diff, i, j])\n diff = 10\nfor i in diffList : \n mp += i[0] \n goal.remove(i[1])\n lList.remove(i[2])\n\nadd2 = []\nfor i in lList :\n for j in lList[i+1:] :\n add2.append(i + j, i, j)\n# ------------------------------------------------------\n# addList = []\n# diff = 10\n# for j in add2 :\n\n# if abs(i-j[0]) < 10 :\n\n\n# diffList.append([diff, i, j[0]])\n# diff = 10\n\n# mp += i[0] \n# goal.remove(i[1])\n# lList.remove(i[2])\n\n\n \nprint(mp)\n', '# review\nN,A,B,C = map(int,input().split())\nL = [int(input()) for _ in range(N)]\n \ndef f(i,a,b,c):\n if i == N:\n if min(a, b, c) <= 0:\n return 10**9\n return abs(a-A)+abs(b-B)+abs(c-C)-30\n costx = f(i+1,a,b,c)\n costA = f(i+1,a+L[i],b,c)+10\n costB = f(i+1,a,b+L[i],c)+10\n costC = f(i+1,a,b,c+L[i])+10\n return min(costx,costA,costB,costC)\n \nprint(f(0,0,0,0))']
['Runtime Error', 'Accepted']
['s600541325', 's469067706']
[3444.0, 3064.0]
[22.0, 69.0]
[1614, 397]
p03111
u932868243
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["import itertools\nA,B,C,n=map(int,input(),split())\nl=[int(input()) for i in range(n)]\nll=[]\nfor p in itertools.product(['A','B','C','Z'].repeat=n):\n ans=0\n a=0\n b=0\n c=0\n for i in range(n):\n if p[i]=='A':\n a+=l[i]\n elif p[i]=='B':\n b+=l[i]\n elif p[i]=='C':\n c+=l[i]\n ans+=(abs(a-A)+abs(B-b)+abs(C-c))\n ll.append(ans)\nprint(min(ans))\n", "import itertools\nn,a,b,c=map(int,input().split())\nl=[int(input()) for i in range(n)]\nans=100000\nfor p in itertools.product(['A','B','C','Z'],repeat=n):\n if list(p).count('A')>=1 and list(p).count('B')>=1 and list(p).count('C')>=1:\n for i in range(n):\n la=0\n lb=0\n lc=0\n if p[i]=='A':\n la+=p[i]\n elif p[i]=='B':\n lb+=p[i]\n elif p[i]=='C':\n lc+=p[i]\n ans=min(ans,abs(la-a)+abs(lb-b)+abs(lc-c))\nprint(ans)", "import itertools\nn,A,B,C=map(int,input().split())\nl=[int(input()) for i in range(n)]\nll=[]\nfor p in itertools.product(['A','B','C','Z'],repeat=n):\n ans=0\n a=0\n b=0\n c=0\n numa=0\n numb=0\n numc=0\n for i in range(n):\n if p[i]=='A':\n a+=l[i]\n numa+=1\n elif p[i]=='B':\n b+=l[i]\n numb+=1\n elif p[i]=='C':\n c+=l[i]\n numc+=1\n ans+=(abs(a-A)+abs(B-b)+abs(C-c)+(numa+numb+numc-3)*10)\n if all(nn!=0 for nn in [numa,numb,numc]):\n ll.append(ans)\nprint(min(ll))"]
['Runtime Error', 'Runtime Error', 'Accepted']
['s015798759', 's303304112', 's645785780']
[3064.0, 3064.0, 5040.0]
[17.0, 18.0, 321.0]
[363, 462, 498]
p03111
u933341648
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input() for i in range(n))]\ninf = 10**4\n\ndef bamboo_connect(i, a, b, c):\n if i == N:\n if all(a, b, c):\n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n return inf\n no_connect = bamboo_connect(i+1, a, b, c)\n choice_a = bamboo_connect(i+1, a+l[i], b, c) + 10\n choice_b = bamboo_connect(i+1, a, b+l[i], c) + 10\n choice_c = bamboo_connect(i+1, a, b, c+l[i]) + 10\n return min(no_connect, choice_a, choice_b, choice_c)\n\nprint(bamboo_connect(0, 0, 0, 0))', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for i in range(N)]\ninf = 10**4\n\ndef bamboo_connect(i, a, b, c):\n if i == N:\n if all((a, b, c)):\n return abs(a-A) + abs(b-B) + abs(c-C) - 30\n else:\n return inf\n no_connect = bamboo_connect(i+1, a, b, c)\n choice_a = bamboo_connect(i+1, a+l[i], b, c) + 10\n choice_b = bamboo_connect(i+1, a, b+l[i], c) + 10\n choice_c = bamboo_connect(i+1, a, b, c+l[i]) + 10\n return min(no_connect, choice_a, choice_b, choice_c)\n\nprint(bamboo_connect(0, 0, 0, 0))']
['Runtime Error', 'Accepted']
['s622177042', 's541967856']
[3064.0, 3064.0]
[17.0, 64.0]
[552, 554]
p03111
u934868410
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nans = 10000\nfor i in range(2 ** (2*n)):\n v = [0,0,0,0]\n assign = [(i>>(2*j)) & 3 for j in range(n)]\n for j in range(n):\n v[assign[j]] += l[j] + (v[assign[j]] > 0) * 10\n if v[1] == 0 or v[2] == 0 or v[3] == 0:\n continue\n ans = min(ans, abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))\nprint(ans)', 'n,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nans = 10000\nfor i in range(2 ** (2*n)):\n v = [0,0,0,0]\n assign = [(i>>(2*j)) & 3 for j in range(n)]\n for j in range(n):\n v[assign[j]] += l[j]\n if v[1] == 0 or v[2] == 0 or v[3] == 0:\n continue\n ans = min(ans, abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))\nprint(ans)', 'n,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nans = 10000\nfor i in range(2 ** (2*n)):\n v = [0,0,0,0]\n assign = [(i>>(2*j)) & 3 for j in range(n)]\n cost = 0\n for j in range(n):\n is v[assign[j]] > 0:\n cost += 10\n v[assign[j]] += l[j]\n if v[1] == 0 or v[2] == 0 or v[3] == 0:\n continue\n ans = min(ans, cost + abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))\nprint(ans)', 'n,a,b,c = map(int,input().split())\nl = [int(input()) for _ in range(n)]\nans = 10000\nfor i in range(2 ** (2*n)):\n v = [0,0,0,0]\n assign = [(i>>(2*j)) & 3 for j in range(n)]\n cost = 0\n for j in range(n):\n if assign[j] > 0 and v[assign[j]] > 0:\n cost += 10\n v[assign[j]] += l[j]\n if v[1] == 0 or v[2] == 0 or v[3] == 0:\n continue\n ans = min(ans, cost + abs(v[1]-a) + abs(v[2]-b) + abs(v[3]-c))\nprint(ans)']
['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s019915668', 's530384853', 's804632595', 's972445983']
[3064.0, 3064.0, 2940.0, 3064.0]
[406.0, 321.0, 17.0, 458.0]
[369, 343, 403, 421]
p03111
u941434715
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['#coding: utf-8\nimport math\nimport heapq\nimport bisect\nimport numpy as np\n#from scipy.misc import comb\n\nN,A,B,C = map(int, input().split())\n\nL = []\nfor i in range(N):\n l = int(input())\n L.append(l)\n\nans = 10**9\n\nfor i in range(1<<(2*N)):\n a = b = c = 0\n tmp = 0\n for j in range(N):\n flg = 0\n if i&(1<<(2*j)):\n flg += 1\n if i&(1<<(2*j+1)):\n flg += 2\n\n if flg == 1:\n if a:\n tmp += 10\n a += L[j]\n elif flg == 2:\n if b:\n tmp += 10\n b += L[j]\n elif flg == 3:\n if c:\n tmp += 10\n c += L[j]\n print(tmp)\n\n if a*b*c==0:\n continue\n\n tmp += abs(A-a)+abs(B-b)+abs(C-c)\n ans = min(ans,tmp)\n\nprint(ans)\n', '#coding: utf-8\nimport math\nimport heapq\nimport bisect\nimport numpy as np\n#from scipy.misc import comb\n\nN,A,B,C = map(int, input().split())\n\nL = []\nfor i in range(N):\n l = int(input())\n L.append(l)\n\nans = 10**9\n\nfor i in range(1<<(2*N)):\n a = b = c = 0\n tmp = 0\n for j in range(N):\n flg = 0\n if i&(1<<(2*j)):\n flg += 1\n if i&(1<<(2*j+1)):\n flg += 2\n\n if flg == 1:\n if a:\n tmp += 10\n a += L[j]\n elif flg == 2:\n if b:\n tmp += 10\n b += L[j]\n elif flg == 3:\n if c:\n tmp += 10\n c += L[j]\n\n if a*b*c==0:\n continue\n\n tmp += abs(A-a)+abs(B-b)+abs(C-c)\n ans = min(ans,tmp)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s235691381', 's113394773']
[19436.0, 12932.0]
[1009.0, 572.0]
[800, 781]
p03111
u941753895
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['import itertools\n\nn,a,b,c=map(int,input().split())\nl0=[a,b,c]\nl0.sort()\nl02=l0[:]\nl02.reverse()\nl=[]\nfor i in range(n):\n x=int(input())\n if l0.count(x)>0:\n l0.remove(x)\n else:\n l.append(x)\nif len(l0)==0:\n print(0)\n exit()\nl.sort()\nll=l[:]\n\ncst1=0\nl2=[]\nfor i in l0:\n if i<l[0]:\n cst1=l[0]-i\n l.remove(l[0])\n else:\n p=100000000000000\n r=[]\n for j in range(1,len(l)+1):\n for k in list(itertools.combinations(l,j)):\n q=abs(i-sum(k))+(j-1)*10\n if q<p:\n p=q\n r=k\n l2.append(tuple([r,p]))\n for j in r:\n l.remove(j)\nfor i in l2:\n cst1+=i[1]\nprint(cst1)', 'import itertools\n\nn,a,b,c=map(int,input().split())\nl0=[a,b,c]\nl0.sort()\nl02=l0[:]\nl02.reverse()\nl=[]\nfor i in range(n):\n x=int(input())\n if l0.count(x)>0:\n l0.remove(x)\n else:\n l.append(x)\nif len(l0)==0:\n print(0)\n exit()\nl.sort()\nll=l[:]\n\ncst1=0\nl2=[]\nfor i in l0:\n if i<l[0]:\n cst1=l[0]-i\n l.remove(l[0])\n else:\n p=100000000000000\n r=[]\n for j in range(1,len(l)+1):\n for k in list(itertools.combinations(l,j)):\n q=abs(i-sum(k))+(j-1)*10\n if q<p:\n p=q\n r=k\n l2.append(tuple([r,p]))\n for j in r:\n l.remove(j)\nfor i in l2:\n cst1+=i[1]\n\ncst2=0\nl2=[]\nfor i in l02:\n if len(ll)>0 and i<ll[0]:\n cst2=ll[0]-i\n ll.remove(ll[0])\n else:\n p=100000000000000\n r=[]\n for j in range(1,len(ll)+1):\n for k in list(itertools.combinations(ll,j)):\n q=abs(i-sum(k))+(j-1)*10\n if q<p:\n p=q\n r=k\n l2.append(tuple([r,p]))\n for j in r:\n ll.remove(j)\nfor i in l2:\n cst2+=i[1]\nprint(cst1,cst2)\nprint(min(cst1,cst2))', 'import itertools\n\nn,a,b,c=map(int,input().split())\nl0=[a,b,c]\nl0.sort()\nl02=l0[:]\nl02.reverse()\nl=[]\nfor i in range(n):\n x=int(input())\n if l0.count(x)>0:\n l0.remove(x)\n else:\n l.append(x)\nif len(l0)==0:\n print(0)\n exit()\nll=l[:]\n\ncst1=0\nl2=[]\nfor i in l0:\n if i<min(l):\n cst1=min(l)-i\n l.remove(min(l))\n else:\n p=100000000000000\n r=[]\n for j in range(1,len(l)+1):\n for k in list(itertools.combinations(l,j)):\n q=abs(i-sum(k))+(j-1)*10\n if q<p:\n p=q\n r=k\n l2.append(tuple([r,p]))\n for j in r:\n l.remove(j)\nfor i in l2:\n cst1+=i[1]\nprint(cst1)', 'import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\ndd=[(-1,0),(0,1),(1,0),(0,-1)]\nddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n\ndef LI(): return [int(x) for x in sys.stdin.readline().split()]\n# def LF(): return [float(x) for x in sys.stdin.readline().split()]\ndef I(): return int(sys.stdin.readline())\ndef F(): return float(sys.stdin.readline())\ndef LS(): return sys.stdin.readline().split()\ndef S(): return input()\n\nn,a,b,c=LI()\nl=[I() for _ in range(n)]\n\ndef dfs(cnt,aa,bb,cc):\n if cnt==n:\n if aa==0 or bb==0 or cc==0:\n return inf\n return abs(aa-a)+abs(bb-b)+abs(cc-c)-30\n\n aaa=dfs(cnt+1,aa+l[cnt],bb,cc)+10\n bbb=dfs(cnt+1,aa,bb+l[cnt],cc)+10\n ccc=dfs(cnt+1,aa,bb,cc+l[cnt])+10\n ddd=dfs(cnt+1,aa,bb,cc)\n return min(aaa,bbb,ccc,ddd)\n\nprint(dfs(0,0,0,0))\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s134330745', 's160415984', 's831100989', 's910506996']
[3064.0, 3188.0, 3064.0, 10712.0]
[18.0, 18.0, 18.0, 71.0]
[622, 1032, 619, 861]
p03111
u953237709
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
["from sys import setrecursionlimit\nsetrecursionlimit(1000000)\n\ndef permute(a, idx):\n if idx == len(a):\n permutations.append(a[::])\n for i in range(idx, len(a)):\n a[i], a[idx] = a[idx], a[i]\n permute(a, idx + 1)\n a[i], a[idx] = a[idx], a[i]\n\ndef doit(a, b, c, idx):\n if (a, b, c, idx) in memo:\n return memo[a, b, c, idx]\n if idx == len(unused):\n return abs(a - needA) + abs(b - needB) + abs(c - needC)\n memo[a, b, c, idx] = min(\n doit(a, b, c, idx + 1),\n doit(a + unused[idx], b, c, idx + 1) + 10,\n doit(a, b + unused[idx], c, idx + 1) + 10,\n doit(a, b, c + unused[idx], idx + 1) + 10\n )\n return memo[a, b, c, idx]\n\nn, needA, needB, needC = map(int, input().split())\na = [int(input()) for _ in range(n)]\nret = float('inf')\nfor mask in range(1 << n):\n if bin(mask).count('1') != 3:\n continue\n abc = [a[i] for i in range(n) if (mask >> i) & 1]\n unused = [a[i] for i in range(n) if not (mask >> i) & 1]\n permutations = []\n permute(abc, 0)\n for p in permutations:\n \tmemo = {}\n ret = min(ret, doit(p[0], p[1], p[2], 0))\nprint(ret)\n", "from itertools import permutations\nfrom sys import setrecursionlimit\nsetrecursionlimit(1000000)\n\ndef doit(a, b, c, idx):\n if (a, b, c, idx) in memo:\n return memo[a, b, c, idx]\n if idx == len(unused):\n return abs(a - needA) + abs(b - needB) + abs(c - needC)\n memo[a, b, c, idx] = min(\n doit(a, b, c, idx + 1),\n doit(a + unused[idx], b, c, idx + 1) + 10,\n doit(a, b + unused[idx], c, idx + 1) + 10,\n doit(a, b, c + unused[idx], idx + 1) + 10\n )\n return memo[a, b, c, idx]\n\nn, needA, needB, needC = map(int, input().split())\na = [int(input()) for _ in range(n)]\nret = float('inf')\nfor mask in range(1 << n):\n if bin(mask).count('1') != 3:\n continue\n abc = [a[i] for i in range(n) if (mask >> i) & 1]\n unused = [a[i] for i in range(n) if not (mask >> i) & 1]\n for p in permutations(abc):\n memo = {}\n ret = min(ret, doit(p[0], p[1], p[2], 0))\nprint(ret)"]
['Runtime Error', 'Accepted']
['s034570178', 's976114978']
[3064.0, 3188.0]
[17.0, 326.0]
[1152, 938]
p03111
u955251526
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['n, k = map(int, input().split())\nx = list(map(int, input().split()))\nmintime = 10**20\nfor i in range(n-k+1):\n left = x[i]\n right = x[i+k-1]\n abss = (abs(left), abs(right))\n if left * right >= 0:\n mintime = min(mintime, max(abss))\n else:\n mintime = min(mintime, min(abss) * 2 + max(abss))\nprint(mintime)\n', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\ndef bintoset(b):\n ret = set()\n for i in range(N):\n if b & 1 == 1:\n ret.add(l[i])\n b = b >> 1\n return ret\ndef cost(b, x):\n s = bintoset(b)\n return abs(x - sum(s)) + (len(s) - 1) * 10\nmincost = 10 ** 10\ncount = 0\nfor a in range(1, 1 << N):\n for b in range(1, (1 << N) - a):\n if b & a == 0:\n for c in range(1, (1 << N) - a - b):\n if c & (a+b) == 0 and a * b * c != 0:\n mincost = min(mincost, cost(a, A) + cost(b, B) + cost(c, C))\n count += 1\nprint(mincost)\nprint(count)\n', 'n, k = map(int, input().split())\nx = list(map(int, input().split()))\nmintime = 10**20\nfor i in range(n-k+1):\n left = x[i]\n right = x[i+k-1]\n abss = (abs(left), abs(right))\n if left * right >= 0:\n mintime = min(mintime, max(abss))\n else:\n mintime = min(mintime, min(abss) * 2 + max(abss))\nprint(mintime)\n', 'n, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(n)]\ninf = 10 ** 10\ndef dfs(k, a, b, c):\n if k == n:\n if 0 in (a,b,c):\n return inf\n return abs(A - a) + abs(B - b) + abs(C - c) - 30\n ret = [0] * 4\n ret[0] = dfs(k+1, a + l[k], b, c) + 10\n ret[1] = dfs(k+1, a, b + l[k], c) + 10\n ret[2] = dfs(k+1, a, b, c + l[k]) + 10\n ret[3] = dfs(k+1, a, b, c)\n return min(ret)\nprint(dfs(0, 0, 0, 0))\n']
['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted']
['s574568941', 's750487335', 's883896473', 's774013452']
[3060.0, 3064.0, 3060.0, 3064.0]
[19.0, 420.0, 17.0, 66.0]
[332, 657, 332, 453]
p03111
u963903527
2,000
1,048,576
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively. Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number: * Extension Magic: Consumes 1 _MP_ (magic point). Choose one bamboo and increase its length by 1. * Shortening Magic: Consumes 1 MP. Choose one bamboo of length at least 2 and decrease its length by 1. * Composition Magic: Consumes 10 MP. Choose two bamboos and combine them into one bamboo. The length of this new bamboo is equal to the sum of the lengths of the two bamboos combined. (Afterwards, further magics can be used on this bamboo.) At least how much MP is needed to achieve the objective?
['N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A)+abs(b-B)+abs(c-C) if min(a,b,c) > 0 else return 10**8\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a+l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b+l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c+l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\nprint(dfs(0,0,0,0))\n\n\n\n\n', 'N, A, B, C = map(int, input().split())\nl = [int(input()) for _ in range(N)]\ndef dfs(cur, a, b, c):\n if cur == N:\n return abs(a-A)+abs(b-B)+abs(c-C)-30 if min(a,b,c) > 0 else 10**9\n ret0 = dfs(cur+1, a, b, c)\n ret1 = dfs(cur+1, a+l[cur], b, c) + 10\n ret2 = dfs(cur+1, a, b+l[cur], c) + 10\n ret3 = dfs(cur+1, a, b, c+l[cur]) + 10\n return min(ret0, ret1, ret2, ret3)\n\nprint(dfs(0,0,0,0))']
['Runtime Error', 'Accepted']
['s858785348', 's971028043']
[2940.0, 3064.0]
[18.0, 72.0]
[401, 393]