func_code_string: #include <bits/stdc++.h>   using namespace std;   inline long long rd() {     long long x = 0;     int ch = getchar(), f = 1;     while (!isdigit(ch) && (ch !=  - ) && (ch != EOF)) ch = getchar();     if (ch ==  - ) {       f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline void rt(long long x) {     if (x < 0) putchar( - ), x = -x;     if (x >= 10)       rt(x / 10), putchar(x % 10 +  0 );     else       putchar(x +  0 );   }   const int maxn = 5005, S = 100005;   int n, m, a[maxn], id[S], dsc[maxn];   short int f[maxn][maxn], g[maxn][maxn], h[maxn][7], ans;   void upd(short int &x, short int y) {     if (y > x) x = y;   }   int main() {     n = rd();     for (int i = int(1); i <= (int)(n); i++) a[i] = dsc[i] = rd();     sort(dsc + 1, dsc + n + 1);     m = unique(dsc + 1, dsc + n + 1) - dsc - 1;     for (int i = int(1); i <= (int)(m); i++) id[dsc[i]] = i;     for (int i = int(1); i <= (int)(n); i++) {       int x = id[a[i]];       for (int j = int(0); j <= (int)(i - 1); j++) {         if (x && dsc[x - 1] + 1 == a[i]) upd(f[j][i], g[j][x - 1] + 1);         if (x < m && dsc[x + 1] - 1 == a[i]) upd(f[j][i], g[j][x + 1] + 1);         upd(f[j][i], h[j][a[i] % 7] + 1);         if (j)           upd(h[i][a[j] % 7], f[j][i]), upd(g[i][id[a[j]]], f[j][i]);         else {           for (int k = int(0); k <= (int)(6); k++) upd(h[i][k], f[j][i]);           for (int k = int(1); k <= (int)(m); k++) upd(g[i][k], f[j][i]);         }         upd(g[j][id[a[i]]], f[j][i]), upd(h[j][a[i] % 7], f[j][i]);         upd(ans, f[j][i]);       }     }     rt(ans), putchar(  n );   }   