B. 剩菜 Leftovers

Memory limit: 256 MiB Time limit: 1000 ms Input file: stdin Output file: stdout
Problem type: traditional Judging mode: text compare

Description

今天是愛麗絲的生日!為了慶祝生日,她去了一間高檔餐廳吃晚餐。由於這是她第一次去高檔餐廳吃晚餐,她感到十分興奮,所以點了很多食物。

可是,她發現她點了太多食物,她沒有辦法吃光它們。由於桌上有太多剩菜,她又不想浪費食物,她決定把剩菜打包,留到以後在家吃。

為了打包食物,愛麗絲向侍應拿了一些打包盒。她有 b_1 個可以載 1 單位食物的打包盒, b_2 個可以載 2 單位食物的打包盒, b_4 個可以載 4 單位食物的打包盒和 b_6 個可以載 6 單位食物的打包盒。桌上有 N 道菜,第 i 道菜還剩下 p_i (1 \le p_i \le 6) 單位的食物。

她想按照下面的規則盡可能打包更多單位的食物:

  1. 對於每一道菜,你只能打包整道菜或不打包整道菜。此外,同一道菜的每一個單位的食物必須打包到同一個打包盒。例如:你不能打包一道有 6 單位食物的菜到兩個只能載 4 單位食物的打包盒或打包 6 單位其中的 4 單位食物到一個打包盒。
  2. 打包一道菜到打包盒時,打包盒的容量必須不少於那道菜的食物單位。例如:你不能打包一道有 5 單位食物的菜到一個只能載 4 單位食物的打包盒。
  3. 你可以打包多於一道菜到同一個打包盒。可是,由於愛麗絲不喜歡不同菜的醬汁混在一起,當多於一道菜打包到同一個打包盒時,為了保持不同菜之間的距離,必須留下打包盒一半的容量。例如:當你打包一道有 1 單位食物的菜和一道有 3 單位食物的菜到一個只能載 6 單位食物的打包盒時,由於打包盒會只剩下 2 單位食物的容量,少於打包盒原本一半的容量,所以你不能這樣做。

她想知道她可以盡可能打包多少單位的食物。你能幫幫她嗎?


Today is Alice's birthday! To celebrate it, she went to a high-end restaurant to have dinner. As it was her first time having dinner in an expensive restaurant, she felt very excited and ordered a lot of foods.

However, she found that she has ordered too many foods and she could not finish all of them. As there are too many leftovers on the table and she does not want to waste them, she decided to wrap the leftovers up and eat them at home in the future.

Alice has got some to-go boxes from the server for the leftovers. She has b_1 to-go boxes that can hold 1 unit of foods, b_2 to-go boxes that can hold 2 units of foods, b_4 to-go boxes that can hold 4 units of foods, and b_6 to-go boxes that can hold 6 units of foods. There are also N dishes that Alice cannot finish. For the i^{\text{th}} dish, there is p_i units of food left. (1 \le p_i \le 6)

She is trying to wrap up as many units of food as possible following these rules:

  1. For each dish, you can only pack the whole dish or not pack the dish. Also, every unit of the same dish must be packed into the same to-go box. E.g., you cannot pack a dish with 6 units into two to-go boxes with a capacity of 4 units or pack 4 out of 6 units of a dish into a to-go box.
  2. To pack a dish into a to-go box, the capacity of the to-go box must not be less than the units of the dish. E.g., you cannot pack a dish with 5 units into a to-go box with a capacity of 4 units.
  3. You may pack multiple dishes into the same to-go box. However, as Alice does not like the sauces of dishes mixed together, if more than one kind of dish is packed into the same to-go box, half of the capacity of the to-go box must remain empty to keep distance between different dishes. E.g., you cannot pack a dish with 1 unit and a dish with 3 units into a to-go box with a capacity of 6 units, as there are only 2 units of capacity remaining, which is less than half of the original capacity of the to-go box.

She wants to know what is the maximum amount of units of foods she can wrap up. Can you help her?

Input

第一行有五個整數 N , b_1 , b_2 , b_4 b_6 ,菜的數量和能載 1 2 4 6 單位食物的打包盒的數量。

第二行有 N 個整數 p_i ,愛麗絲吃剩的第 i 道菜的單位。


The first line consists of 5 integers: N , b_1 , b_2 , b_4 , and b_6 . These integers represent the number of dishes and the number of to-go boxes with capacities of 1 , 2 , 4 , and 6 units, respectively.

The second line contains N integers p_i , the number of units of the i^{th} dish that Alice cannot finish.

Output

輸出一個整數,愛麗絲可以打包的最大食物單位數量。


Output an integer, the maximum amount of units of foods that Alice can wrap up.

Sample

Sample 1 input

4 0 0 2 0
1 1 2 3

Sample 1 output

5

Sample 2 input

4 0 0 0 2
2 2 1 1

Sample 2 output

6

Sample explanation

樣例 1︰分別打包第三和第四道菜到能載 4 單位食物的打包盒。

樣例 2︰打包第一和第三道菜到一個能載 6 單位食物的打包盒,然後打包剩餘的到另一個能載 6 單位食物的打包盒。

Sample 1: Pack the 3^\text{rd} and 4^\text{th} dish into 4 -unit to-go boxes, respectively.

Sample 2: Pack the 1^\text{st} and 3^\text{rd} dish into a 6 -unit to-go box, and pack the rest into another 6 -unit to-go box.

Constraint and hint

對於全部測試數據,滿足: 1 \le N \le 1000000 0 \le b_1, b_2, b_4, b_6 \le 1000000 1 \le p_i \le 6

子任務 分數 附加限制
1 18 N \leq 100 , p_i = 1
2 21 N \leq 100 , b_1 = b_2 = b_4 = 0
3 23 N \leq 100 , p_i \geq 3
4 22 N \leq 100
5 16 無附加限制

For all test data, 1 \le N \le 1000000 , 0 \le b_1, b_2, b_4, b_6 \le 1000000 , 1 \le p_i \le 6 .

Subtask Score Additional Constraints
1 18 N \leq 100 , p_i = 1
2 21 N \leq 100 , b_1 = b_2 = b_4 = 0
3 23 N \leq 100 , p_i \geq 3
4 22 N \leq 100
5 16 No additional constraints