All submissions for this problem are available.
The story of Harry Potter begins when Lord Voldemort arrives at his house at Privet Drive. Harry's house has N rooms placed in one line. Each room has its own energy level and no two rooms have exactly same energy. Lord Voldemort arrives at the room which has lowest energy while Harry is at the room having highest energy.
Lord Voldemort has to reach Harry's room. Voldemort can travel from a room having energy X to any other room having energy Y such that |X-Y| is minimum and that room hasn't been visited before. The energy required for moving from room having energy X to room having energy Y is X*Y.
Since Lord Voldemort is busy practicing Avada Kedavra to kill Harry, so he asks you to find the energy required to reach Harry's room.
- The first line of input contains 1 integer N denoting the number of rooms.
- The second line contains N space separated integers denoting energy levels of each room.
Print the required energy.
- 2 ≤ N ≤ 1000
- 1 ≤ Ei ≤ 10000
Input: 3 4 2 1 Output: 10
Lord Voldemort arrives at room 3 and Harry is in room 1.
Total energy consumed = 1*2 + 2*4 = 10.
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions