Woburn Challenge 2002
Cow-Bot was a success! With him roaming the streets of Scarberia gathering valuable information about the monkeys, Bo Vine feels very secure, and decides to throw a party for the cows. Bo invites all the dignitaries to his shindig, including the always popular Hugh Heifer who arrives with his escorts, Bessie and Jersey. Once the party is in full gear, however, Bo realizes that there remains a flaw with Cow-Bot: He forgot to program the instructions for him to return home!
This is a cow-tastrophe! Should Cow-Bot fall into the wrong hoofs, there
could potentially be a coup attempt, for he who controls Cow-Bot, is
automatically anointed the leader of the cows! Bo Vine cannot allow this
to happen. He summons his best warrior, and informs him of the plan: The
warrior will begin at a stepping-stone

From the figure, we see that the Party Hall is located at one end of this one-dimensional "street". The markers represent stones, a fixed distance apart. Note that the warrior only jumps in one direction. Note also that the warrior initially starts off at a stone and keeps jumping even if he doesn't land on a stone.
Input Specification
The first line of input contains a single integer
Each test case consists of a single line containing
Output Specification
A single integer that is the distance Cow-Bot is from the party hall.
Sample Input
2
2 3 4
-3 2 5
Sample Output
14
7
Comments