#include <bits/stdc++.h>
using namespace std;
namespace cp {
const long long INF = 9223372036854775807;
const int MOD = 1e9 + 7;
string ts(int n) { return to_string(n); }
string ts(double n) { return to_string(n); }
string ts(long double n) { return to_string(n); }
string ts(long long n) { return to_string(n); }
string ts(char c) { return to_string(c); }
string ts(bool b) { return b ? "true" : "false"; }
string ts(string s) { return s; }
template <typename T, typename V>
string ts(pair<T, V> p) {
  return "{" + ts(p.first) + ", " + ts(p.second) + "}";
}
template <typename T>
string ts(T arr[], int len) {
  ostringstream oss;
  oss << "[";
  string delim = "";
  for (int i = 0; i < len; i++) {
    oss << delim << ts(arr[i]);
    delim = ", ";
  }
  oss << "]";
  return oss.str();
}
template <typename Container>
string ts(const Container &v) {
  ostringstream oss;
  oss << "[";
  string delim = "";
  for (const auto &x : v) {
    oss << delim << ts(x);
    delim = ", ";
  }
  oss << "]";
  return oss.str();
}
template <typename T, typename V>
string ts(map<T, V> m) {
  ostringstream oss;
  oss << "[";
  string delim = "";
  for (pair<T, V> p : m) {
    oss << delim;
    oss << "{" << p.first << ": " << p.second << "}";
    delim = ", ";
  }
  oss << "]";
  return oss.str();
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
  size_t operator()(pair<uint64_t, uint64_t> &x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x.first + FIXED_RANDOM) ^
           (splitmix64(x.second + FIXED_RANDOM) >> 1);
  }
};
void setI(string s) { freopen(s.c_str(), "r", stdin); }
void setO(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s1, string s2) {
  setI(s1);
  setO(s2);
}
void setUsacoIO(string s) { setIO(s + ".in", s + ".out"); }
}  // namespace cp
using namespace cp;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  unordered_map<int, int> mp;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (!mp.count(arr[i])) {
      mp[arr[i]] = i;
    }
    arr[i] = mp[arr[i]];
  }
  int mx = *max_element(arr, arr + n);
  pair<int, bool> len[mx + 1][mx + 1];
  for (int i = 0; i <= mx; i++)
    for (int j = 0; j <= mx; j++) len[i][j] = {0, 0};
  for (int x : arr) {
    for (int j = 0; j <= mx; j++) {
      if (j == x) {
        len[j][x].first++;
        continue;
      }
      if (len[j][x].second == 1) {
        len[j][x].first++;
        len[j][x].second = 0;
      }
      if (len[x][j].second == 0) {
        len[x][j].first++;
        len[x][j].second = 1;
      }
    }
  }
  int ret = 0;
  for (int i = 0; i <= mx; i++)
    for (int j = 0; j <= mx; j++) ret = max(ret, len[i][j].first);
  cout << ret << endl;
  return 0;
}
