Doghouses
Practice
3.8 (29 votes)
Easy
Problem
82% Success 4461 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
  • Russian version of the problem can be read here.

As you probably know, cats usually fight with dogs.

There are N doghouses in a backyard. For simplicity, we consider the backyard as a plane, and the doghouses as points on the plane. All doghouses are numbered from 1 to N. The i-th doghouse is located at point (i, Y[i]). (Note that this means that there are no two doghouses with the same x-coordinate.)

Cats are about to build some rectangular fence, parallel to the axis. If some doghouse is located at the perimeter of the fence, it should be removed. Your task it to find the maximum possible number of doghouses that may be removed after choosing arbitrary fence sizes and location. Please note that the area covered by the fence may be equal to 0.

Input format

The first line of the input contains the single integer N - the number of doghouses. The next line contains N space-separated integers that are Y-coordinates of the corresponding doghouse.

Output format

In the only line of the output print the maximum number of doghouses that may be removed.

Constraints

1 ≤ N ≤ 1,000, 0 ≤ Y[i] ≤ 1,000.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
Binary SearchAlgorithms
Points:30
58 votes
Tags:
AlgorithmsEasyMonthly-ContestReady
Points:30
20 votes
Tags:
Binary SearchEasySearching