AIOC Banner

Problem: Pygmy Hippos

Want to try solving this problem? You can submit your code online if you log in or register.


Pygmy Hippos

Input File: hippoin.txt
Output File: hippoout.txt
Time Limit: 1 second

Your backyard has been overrun by adorably tiny hippos, and they are eating the daisies!


You have a line of N daisies, labelled from 1 to N. There are three hippos standing next to different daisies ...and they are already eating them! If you don't act fast, they will eat all the daisies in your garden.

You have enough plywood to build up to three fences. Each fence will be built between two daisies that are next to each other. Hippos cannot go through fences (or over them, or under them, or around them).

Once you have built your fences, the hippos will roam back and forth along the line of daisies, eating all the daisies they can reach without crossing your fences. What is the greatest number of daisies you can save?

Input

Your program should read from the file hippoin.txt.

Output

Your program should write to the file hippoout.txt. Your output file should contain one line with one integer: the greatest number of daisies you can save.

Sample Input 1

9
2
5
7

Sample Input 2

3
1
2
3

Sample Output 1

4

Sample Output 2

0

Explanation

In the first sample case, as illustrated above, if we put a fence between daisies 2 and 3, between daisies 4 and 5 and between daisies 7 and 8, no hippo will be able to reach daisies 3, 4, 8 or 9. There is no placement of fences that will save more daisies, so 4 is the correct answer.


In the second sample case, no matter where you place the three fences you will not save any daisies, as they are all being eaten.

Constraints

To evaluate your solution, the judges will run your program against several different input files. All of these files will adhere to the following bounds:

 


Privacy statement
© Australian Mathematics Trust 2001-2024

Contact: training@orac.amt.edu.au
Page generated: 28 March 2024, 11:54pm AEDT