#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long powm(long long x, long long y, long long m = 998244353) {
  x = x % m;
  long long res = 1;
  while (y) {
    if (y & 1) res = res * x;
    res %= m;
    y = y >> 1;
    x = x * x;
    x %= m;
  }
  return res;
}
long long modInverse(long long a, long long m = 998244353) {
  return powm(a, m - 2, m);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j, k, z, t, e, f, p, q, g, r, o, w, h, x, y,
      count1 = 0, prod = 1, ans = 0, a, b, c, d, index, x1, x2, y1, y2, diff,
      sum = 0, sum1 = 0, sum2 = 0, flag = 0, flag1 = 0, flag2 = 0;
  string s, s1, s2;
  cin >> n;
  long long ar[n];
  vector<vector<long long> > m1(1000005);
  map<pair<long long, long long>, long long> m2;
  set<long long> st;
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    st.insert(ar[i]);
    m1[ar[i]].push_back(i);
  }
  ans = 1;
  for (auto i : st) {
    x = i;
    long long maxi;
    for (auto j : st) {
      y = j;
      maxi = 0;
      long long idx = -1;
      while (1) {
        auto it = upper_bound(m1[x].begin(), m1[x].end(), idx);
        if (it != m1[x].end()) {
          maxi++;
          idx = m1[x][it - m1[x].begin()];
        } else {
          break;
        }
        it = upper_bound(m1[y].begin(), m1[y].end(), idx);
        if (it != m1[y].end()) {
          maxi++;
          idx = m1[y][it - m1[y].begin()];
        } else {
          break;
        }
      }
      ans = max(ans, maxi);
    }
  }
  cout << ans;
}
