Under construction

Still being built. Things may change

Black and White Chef

Time limit1sMemory limit1024 MB

Summary
Given N steaks with thicknesses up to 25, find the minimum total grilling time so that both sides of every steak are cooked the same number of times and for the same total time.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Math
Solved
No attempts yet

Problem

Seonghyeon joined a cooking competition and received this harsh review:

This sirloin was grilled badly. The meat was not cooked even.

He entered the competition again the next season and decided to cook the meat even this time. But he misunderstood the meaning of even, and he plans to grill each steak an even number of times. In other words, both sides of each steak must be grilled the same number of times, at least once. Both sides must also be grilled for the same amount of time.

To grill a steak of thickness xx, one side must be grilled for exactly xx minutes and then flipped. The steak cannot be flipped before xx minutes have passed, and it cannot be left unflipped after xx minutes have passed.

At minute 00, Seonghyeon puts all NN steaks on the grill and starts grilling them at the same time. He cannot remove any steak from the grill during cooking, and when he finishes, all NN steaks must be cooked evenly.

Overcooked meat gets tough, so Seonghyeon wants to finish grilling all the steaks as quickly as possible while meeting these conditions. How many minutes must he grill the steaks?

Input

The first line contains the number of steaks NN. (1≤N≤200 000)(1 \leq N \leq 200\,000)

The second line contains the thickness of each steak, a positive integer xix_i, separated by spaces. (1≤xi≤25)(1 \leq x_i \leq 25)

Output

Print the minimum time, in minutes, that Seonghyeon needs to grill all the steaks evenly.

Hint

For C/C++, use the 64-bit integer type long long, since the answer can exceed the range of the 32-bit int type.

Examples3

  1. Example 1

    Input
    3
    1 2 3
    
    Expected output
    12
    
  2. Example 2

    Input
    4
    1 3 5 7
    
    Expected output
    210
    
  3. Example 3

    Input
    9
    9 11 13 15 17 19 21 23 25
    
    Expected output
    3346393050