#include <bits/stdc++.h>
using namespace std;
int matr[4000][4000];
int mas[4000];
int N;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> mas[i];
  memset(matr, 0, sizeof(matr));
  map<int, int> mp;
  for (int i = 0; i < N; i++)
    if (mp.find(mas[i]) == mp.end()) {
      int a = mp.size();
      mp[mas[i]] = a;
    }
  vector<pair<int, int> > v;
  int M = mp.size();
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
    v.push_back(make_pair(it->first, it->second));
  for (int i = 0; i < N; i++) {
    int index = mp[mas[i]];
    for (int j = 0; j < M; j++)
      if (j != index)
        if (matr[index][j] % 2 == 0) matr[index][j]++;
    for (int j = 0; j < M; j++)
      if (j != index)
        if (matr[j][index] % 2 == 1) matr[j][index]++;
    matr[index][index]++;
  }
  int res = 0;
  for (int i = 0; i < M; i++)
    for (int j = 0; j < M; j++) res = max(res, matr[i][j]);
  cout << res << "\n";
  return 0;
}
