#include <bits/stdc++.h>
using namespace std;
int x[1000001][2];
int main() {
  int i, j, k, l, test, m, n;
  int a[4100];
  scanf("%d", &n);
  int c[4100];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    c[i] = a[i];
  }
  sort(c, c + n);
  int b[4100];
  int d[4100];
  b[0] = c[0];
  d[0] = 1;
  int in = 0;
  for (i = 1; i < n; i++)
    if (c[i] != b[in]) {
      d[++in] = 1;
      b[in] = c[i];
    } else {
      d[in]++;
    }
  int g = 0;
  for (i = 0; i <= in; i++) g = max(g, d[i]);
  int f = 0;
  for (i = 0; i <= in; i++) {
    for (j = 0; j <= in; j++) x[b[j]][0] = x[b[j]][1] = 0;
    int val = b[i];
    for (j = 0; j < n; j++) {
      if (a[j] == val)
        x[val][1]++;
      else {
        k = a[j];
        if (x[k][1] == x[val][1])
          ;
        else {
          x[k][1] = x[val][1];
          x[k][0] += 2;
        }
      }
    }
    for (j = 0; j <= in; j++) {
      if (x[b[j]][1] != x[val][1]) x[b[j]][0]++;
    }
    for (j = 0; j <= in; j++) f = max(f, x[b[j]][0]);
  }
  cout << max(f, g) << endl;
}
