Woburn Challenge 2001 - Suicidal
It's Wednesday night and the remaining frosh (the ones that haven't been kicked off) are having a little fun inside the Waterloo compound (i.e. inside the convex polygonal fence previously described) arranged by their frosh leaders as a way to unwind. They are divided into groups and each group is given a map of the fence. Each vertex of the fence has a number on it and they are told the following things.
Along the path connecting any vertices, there are exactly
tokens
(where
is the multiplicative product of the
numbers on the end
vertices). Each token entitles the group to have an extra
hour of fun
during the week. The goal is to divide the entire intra-fence region
into triangles in the following way:
- The vertices of the triangles have to be vertices of the original polygonal fence.
- The triangles that the group chooses to form are determined by which
paths the group decides to choose (the paths mark the sides of the
triangle). If they choose a path, they pick up all the tokens on
that path. Clearly, since the vertices of the triangles have to be
vertices of the original fence, the group cannot choose
paths that cross each other.
See the accompanying drawing for an example of a correct triangulation (shown in bold).
These are all the instructions that the group is given. What they don't know is that this is not really a game. They are being watched by the leaders to determine which group will triangulate the field by choosing paths that allow them to pick up the least number of tokens, i.e. which group will decide to have the least fun. The leaders realize that all good engineers eschew fun and thus, the groups that instinctively choose to have the least fun are best qualified for the program. The rest are kicked out.
You are in one of these groups. You don't like fun (hey, you're writing this contest on a summer day, aren't you?) and want to determine the least amount of fun your group can have, i.e. what is the least number of tokens that a group can pick up and still triangulate the field.
Input Specification
(number of vertices in the fence;
denotes end of input;
).
The next line will contain , the numbers assigned to the
th vertex.
(natural numbers).
Output Specification
The least number of tokens that can be picked up.
Sample Input
5
1 1 3 2 4
-1
Sample Output
4
Comments