#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <math.h>
#include <sstream>
#include <complex>
#include <string.h>
#include <algorithm>
using namespace std;

void solve();
#define mp make_pair
#define pb push_back
typedef int fknmain;
typedef long long int li;
/**
 CAUTION Is int really int?
 *
 Real solution after main function
 */
//#define int li
typedef pair<int, int> pi;
//typedef vector<int> vi;
typedef double ld;

fknmain main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    //freopen("output", "w", stdout);
#define LL "%lld"
#else
#define LL "%I64d"
#endif
#ifndef int
#define INT "%d"
#else
#define INT LL
#endif
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    solve();
    return 0;
}

struct vi{

    int l;
    int ans[5005];
    vi(){
        l=0;
    }
    int size(){
        return l;
    }
    bool empty(){
        return l==0;
    }

    void pop_back(){
        --l;
    }
    void push_back(int k){
        ans[l++]=k;
    }

    int operator[] (int k){
        return ans[k];
    }

    int* begin(){
        return ans;
    }

    int* end(){
        return ans+l;
    }

};
vi g[5555];
int used[5555];
vi ans;

int dfs(int v) {
    used[v] = 1;
    for (int i = 0; i < (int) g[v].size(); ++i) {
        if (used[g[v][i]] == 0) {
            int p = dfs(g[v][i]);
            if (p != -1) {
                if ((p == -2) || (p == v)) {
                    return -2;
                }
                ans.pb(v);
                return p;
            }
        } else if (used[g[v][i]] == 1) {
            ans.pb(g[v][i]);
            ans.pb(v);
            return g[v][i];
        }

    }
    used[v] = 2;
    return -1;
}
char s[5555][5555];

void solve() {

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> s[i][j];
            if (s[i][j] == '1')
                g[i].pb(j);
        }
    }
    for (int i = 0; i < n && ans.empty(); ++i) {
        if (!used[i])
            dfs(i);
    }
    if (ans.empty()) {
        cout << "-1";
        return;
    }
    reverse(ans.begin(), ans.end());
    //cout<<endl;
    //for(int i=0;i<ans.size();++i)
    //  cout<<ans[i]<<' ';
    //cout<<endl;
    while (ans.size() > 3) {
        if (s[ans[0]][ans[ans.size() - 2]] == '1') {
            cout << ans[0] + 1 << ' ' << ans[ans.size() - 2] + 1 << ' ' << ans[ans.size()-1] + 1;
            return;
        }
        ans.pop_back();
    }

    cout << ans[0] + 1 << ' ' << ans[1] + 1 << ' ' << ans[2] + 1;
}


#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <math.h>
#include <sstream>
#include <complex>
#include <string.h>
#include <algorithm>
using namespace std;

void solve();
#define mp make_pair
#define pb push_back
typedef int fknmain;
typedef long long int li;
/**
 CAUTION Is int really int?
 *
 Real solution after main function
 */
//#define int li
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef double ld;

fknmain main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    //freopen("output", "w", stdout);
#define LL "%lld"
#else
#define LL "%I64d"
#endif
#ifndef int
#define INT "%d"
#else
#define INT LL
#endif
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    solve();
    return 0;
}

struct vim{

    int l;
    int ans[5005];
    vim(){
        l=0;
    }
    int size(){
        return l;
    }
    bool empty(){
        return l==0;
    }

    void pop_back(){
        --l;
    }
    void push_back(int k){
        ans[l++]=k;
    }

    int operator[] (int k){
        return ans[k];
    }

    int* begin(){
        return ans;
    }

    int* end(){
        return ans+l;
    }

};
vi g[5555];
int used[5555];
vi ans;

int dfs(int v) {
    used[v] = 1;
    for (int i = 0; i < (int) g[v].size(); ++i) {
        if (used[g[v][i]] == 0) {
            int p = dfs(g[v][i]);
            if (p != -1) {
                if ((p == -2) || (p == v)) {
                    return -2;
                }
                ans.pb(v);
                return p;
            }
        } else if (used[g[v][i]] == 1) {
            ans.pb(g[v][i]);
            ans.pb(v);
            return g[v][i];
        }

    }
    used[v] = 2;
    return -1;
}
char s[5555][5555];

void solve() {

    int n;
    scanf("%d",&n);
    for (int i = 0; i < n; ++i) {
        scanf(" %s ",s[i]);
        for (int j = 0; j < n; ++j) {

            if (s[i][j] == '1')
                g[i].pb(j);
        }
    }
    for (int i = 0; i < n && ans.empty(); ++i) {
        if (!used[i])
            dfs(i);
    }
    if (ans.empty()) {
        cout << "-1";
        return;
    }
    reverse(ans.begin(), ans.end());
    //cout<<endl;
    //for(int i=0;i<ans.size();++i)
    //  cout<<ans[i]<<' ';
    //cout<<endl;
    while (ans.size() > 3) {
        if (s[ans[0]][ans[ans.size() - 2]] == '1') {
            cout << ans[0] + 1 << ' ' << ans[ans.size() - 2] + 1 << ' ' << ans[ans.size()-1] + 1;
            return;
        }
        ans.pop_back();
    }

    cout << ans[0] + 1 << ' ' << ans[1] + 1 << ' ' << ans[2] + 1;
}


#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <math.h>
#include <sstream>
#include <complex>
#include <string.h>
#include <algorithm>
using namespace std;

void solve();
#define mp make_pair
#define pb push_back
typedef int fknmain;
typedef long long int li;
/**
 CAUTION Is int really int?
 *
 Real solution after main function
 */
//#define int li
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef double ld;

fknmain main() {
#ifdef DEBUG
    freopen("input", "r", stdin);
    //freopen("output", "w", stdout);
#define LL "%lld"
#else
#define LL "%I64d"
#endif
#ifndef int
#define INT "%d"
#else
#define INT LL
#endif
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    solve();
    return 0;
}

struct vim{

    int l;
    int ans[5005];
    vim(){
        l=0;
    }
    int size(){
        return l;
    }
    bool empty(){
        return l==0;
    }

    void pop_back(){
        --l;
    }
    void push_back(int k){
        ans[l++]=k;
    }

    int operator[] (int k){
        return ans[k];
    }

    int* begin(){
        return ans;
    }

    int* end(){
        return ans+l;
    }

};
vi g[5555];
int used[5555];
vi ans;

int dfs(int v) {
    used[v] = 1;
    for (int i = 0; i < (int) g[v].size(); ++i) {
        if (used[g[v][i]] == 0) {
            int p = dfs(g[v][i]);
            if (p != -1) {
                if ((p == -2) || (p == v)) {
                    return -2;
                }
                ans.pb(v);
                return p;
            }
        } else if (used[g[v][i]] == 1) {
            ans.pb(g[v][i]);
            ans.pb(v);
            return g[v][i];
        }

    }
    used[v] = 2;
    return -1;
}
char s[5555][5555];

void solve() {

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            scanf("%d",&s[i][j]);
            if (s[i][j] == '1')
                g[i].pb(j);
        }
    }
    for (int i = 0; i < n && ans.empty(); ++i) {
        if (!used[i])
            dfs(i);
    }
    if (ans.empty()) {
        cout << "-1";
        return;
    }
    reverse(ans.begin(), ans.end());
    //cout<<endl;
    //for(int i=0;i<ans.size();++i)
    //  cout<<ans[i]<<' ';
    //cout<<endl;
    while (ans.size() > 3) {
        if (s[ans[0]][ans[ans.size() - 2]] == '1') {
            cout << ans[0] + 1 << ' ' << ans[ans.size() - 2] + 1 << ' ' << ans[ans.size()-1] + 1;
            return;
        }
        ans.pop_back();
    }

    cout << ans[0] + 1 << ' ' << ans[1] + 1 << ' ' << ans[2] + 1;
}


#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>

#define DEBUG 0

using namespace std;

char mx[5000][5001];

/*int findC(int from, int to,int sum){
    int i,root=to;
    tra[root] = true;
    for(i=0;i<nd[root].size();i++){
        int nei = nd[root][i];
        if(DEBUG)printf("findC: edge %d %d\n", root, nei);
        if(nei==from) continue;
          if(tra[nei]){
            if(sum==2){if(DEBUG) printf("find cycle: %d %d\n", to, nei);isc.push_back(root); return 1;}
            else continue;
        }
        if(sum<2 && findC(to, nei, sum+1)){isc.push_back(root);  return 1;}
    }
    tra[root] = false;          //pass
    return 0;
}*/
bool findC(int start, vector<int>cur){
    if(cur.size()<3)    return false;
    int i,j;
    vector<int>in,out;
    //if(DEBUG)printf("findc %d\n",start);
    for(i=0;i<cur.size();i++){
        if(cur[i]==start)continue;
        if(mx[start][cur[i]] == '0') in.push_back(cur[i]);
        else out.push_back(cur[i]);
    }
    for(i=0;i<in.size();i++)
        for(j=0;j<out.size();j++)
            if(mx[out[j]][in[i]]=='1') {
                /*if(DEBUG)printf("in %d start %d out %d\n", in[i], start, out[j]);
                isc[0] = in[i]+1;
                isc[1] = start+1;
                isc[2] = out[j]+1;*/
                printf("%d %d %d\n",in[i]+1, start+1, out[j]+1);
                return 1;
            }
    if(in.size()>=3 && findC(in[rand()%in.size()], in)){
        in.clear();
        out.clear();
        return 1;
    }
    in.clear();
    if(out.size()>=3 && findC(out[rand()%out.size()], out)){
        out.clear();
        return 1;
    }
    in.clear();
    out.clear();
    return 0;
}
/*int getNum(){
    int i;
    vector<int>cur;
    for(i=0;i<n;i++)
        cur.push_back(i);
    if(findC(rand()%n, cur)){
        for(i=0;i<2;i++)
            printf("%d ", isc[i]);
        printf("%d", isc[2]);
    }
    else printf("-1");
    return 0;
}*/
int main(){
    int n;
    scanf("%d", &n);
    getchar();

    for(int i = 0; i < n; i++){
        for(int j = 0 ;j < n; j++)
            mx[i][j] = getchar();
        getchar();
    }
    srand(time(NULL));
    //if(DEBUG)printf("getnum\n");
    vector<int>cur;
    for(int i=0;i<n;i++)
        cur.push_back(i);

    if(!findC((rand()%n), cur)) puts("-1");
    //getNum();
    return 0;
}


import java.util.Scanner;

public class Codeforces602B_Approximating_a_Constant_Range {
//    static boolean isConstant(int[] a, int i, int j){
//        boolean result = true;
//        for (int  k = i;  k <= j;  k++) {
//            for (int l = i; l <= j; l++) {
//                if(k==l) continue;
//                if(Math.abs(a[k]-a[l])>1){
//                    result = false;
//                    break;
//                }
//            }
//        }
//        return result;
//    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[1000050];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int x = scanner.nextInt();
            a[x]++;
            a[x-1]++;
            a[x+1] = 0;
            if(x!=1) a[x-2] = 0;
            ans = Math.max(ans, a[x]);
            ans = Math.max(ans, a[x-1]);
        }
        System.out.println(ans);
//        int n = 2781;
//        int[] a = new int[n];
//        for (int i = 0; i < n; i++) {
//            a[i] = 64961;
//        }
//        int i = 0; int j = 0;
//        int thisSum = 0;
//        int maxSum = 0;
//        while( i<n && j<n){
//            System.out.println(i+" "+j);
//            if(isConstant(a, i, j)){
//                j++;
//                thisSum++;
//            }else{
//                i++;
//                j = i;
//                thisSum = 0;
//            }
//            if(maxSum<thisSum)
//                maxSum = thisSum;
//        }
//        System.out.println(maxSum);
    }
}


import java.util.Scanner;

public class Codeforces602B_Approximating_a_Constant_Range {
    static boolean isConstant(int[] a, int i, int j){
//        System.out.println(i+" "+j);
        boolean result = true;
        for (int  k = i;  k <= j;  k++) {
            for (int l = i; l <= j; l++) {
                if(k==l) continue;
//                System.out.println(k+" "+l+" "+Math.abs(a[k]-a[l]));
                if(Math.abs(a[k]-a[l])>1){
                    result = false;
                    break;
                }
            }
        }
        return result;
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int i = 0; int j = 0;
        int thisSum = 0;
        int maxSum = 0;
        while( i<n && j<n){
            if(isConstant(a, i, j)){
                j++;
                thisSum++;
            }else{
                i++;
                j = i;
                thisSum = 0;
            }
            if(maxSum<thisSum)
                maxSum = thisSum;
        }
//        System.out.println(isConstant(a, 1, 4));
        System.out.println(maxSum);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    int M=0,flage=0,j=0,temp,up=0,down=0;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }

            if(M-temp==0) {up++;arr[j]++;down=0;}
            if(M-temp==1) {arr[j]++;up=0;down++;}
            if(M-temp==-1){
                j++;
                arr[j] =up+1;
                up=1;
                M=temp;
                down=0;
            }
            if(M-temp==2){
                M-=1;
                arr[j+1] = down +1;
                down = 1;
                j++;
                up=0;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            System.out.println( temp +"he "+n );
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }

            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
            if(M-temp==2){
                M-=1;
                System.out.println(arr[j] + " " + nom +"he " );
                arr[j+1] =  arr[j] - nom +1;
                nom = arr[j] - nom;
                j++;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }

            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
            if(M-temp==2){
                M-=1;
                arr[j+1] =  arr[j] - nom +1;
                nom = arr[j] - nom;
                j++;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }
            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }
            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n-1]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }

            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
            if(M-temp==2){
                M-=1;
                arr[j+1] =  arr[j] - nom +1;
                j++;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    int M=0,flage=0,j=0,temp,up=1,down=0;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }

            if(M-temp==0) {up++;arr[j]++;down=0;}
            if(M-temp==1) {arr[j]++;up=0;down++;}
            if(M-temp==-1){
                j++;
                arr[j] =up+1;
                up=1;
                M=temp;
                down=0;
            }
            if(M-temp==2){
                M-=1;
                arr[j+1] = down +1;
                down = 1;
                j++;
                up=0;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }
            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n-1]);
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Stack;

public class scorify{
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
    int n =in.nextInt();
    int[] arr = new int[n+1];
    TreeSet<Integer> set = new TreeSet<Integer>();
    int nom=1,M=0,flage=0,j=0,temp;

        for(int i=0 ; i<n ;i++){
            temp = in.nextInt();
            if(flage==0){
                M = temp;
                arr[j]++;
                flage=1;
                continue;
            }
            if(M-temp==0) {nom++;arr[j]++;}
            if(M-temp==1) {arr[j]++;}
            if(M-temp==-1){
                j++;
                arr[j]+=nom+1;
                nom=1;
                M=temp;
            }
            if(M-temp==2){
                M-=1;
                arr[j+1] =  arr[j] - nom +1;
                j++;
            }
        }
        Arrays.sort(arr);
        System.out.println(arr[n]);
	}
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

/**
*
* Codeforces Round #333 (Div 2) - B. Approximating a Constant Range
*
* In-progress
*
* @author Daniel
*
*/
public class B {

    static void solve() throws Exception {

        int n = nextInt();
        int[] a = readIntArray(n);

        int min = a[0];
        int max = a[0];
        int minIndex = 0;
        int maxIndex = 0;
        int longestRange = 1;
        int currentLength = 1;

        for (int i=1; i<n; i++) {
            int num = a[i];
            //Maintain everything is fine
            if (num == min || num == max)
                currentLength++;
            if (num == min)
                minIndex = i;
            if (num == max)
                maxIndex = i;
            //New max
            else if (num > max) {
                //Range is too long, re-adjust everything
                if (num - min > 1) {
                    currentLength = i - minIndex;
                    minIndex = maxIndex;
                    min = max;
                }
                else {
                    currentLength++;
                }
                max = num;
                maxIndex = i;
            }
            //New min
            else if (num < min) {
                if (max - num > 1) {
                    currentLength = i - maxIndex;
                    maxIndex = minIndex;
                    max = min;
                }
                else {
                    currentLength++;
                }
                min = num;
                minIndex = i;
            }
            longestRange = Math.max(longestRange, currentLength);
        }
        printf("%d\n", longestRange);
    }

    /*=============================================================================
     *                          STANDARD I/O TEMPLATE
     * ============================================================================
     */
    static BufferedReader in;
    static BufferedWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            out.flush();
            out.close();
            in.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    static void print(CharSequence str) throws IOException {
        out.write(str.toString());
    }

    static void println() throws IOException {
        out.write(System.lineSeparator());
    }

    static void println(CharSequence str) throws IOException {
        print(str);
        println();
    }

    static void printf(String format, Object... args) throws IOException {
        print(String.format(format, args));
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static String nextLine() throws IOException {
        if (tok == null || !tok.hasMoreTokens())
            return in.readLine();
        else
            return tok.nextToken("\n\r");
    }

    static int[] readIntArray(int n) throws IOException {
        int[] a = new int[n];
        for (int i=0; i<n; i++)
            a[i] = nextInt();
        return a;
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

/**
*
* Codeforces Round #333 (Div 2) - B. Approximating a Constant Range
*
* In-progress
*
* @author Daniel
*
*/
public class B {

    static void solve() throws Exception {

        int n = nextInt();
        int[] a = readIntArray(n);

        int min = a[0];
        int max = a[0];
        int minIndex = 0;
        int maxIndex = 0;
        int longestRange = 1;
        int currentLength = 1;

        for (int i=1; i<n; i++) {
            int num = a[i];
            //Maintain everything is fine
            if (num == min) {
                currentLength++;
                minIndex = i;
            }
            if (num == max) {
                currentLength++;
                maxIndex = i;
            }
            //New max
            else if (num > max) {
                //Range is too long, re-adjust everything
                if (num - min > 1) {
                    currentLength = i - minIndex;
                    minIndex = maxIndex;
                    min = max;
                }
                else {
                    currentLength++;
                }
                max = num;
                maxIndex = i;
            }
            //New min
            else if (num < min) {
                if (max - num > 1) {
                    currentLength = i - maxIndex;
                    maxIndex = minIndex;
                    max = min;
                }
                else {
                    currentLength++;
                }
                min = num;
                minIndex = i;
            }
            longestRange = Math.max(longestRange, currentLength);
        }
        printf("%d\n", longestRange);
    }

    /*=============================================================================
     *                          STANDARD I/O TEMPLATE
     * ============================================================================
     */
    static BufferedReader in;
    static BufferedWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            out.flush();
            out.close();
            in.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    static void print(CharSequence str) throws IOException {
        out.write(str.toString());
    }

    static void println() throws IOException {
        out.write(System.lineSeparator());
    }

    static void println(CharSequence str) throws IOException {
        print(str);
        println();
    }

    static void printf(String format, Object... args) throws IOException {
        print(String.format(format, args));
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static String nextLine() throws IOException {
        if (tok == null || !tok.hasMoreTokens())
            return in.readLine();
        else
            return tok.nextToken("\n\r");
    }

    static int[] readIntArray(int n) throws IOException {
        int[] a = new int[n];
        for (int i=0; i<n; i++)
            a[i] = nextInt();
        return a;
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

/**
*
* Codeforces Round #333 (Div 2) - B. Approximating a Constant Range
*
* In-progress
*
* @author Daniel
*
*/
public class B {

    static void solve() throws Exception {

        int n = nextInt();
        int[] a = readIntArray(n);

        int min = a[0];
        int max = a[0];
        int minIndex = 0;
        int maxIndex = 0;
        int longestRange = 1;
        int currentLength = 1;

        for (int i=1; i<n; i++) {
            int num = a[i];
            //Maintain everything is fine
            if (num == min) {
                currentLength++;
                minIndex = i;
            }
            else if (num == max) {
                currentLength++;
                maxIndex = i;
            }
            //New max
            else if (num > max) {
                //Range is too long, re-adjust everything
                if (num - min > 1) {
                    currentLength = i - minIndex;
                    minIndex = maxIndex;
                    min = max;
                }
                else {
                    currentLength++;
                }
                max = num;
                maxIndex = i;
            }
            //New min
            else if (num < min) {
                if (max - num > 1) {
                    currentLength = i - maxIndex;
                    maxIndex = minIndex;
                    max = min;
                }
                else {
                    currentLength++;
                }
                min = num;
                minIndex = i;
            }
            longestRange = Math.max(longestRange, currentLength);
        }
        printf("%d\n", longestRange);
    }

    /*=============================================================================
     *                          STANDARD I/O TEMPLATE
     * ============================================================================
     */
    static BufferedReader in;
    static BufferedWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            out.flush();
            out.close();
            in.close();
        } catch (Throwable e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    static void print(CharSequence str) throws IOException {
        out.write(str.toString());
    }

    static void println() throws IOException {
        out.write(System.lineSeparator());
    }

    static void println(CharSequence str) throws IOException {
        print(str);
        println();
    }

    static void printf(String format, Object... args) throws IOException {
        print(String.format(format, args));
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static String nextLine() throws IOException {
        if (tok == null || !tok.hasMoreTokens())
            return in.readLine();
        else
            return tok.nextToken("\n\r");
    }

    static int[] readIntArray(int n) throws IOException {
        int[] a = new int[n];
        for (int i=0; i<n; i++)
            a[i] = nextInt();
        return a;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[100001];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            if (arr[x - 1] > arr[x + 1]) {
                int temp = i - max(arr[x + 1], arr[x - 2]);
                result = max(result, temp);
            } else {
                int temp = i - max(arr[x + 2], arr[x - 1]);
                result = max(result, temp);
            }
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        if (n1 > n2) return n1;
        return n2;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[100003];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            result = arr[x - 1] > arr[x + 1] ?
                    max(result, i - max(0, arr[x - 2])) :
                    max(result, i - max(0, arr[x - 1]));
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        return n1 > n2 ? n1 : n2;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[100003];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            if (arr[x - 1] > arr[x + 1]) result = max(result, i - max(arr[x + 1], arr[x - 2]));
            else result = max(result, i - max(arr[x + 2], arr[x - 1]));
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        if (n1 > n2) return n1;
        return n2;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[1000001];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            if (arr[x - 1] > arr[x + 1]) {
                int temp = i - max(arr[x + 1], arr[x - 2]);
                result = max(result, temp);
            } else {
                int temp = i - max(arr[x + 2], arr[x - 1]);
                result = max(result, temp);
            }
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        if (n1 > n2) return n1;
        return n2;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[100002];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            if (arr[x - 1] > arr[x + 1]) result = max(result, i - max(arr[x + 1], arr[x - 2]));
            else result = max(result, i - max(arr[x + 2], arr[x - 1]));
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        if (n1 > n2) return n1;
        return n2;
    }
}


import java.util.Scanner;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        sc.nextLine();
        int[] arr = new int[100003];
        int result = 0;
        for (int i = 1; i <= n; i++) {
            int x = sc.nextInt();
            arr[x] = i;
            result = arr[x - 1] > arr[x + 1] ?
                    max(result, i - max(0, arr[x - 2])) :
                    max(result, i - max(arr[x + 2], 0));
        }
        sc.close();
        System.out.println(result);
    }

    private static int max(int n1, int n2) {
        return n1 > n2 ? n1 : n2;
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by puneet.goyal on 24/11/15.
 */
public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        String[] parts = br.readLine().trim().split("\\s");
        int[] array = new int[n];
        int lastValue = 0;
        for (int i = 0; i < n; i++) {
            int value = Integer.parseInt(parts[i]);
            if (i == 0) array[i] = 0;
            else {
                if (value == lastValue) array[i] = 0;
                else if (value < lastValue) array[i] = -1;
                else array[i] = 1;
            }
            lastValue = value;
        }

        int j=0;
        int lastChangeValue = 0;
        int answer = 0;
        for (int i = 0; i < n; i++) {
            if(array[i] == 1) {
                if(lastChangeValue == -1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i -1;
                }
                lastChangeValue = 1;
            } else if(array[i] == -1) {
                if(lastChangeValue == 1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i-1;
                }
                lastChangeValue = -1;
            }
        }
        if(n - j  > answer) answer = n - j ;
        System.out.println(answer);

    }
}


package codeforces;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by puneet.goyal on 24/11/15.
 */
public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        String[] parts = br.readLine().trim().split("\\s");
        int[] array = new int[n];
        int[] cumulative = new int[n];
        int lastValue = 0;
        for (int i = 0; i < n; i++) {
            int value = Integer.parseInt(parts[i]);
            if (i == 0) array[i] = 0;
            else {
                if (value == lastValue) array[i] = 0;
                else if (value < lastValue) array[i] = -1;
                else array[i] = 1;
            }
            lastValue = value;
            cumulative[i] += array[i];
        }

        int j=0;
        int lastChangeValue = 0;
        int lastChangeIndex = 0;
        int answer = 0;
        for (int i = 0; i < n; i++) {
            if(array[i] == 1) {
                if(lastChangeValue == -1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i -1;
                }
                lastChangeValue = 1;
                lastChangeIndex = i;
            } else if(array[i] == -1) {
                if(lastChangeValue == 1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i-1;
                }
                lastChangeValue = -1;
                lastChangeIndex = i;
            }
        }
        if(n - j  > answer) answer = n - j ;
        System.out.println(answer);

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * Created by puneet.goyal on 24/11/15.
 */
public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine().trim());
        String[] parts = br.readLine().trim().split("\\s");
        int[] array = new int[n];
        int lastValue = 0;
        for (int i = 0; i < n; i++) {
            int value = Integer.parseInt(parts[i]);
            if (i == 0) array[i] = 0;
            else {
                if (value == lastValue) array[i] = 0;
                else if (value < lastValue) array[i] = -1;
                else array[i] = 1;
            }
            lastValue = value;
        }

        int j=0;
        int lastChangeValue = 0;
        int answer = 0;
        for (int i = 0; i < n; i++) {
            if(array[i] == 1) {
                if(lastChangeValue == -1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i -1;
                    while(array[j] == 0) j--;
                }
                lastChangeValue = 1;
            } else if(array[i] == -1) {
                if(lastChangeValue == 1 || lastChangeValue == 0){

                } else {
                    int current = i - j;
                    if (current > answer) answer = current;
                    j = i-1;
                    while(array[j] == 0) j--;
                }
                lastChangeValue = -1;
            }
        }
        if(n - j  > answer) answer = n - j ;
        System.out.println(answer);

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static long max=-999;
    public static void main(String[] args) throws Exception {
           ModScanner ms=new ModScanner();
           int n=ms.nextInt();
           int[] a=new int[n];
           for(int i=0;i<n;i++)
               a[i]=ms.nextInt();
           func(a,0,n);
           System.out.println(max);
           }
        public static long func(int[] z,int a,int n){
            int p=z[a],q=-99,ind=0;
            long seq=0,flag=0;
            for(int i=a;i<n;i++){
              if(z[i]==p)
                   seq++;
              else if(z[i]==q){
                  seq++;
                  if(flag==0){
                      flag=1;
                      ind=i;
                  }
              }
              else if(q==-99){
                   if(z[i]-1==p||z[i]+1==p){
                       seq++;
                       q=z[i];
                       ind=i;
              }
              }
              else{
                  if(seq>max)
                      max=seq;

                   return func(z,ind,n);

              }
        }
            if(seq>max)
                max=seq;
            return max;
        }
}

    class ModScanner {
    BufferedReader br;
    StringTokenizer st;
    public ModScanner() {
    br = new BufferedReader(new InputStreamReader(System.in));
    }
    String nextToken() throws Exception {
    while (st == null || !st.hasMoreElements()) {
    st = new StringTokenizer(br.readLine());
    }
    return st.nextToken();
    }
    int nextInt() throws Exception, Exception {
    return Integer.parseInt(nextToken());
    }
    long nextLong() throws Exception {
    return Long.parseLong(nextToken());
    }
    double nextDouble() throws Exception {
    return Double.parseDouble(nextToken());
    }
    }


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static long max=-999;
    public static void main(String[] args) throws Exception {
           ModScanner ms=new ModScanner();
           int n=ms.nextInt();
           int[] a=new int[n];
           for(int i=0;i<n;i++)
               a[i]=ms.nextInt();
           func(a,0,n);
           System.out.println(max);
           }
        public static long func(int[] z,int a,int n){
            int p=z[a],q=-999,ind=0;
            long seq=0,flag=0;
            for(int i=a;i<n;i++){
              if(z[i]==p||z[i]==q)
                   seq++;

              else if(q==-999){
                   if(z[i]-1==p||z[i]+1==p){
                       seq++;
                       q=z[i];
                       ind=i;
              }
              }
              else{
                  if(seq>max)
                      max=seq;

                   return func(z,ind,n);

              }
        }
            if(seq>max)
                max=seq;
            return max;
        }
}

    class ModScanner {
    BufferedReader br;
    StringTokenizer st;
    public ModScanner() {
    br = new BufferedReader(new InputStreamReader(System.in));
    }
    String nextToken() throws Exception {
    while (st == null || !st.hasMoreElements()) {
    st = new StringTokenizer(br.readLine());
    }
    return st.nextToken();
    }
    int nextInt() throws Exception, Exception {
    return Integer.parseInt(nextToken());
    }
    long nextLong() throws Exception {
    return Long.parseLong(nextToken());
    }
    double nextDouble() throws Exception {
    return Double.parseDouble(nextToken());
    }
    }


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static int max=-999;
    public static void main(String[] args) throws Exception {
           ModScanner ms=new ModScanner();
           int n=ms.nextInt();
           int[] a=new int[n];
           for(int i=0;i<n;i++)
               a[i]=ms.nextInt();
           func(a,0,n);
           System.out.println(max);
           }
        public static int func(int[] z,int a,int n){
            int p=z[a],q=-99;
            int seq=0,ind=0,flag=0;
            for(int i=a;i<n;i++){
              if(z[i]==p)
                   seq++;
              else if(z[i]==q){
                  seq++;
                  ind=i;
              }
              else if(q==-99){
                   if(z[i]-1==p||z[i]+1==p){
                       seq++;
                       q=z[i];
                       ind=i;
              }
              }
              else{
                  if(seq>max)
                      max=seq;

                   return func(z,ind,n);

              }
        }
            if(seq>max)
                max=seq;
            return max;
        }
}

    class ModScanner {
    BufferedReader br;
    StringTokenizer st;
    public ModScanner() {
    br = new BufferedReader(new InputStreamReader(System.in));
    }
    String nextToken() throws Exception {
    while (st == null || !st.hasMoreElements()) {
    st = new StringTokenizer(br.readLine());
    }
    return st.nextToken();
    }
    int nextInt() throws Exception, Exception {
    return Integer.parseInt(nextToken());
    }
    long nextLong() throws Exception {
    return Long.parseLong(nextToken());
    }
    double nextDouble() throws Exception {
    return Double.parseDouble(nextToken());
    }
    }


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BApproximatingAConstantRange solver = new BApproximatingAConstantRange();
        solver.solve(1, in, out);
        out.close();
    }

    static class BApproximatingAConstantRange {
        public void solve(int testNumber, InputReader sc, OutputWriter out) {
            int n = sc.nextInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = sc.nextInt();
            int p1 = 0;
            int p2 = 0;
            int min = Integer.MAX_VALUE;
            int max = Integer.MIN_VALUE;
            int ans = 0;
            while (p2 < n) {
                if (ar[p2] > max)
                    max = ar[p2];
                if (ar[p2] < min)
                    min = ar[p2];
                if (max - min > 1) {
                    p1++;
                    p2 = p1;
                    min = Integer.MAX_VALUE;
                    max = Integer.MIN_VALUE;
                    continue;
                }
                int len = (p2 - p1) + 1;
                if (len > ans)
                    ans = len;
                p2++;
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BApproximatingAConstantRange solver = new BApproximatingAConstantRange();
        solver.solve(1, in, out);
        out.close();
    }

    static class BApproximatingAConstantRange {
        public void solve(int testNumber, InputReader sc, OutputWriter out) {
            int n = sc.nextInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = sc.nextInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int max = Integer.MIN_VALUE;
                int min = Integer.MAX_VALUE;
                for (int j = i; j < n; j++) {
                    if (i > 0 && ar[i] == ar[i - 1])
                        break;
                    if (ar[j] > max)
                        max = ar[j];
                    if (ar[j] < min)
                        min = ar[j];
                    if (max - min <= 1 && (j - i) + 1 > ans)
                        ans = (j - i) + 1;
                    else if (max - min > 1)
                        break;
                }
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BApproximatingAConstantRange solver = new BApproximatingAConstantRange();
        solver.solve(1, in, out);
        out.close();
    }

    static class BApproximatingAConstantRange {
        public static void make(int seg[], int ar[], int lo, int hi, int pos) {
            if (lo == hi) {
                seg[pos] = ar[lo];
                return;
            }
            int mid = (lo + hi) / 2;
            make(seg, ar, lo, mid, pos * 2 + 1);
            make(seg, ar, mid + 1, hi, pos * 2 + 2);
            seg[pos] = Math.min(seg[pos * 2 + 1], seg[pos * 2 + 2]);
        }

        public static void make2(int seg[], int ar[], int lo, int hi, int pos) {
            if (lo == hi) {
                seg[pos] = ar[lo];
                return;
            }
            int mid = (lo + hi) / 2;
            make2(seg, ar, lo, mid, pos * 2 + 1);
            make2(seg, ar, mid + 1, hi, pos * 2 + 2);
            seg[pos] = Math.max(seg[pos * 2 + 1], seg[pos * 2 + 2]);
        }

        public static int min(int seg[], int ar[], int start, int end, int lo, int hi, int pos) {
            if (start <= lo && end >= hi)
                return seg[pos];
            if (start > hi || end < lo)
                return Integer.MAX_VALUE;
            int mid = (lo + hi) / 2;
            return Math.min(min(seg, ar, start, end, lo, mid, pos * 2 + 1), min(seg, ar, start, end, mid + 1, hi, pos * 2 + 2));
        }

        public static int min2(int seg[], int ar[], int start, int end, int lo, int hi, int pos) {
            if (start <= lo && end >= hi)
                return seg[pos];
            if (start > hi || end < lo)
                return Integer.MIN_VALUE;
            int mid = (lo + hi) / 2;
            return Math.max(min2(seg, ar, start, end, lo, mid, pos * 2 + 1), min2(seg, ar, start, end, mid + 1, hi, pos * 2 + 2));
        }

        public void solve(int testNumber, InputReader sc, OutputWriter out) {
            int n = sc.nextInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = sc.nextInt();
            int p1 = 0;
            int p2 = 0;
            int min = 0;
            int max = 0;
            double pow = (Math.log(1.0 * n) / Math.log(2));
            int p = (int) pow;
            if (p != pow)
                p++;
            int len = 2 * (1 << p) - 1;
            int seg1[] = new int[len];
            int seg2[] = new int[len];
            make(seg1, ar, 0, n - 1, 0);
            make2(seg2, ar, 0, n - 1, 0);
            int ans = 0;
            while (p2 < n) {
                max = min2(seg2, ar, p1, p2, 0, n - 1, 0);
                min = min(seg1, ar, p1, p2, 0, n - 1, 0);
                if (max - min > 1) {
                    p1++;
                    p2++;
                    continue;
                }
                int le = (p2 - p1) + 1;
                if (le > ans)
                    ans = le;
                p2++;
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BApproximatingAConstantRange solver = new BApproximatingAConstantRange();
        solver.solve(1, in, out);
        out.close();
    }

    static class BApproximatingAConstantRange {
        public void solve(int testNumber, InputReader sc, OutputWriter out) {
            int n = sc.nextInt();
            int ar[] = new int[n];
            for (int i = 0; i < n; i++)
                ar[i] = sc.nextInt();
            int ans = 0;
            for (int i = 0; i < n; i++) {
                int max = Integer.MIN_VALUE;
                int min = Integer.MAX_VALUE;
                for (int j = i; j < n; j++) {
                    if (ar[j] > max)
                        max = ar[j];
                    if (ar[j] < min)
                        min = ar[j];
                    if (max - min <= 1 && (j - i) + 1 > ans)
                        ans = (j - i) + 1;
                    else if (max - min > 1)
                        break;
                }
            }
            out.println(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(int i) {
            writer.println(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class ApproximatingConstantRange {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] n = new int[in.nextInt()];
        for(int i = 0; i < n.length; i++) {
            n[i] = in.nextInt();
        }
        solution(n);
    }

    private static void solution(int[] n) {
        Map<Integer, Integer> dataPoints = new HashMap<>();
        int maxLength = 0;
        for(int i = 0; i < n.length; i++) {
            Integer curPoint = n[i];
            if(dataPoints.get(curPoint) == null) {
                dataPoints.put(curPoint, 0);
            }
            dataPoints.put(curPoint, dataPoints.get(curPoint) + 1);
            if(dataPoints.size() > 2) {
                Integer tail = n[i - maxLength];
                Integer tailCount = dataPoints.get(tail);
                tailCount--;
                if(tailCount == 0) {
                    dataPoints.remove(tail);
                } else {
                    dataPoints.put(tail,tailCount);
                }
            } else {
                maxLength++;
            }
        }
        System.out.print(maxLength);
    }
}


import java.util.*;

public class ApproximatingConstantRange {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] n = new int[in.nextInt()];
        for(int i = 0; i < n.length; i++) {
            n[i] = in.nextInt();
        }
        solution(n);
    }

    private static void solution(int[] n) {
        Set<Integer> dataPointSet = new HashSet<>();
        int maxLength = 0;
        for(int i = 0; i < n.length; i++) {
            dataPointSet.add(n[i]);
            if(dataPointSet.size() > 2) {
                dataPointSet.remove(n[i - maxLength]);
            } else {
                maxLength++;
            }
        }
        System.out.print(maxLength);
    }
}


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class ApproximatingConstantRange {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] n = new int[in.nextInt()];
        for(int i = 0; i < n.length; i++) {
            n[i] = in.nextInt();
        }
        solution(n);
    }

    private static void solution(int[] n) {
        Map<Integer, Integer> dataPoints = new HashMap<>();
        int maxLength = 0;
        for(int i = 0; i < n.length; i++) {
            Integer curPoint = n[i];
            if(dataPoints.get(curPoint) == null) {
                dataPoints.put(curPoint, 0);
            }
            dataPoints.put(curPoint, dataPoints.get(curPoint) + 1);
            if(dataPoints.size() > 2) {
                Integer tail = n[i - maxLength];
                dataPoints.remove(tail);
            } else {
                maxLength++;
            }
        }
        System.out.print(maxLength);
    }
}


import java.util.*;
import java.io.*;
public class b
{
	public static void main(String[] arg)
	{
		new b();
	}
	public b()
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = in.nextInt()+3;
		int[] freq = new int[100_005];
		int left = 0;
		int right = 1;
		int answer = 1;
		freq[arr[0]]++;
		while(right < n)
		{
			if(freq[arr[right]-2] == 0 && freq[arr[right]+2] == 0)
			{
				freq[arr[right++]]++;
			}
			else
			{
				while(freq[arr[right]-2] != 0 || freq[arr[right]+2] != 0)
				{
					freq[arr[left++]]--;
				}
			}
			answer = Math.max(answer, right-left);
		}

		out.println(answer);
		in.close(); out.close();
	}
}


import java.util.*;
import java.io.*;
public class b
{
	public static void main(String[] arg)
	{
		new b();
	}
	public b()
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = in.nextInt()+3;
		int[] freq = new int[100_006];
		int left = 0;
		int right = 1;
		int answer = 1;
		freq[arr[0]]++;
		while(right < n)
		{
			if(freq[arr[right]-2] == 0 && freq[arr[right]+2] == 0)
			{
				freq[arr[right++]]++;
			}
			else
			{
				while(freq[arr[right]-2] != 0 || freq[arr[right]+2] != 0)
				{
					freq[arr[left++]]--;
				}
			}
			answer = Math.max(answer, right-left);
		}

		out.println(answer);
		in.close(); out.close();
	}
}


import java.util.*;
import java.io.*;
public class b
{
	public static void main(String[] arg)
	{
		new b();
	}
	public b()
	{
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) arr[i] = in.nextInt();
		int[] freq = new int[100_001];
		int left = 0;
		int right = 1;
		int answer = 1;
		freq[arr[0]]++;
		while(right < n)
		{
			if(freq[arr[right]-2] == 0 && freq[arr[right]+2] == 0)
			{
				freq[arr[right++]]++;
			}
			else
			{
				while(freq[arr[right]-2] != 0 || freq[arr[right]+2] != 0)
				{
					freq[arr[left++]]--;
				}
			}
			answer = Math.max(answer, right-left);
		}

		out.println(answer);
		in.close(); out.close();
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,maxi=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			/*else if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}*/
			mx=Math.max(a[j],mx);
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=mini+1;
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=-1,maxi=-1,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.util.*;
import java.io.*;
public class B {
	static final int N = 100002;
	public static void main(String... thegame) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int[] currs = new int[N];
		int[] maxs = new int[N];
		st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken()); int b = 0;
		currs[a] = 1; currs[a-1] = 1;
		maxs[a] = 1; maxs[a-1] = 1;
		for(int i = 1; i < n; i++){
			b = Integer.parseInt(st.nextToken());
			if(a < b){
				currs[a-1] = 0;
				currs[a]++;
				currs[a+1]++;
			}
			else if(a == b){
				currs[a-1]++;
				currs[a]++;
			}
			else{
				currs[a-2]++;
				currs[a-1]++;
				currs[a] = 0;
			}
			a = b;
			maxs[a-1] = Math.max(maxs[a-1], currs[a-1]);
			maxs[a] = Math.max(maxs[a], currs[a]);
			maxs[a+1] = Math.max(maxs[a+1], currs[a+1]);
		}
		Arrays.sort(maxs);
		System.out.println(maxs[N-1]);
	}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,maxi=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			else if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=-1,maxi=-1,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			mx=Math.max(a[j],mx);
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=mini+1;
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=-1,maxi=-1,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.max(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}


import java.io.*;
import java.util.*;
import java.math.*;
public class cb {

    InputStream is;
    PrintWriter out;

	static long mod=(long)(1e7+9);

    void solve()
    {
		int n=ni();
		int a[]=na(n);
		int mini=0,maxi=0,i=0,j=0,min=Integer.MAX_VALUE,mx=Integer.MIN_VALUE,ans=Integer.MIN_VALUE;
		while(j<n)
		{
			if(a[j]<=min)
			{
				min=a[j];
					mini=j;
				//out.println(mini+" asd");
			}
			if(a[j]>=mx)
			{
				mx=a[j];
					maxi=j;
				//out.println(mini+" asd");
			}
			if(Math.abs(a[j]-min)<=1&&Math.abs(mx-a[j])<=1)
			{
				j++;
			}
			else
			{
				ans=Math.max(ans,j-i);
				i=Math.min(mini+1,maxi+1);
				min=Integer.MAX_VALUE;
				mx=Integer.MIN_VALUE;

			}
		}
		ans=Math.max(ans,j-i);
		out.println(ans);

	}

 	static class pair
	{
		int k,v;
		public pair(int k,int v)
		{
			this.k=k;
			this.v=v;
		}
	}

	public static long [][] multiply(long a[][],long b[][])
	{
		long mul[][]=new long[2][2];
		for(int i=0;i<2;i++)
		{
			for(int j=0;j<2;j++)
			{
				mul[i][j]=0;
				for(int k=0;k<2;k++)
					mul[i][j]=(mul[i][j]+(a[i][k]*b[k][j]))%mod;
			}
		}
		return mul;
	}

	/* Matrix Exponention*/
	public static long [][] power(long [][] mat,int n)
	{
		long res[][]=new long[2][2];
		res[0][0]=1;res[1][1]=1;
		while(n>0)
		{
			if(n%2==1)
				res=multiply(res,mat);
			mat=multiply(mat,mat);
			n/=2;
		}
		return res;
	}

    //---------- I/O Template ----------

    public static void main(String[] args) { new cb().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        solve();
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }

}