PEG 11/12 Programming Test 1 - October 19

Problem 1: Cyclopian Air

The upscale clothing company FurWear has recently expanded to the planet of Cyclopia. Cyclopia, however, does not have an atmosphere with oxygen, something that the workers producing FurWear products require to work. (They need food and water too, but they can figure that out on their own!) The Oelfinn, as the dominant species of Cyclopia, have a ready supply of oxygen, but they aren't willing to give it away freely. They do have a love of puzzles, however.

The Oelfinn have placed some numbers on some cards arranged in a circle, and will allow FurWear to pick one pair of adjacent cards. The Oelfinn are willing to give FurWear an amount of oxygen proportional to the product of the numbers on said cards.

Obviously, FurWear would like to maximise the amount of oxygen they receive, and have turned to you to help. Your task is to write a program that will find the largest product of any two adjacent numbers, which will then be stored on a chip implanted into a peon.

Input

The first line consists of a single integer N (8 ≤ N ≤ 10 000). The following N lines each contain a single integer ai (0 ≤ ai ≤ 30 000), the number on the ith card. The numbers will be given from the northernmost card, then clockwise all the way around.

Output

On a single line, output the maximum product of any two adjacent numbers.

Sample Input

10
2
5
6
12
76
0
200
1
32
14

Sample Output

912

All Submissions
Best Solutions


Point Value: 3
Time Limit: 2.00s
Memory Limit: 16M
Added: Oct 17, 2011
Author: jargon

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

Comments (Search)

Messing up the first test case. I read the other comment, but I've tried to use the advice jargon gave. Also, is there any way I'm allowed to share my code?

there is no way for you to share code in public under this circumstances and this situation, and I will give you the same hint as jargon, Think carefully about the definition of "adjacent", if you can't solve it, oh well, just take a break and come back, not every problem is intended to be solved in a short amount time or intended for YOU to be able to solve it on the spot

Why doesn't my code work for the first test case? Can someone please help me?

Think carefully about the definition of "adjacent."

Thank you so much!