A Prank

版权声明:来自星空计算机团队——申屠志刚 https://blog.csdn.net/weixin_43272781/article/details/84131908

https://codeforces.com/contest/1062/problem/A

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

6
1 3 4 5 6 9

output

2

input

3
998 999 1000

output

2

input

5
1 2 3 4 5

output

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.

#include <iostream>
#include <stdio.h>
#include <map>
using namespace std;
int n;
int a[1000];
int main()
{
    scanf("%d",&n);
    int maxl=0;
    int tmp=0;
    int cnt=0;
    int ans=0;
    int l=1,r=1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(tmp+1==a[i]){
            tmp=a[i];
            cnt++;
        }else{
        if(maxl<cnt){
            l=i-cnt;
            r=i-1;
            maxl=cnt;
        }
        cnt=1;
        tmp=a[i];
        }

    }
     if(maxl<cnt||(maxl==cnt&&a[n]==1000)){
            l=n-cnt+1;
            r=n;
            maxl=cnt;
    }
    //cout << maxl << endl;
    if(l==1&&a[1]==1||r==n&&a[n]==1000)
        cout << maxl-1 << endl;
    else{
        if(maxl>=3)
        cout << maxl-2 << endl;
        else
        cout << 0 << endl;
    }

    //cout << "Hello world!" << endl;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43272781/article/details/84131908
今日推荐