Codeforces Round #520 (Div. 2) A. A Prank 好题

时间:2023-02-07 16:59:33


A. A Prank

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array a1a1, a2a2, ..., anan of integers, such that 1≤a1<a2<…<an≤1031≤a1<a2<…<an≤103, and then went to the bathroom.

JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range [1,103][1,103].

JATC wonders what is the greatest number of elements he can erase?

Input

The first line of the input contains a single integer nn (1≤n≤1001≤n≤100) — the number of elements in the array.

The second line of the input contains nn integers aiai (1≤a1<a2<⋯<an≤1031≤a1<a2<⋯<an≤103) — the array written by Giraffe.

Output

Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.

If it is impossible to erase even a single element, print 00.

Examples

input

Copy


6 1 3 4 5 6 9


output

Copy


2


input

Copy


3 998 999 1000


output

Copy


2


input

Copy


5 1 2 3 4 5


output

Copy


4


Note

In the first example, JATC can erase the third and fourth elements, leaving the array [1,3,_,_,6,9][1,3,_,_,6,9]. As you can see, there is only one way to fill in the blanks.

In the second example, JATC can erase the second and the third elements. The array will become [998,_,_][998,_,_]. Because all the elements are less than or equal to 10001000, the array is still can be restored. Note, that he can't erase the first 22 elements.

In the third example, JATC can erase the first 44 elements. Since all the elements are greater than or equal to 11, Giraffe can still restore the array. Note, that he can't erase the last 44 elements.


分析:

这题主要是理解题意,给你个递增的数列,让你删除连续的元素(就是因为这个没A,不要以为可以删多处的的元素)仍然可以推出原数组。

我们会发现有三种情况可以推出原数组,

1.删除一串连续数中间的数

6

1 3 4 5 6

删4,5

2.开头为从1开始连续的数,可以删最后一个连续数之前的所有数

5

1 2 3 4 5

删1 2 3 4

2.结尾为从1000开始向前连续的数,可以删最后一个连续数之后的所有数

3

998 999 1000

删999 1000

 

最后,三种情况取最小值

#include<cstdio>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<functional>
#include<cstring>
#include<string>
#include<cstdlib>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<map>
using namespace std;
const int N=1000;
typedef long long ll;
int n,m;
int a[N];
int main()
{
scanf("%d",&n);
int p1=1,p2=n;

for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]==i)
{
p1=i;
}

}
for(int i=n;i>=1;i--)
{
if(n-i==(1000-a[i]))
{
p2=i;
}
}

int k=0,sum=0;
sum=max(p1-1,n-p2);

//cout<<p1<<" "<<p2<<endl;
for(int i=p1;i<p2;i++)
{
if(a[i]+1==a[i+1])
{
k++;
}
else
{
//cout<<k<<endl;
k-=1;
if(k>=0)
sum=max(sum,k);
k=0;
}
if(i==p2-1&&a[i]+1==a[i+1])
{
k-=1;
if(k>=0)
sum=max(sum,k);
k=0;
}
}
cout<<sum<<endl;
return 0;
}