#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    if(n<3){
        cout<<"False\n";
    }
    else{
        int count=0;
        for(int i=1;i<n;i++){
            if(abs(a[i]-a[i-1])==1){
                count++;
            }
        }
        if(count>=3){
            cout<<"True\n";
        }
        else{
            int back_count=0;
            for(int i=n-1;i>=0;i--){
                if(abs(a[i]-a[i-1])==1){
                    back_count++;
                }
            }
            if(back_count>=3){
                cout<<"True\n";
            }
            else{
                cout<<"False\n";
            }
        }
    }
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: