# 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

• The first line of input will contain one integer N: the number of daisies.
• The next three lines will each contain an integer describing which daisy one hippo is currently eating. These will be in increasing order. No two hippos start at the same daisy.

### 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.

```9
2
5
7
```

```3
1
2
3
```

```4
```

```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:

• 3 ≤ N ≤ 1,000,000

Privacy statement
`Page generated: 25 March 2023,  7:35pm AEDT`