#include #define forn(i, n) for(int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; const int MAXN = 100; int a[MAXN + 1]; int main() { //ios_base::sync_with_stdio(false); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n; cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; int ans = 0; for(int i = 1; i <= n; i++) { for(int j = i + 1; j <= n; j++) { int _min = a[i], _max = a[i], res = 1; if(abs(a[i] - a[j]) <= 1) _min = min(_min, a[j]), _max = max(_max, a[j]), res = 2; for (int k = j + 1; k <= n; k++) { if (abs(a[k] - _min) <= 1 && abs(a[k] - _max) <= 1) _min = min(_min, a[k]), _max = max(_max, a[k]), res++; } ans = max(ans, res); } } cout << ans; return 0; }