Woburn Challenge 2015-16 Round 3 - Junior Division

Having found the battle predictions to be inconclusive, Batman has decided to employ another powerful weapon to guarantee his victory against Superman – electricity! After all, the man of steel should be a good conductor.
Although Batman is a genius-level physicist, it doesn't take a genius to know that a stupendous amount of energy is required to bring down a being who draws his power from the sun. Clearly, the quantity of energy to weaken Superman is too massive to be stored and carried around in the Batmobile. Through a stroke of brilliancy, he realized that he could simply tap into the city's power grid. So his plan is as follows: Batman will engineer his mech-suit to conduct electricity without doing any harm to himself, the wearer. When the time is right, Batman will plug the suit into any point in the power grid that he will have hooked up before the battle. Then, he will grip both hands onto Superman's body (closing the circuit) and direct an immense wave of electricity through the man of steel.
The challenge of this plan is all in the preparation: properly wiring up
the city's power grid to the street on which the battle will take place.
Batman already knows the location of the battle, and he knows that on
that street, there are
For example, if there are
_
_ |_|_
|_|_|_|_|
|_|_|_|_|
Each horizontal and vertical unit of wiring will require the same length
of wire. For example, the above structure will require
Input Specification
The first line will contain a single integer
The second line will contain
Output Specification
Output a single integer, the length of wires required to build the circuit, in units.
Sample Input
4
2 1 3 2
Sample Output
24
Comments