This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.

You are given an array [a_1, a_2, ..., a_n]. 

Your goal is to find the length of the longest subarray of this array such that the most frequent value in it is not unique. In other words, you are looking for a subarray such that if the most frequent value occurs f times in this subarray, then at least 2 different values should occur exactly f times.

An array c is a subarray of an array d if c can be obtained from d by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Input

The first line contains a single integer n (1 ≤ n ≤ 200 000) — the length of the array.

The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ min(n, 100)) — elements of the array.

Output

You should output exactly one integer — the length of the longest subarray of the array whose most frequent value is not unique. If there is no such subarray, output 0.

Examples

Input


7
1 1 2 2 3 3 3


Output


6

Input


10
1 1 1 5 4 1 3 1 2 2


Output


7

Input


1
1


Output


0

Note

In the first sample, the subarray [1, 1, 2, 2, 3, 3] is good, but [1, 1, 2, 2, 3, 3, 3] isn't: in the latter there are 3 occurrences of number 3, and no other element appears 3 times.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const long long INF = 1e15;
template <class o>
void qr(o& x) {
  char c = getchar();
  x = 0;
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + '0');
}
template <class o>
void pr1(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) x = -x, putchar('-');
  qw(x);
  putchar('\n');
}
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long power(long long a, long long b = mod - 2, long long p = mod) {
  long long c = 1;
  while (b) {
    if (b & 1) c = c * a % p;
    b /= 2;
    a = a * a % p;
  }
  return c;
}
long long exgcd(long long a, long long b, long long& x, long long& y) {
  if (!a) {
    x = 0;
    y = 1;
    return b;
  }
  long long d = exgcd(b % a, a, y, x);
  x -= b / a * y;
  return d;
}
long long INV(long long n, long long p = mod) {
  long long x, y;
  exgcd(n, p, x, y);
  return (x % p + p) % p;
}
template <class o>
void cmax(o& x, o y) {
  if (x < y) x = y;
}
template <class o>
void cmin(o& x, o y) {
  if (x > y) x = y;
}
template <typename t1, typename t2>
void ad(t1& x, t2 y) {
  x += y;
  if (x >= mod) x -= mod;
}
template <typename t1, typename t2>
void dl(t1& x, t2 y) {
  x -= y;
  if (x < 0) x += mod;
}
template <typename T>
struct BIT {
  T* c;
  int n;
  BIT(int _n) : n(_n) {
    c = new T[n];
    c--;
    for (int i = 1; i <= n; i++) c[i] = T(0);
  }
  void add(int x, T y) {
    for (; x <= n; x += x & -x) c[x] = c[x] + y;
  }
  T sum(int x) {
    T y = T(0);
    for (; x; x &= x - 1) y = y + c[x];
    return y;
  }
};
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<int, int> x) const {
    return operator()(uint64_t(x.first) << 32 | x.second);
  }
};
template <long long mod>
struct dbinom {
  int *jc, *inv;
  dbinom(int n) {
    jc = new int[n + 5];
    inv = new int[n + 5];
    jc_init(n);
  }
  void jc_init(int n) {
    jc[0] = 1;
    for (int i = 1; i <= n; i++) jc[i] = (long long)jc[i - 1] * i % mod;
    inv[n] = power(jc[n], mod - 2, mod);
    for (int i = n; i; i--) inv[i - 1] = (long long)inv[i] * i % mod;
  }
  long long C(int x, int y) {
    if (x < y || y < 0) return 0;
    return (long long)jc[x] * inv[y] % mod * inv[x - y] % mod;
  }
};
struct dsu {
  int *fa, *sz;
  dsu(int n) {
    fa = new int[n + 5];
    sz = new int[n + 5];
    for (int i = 0; i <= n; i++) fa[i] = i, sz[i] = 1;
  }
  int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
  bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x == y) return 0;
    if (sz[x] < sz[y]) swap(x, y);
    fa[y] = x;
    sz[x] += sz[y];
    return 1;
  }
  bool same(int x, int y) { return get(x) == get(y); }
};
int n, t, val, p, k, a[N], buf[N], c[N], cnt, now;
void add(int x, int y) {
  cnt -= c[x] == now;
  c[x] += y;
  cnt += c[x] == now;
}
void solve() {
  qr(n);
  t = sqrt(n);
  for (int i = 1; i <= n; i++) {
    qr(a[i]);
    if (++buf[a[i]] > val)
      val = buf[a[i]], p = a[i], k = 1;
    else
      k += buf[a[i]] == val;
  }
  if (val == n) return pr2(0);
  if (k > 1) return pr2(n);
  t = min(t, val);
  int ans = 0;
  for (now = 1; now <= t; now++) {
    memset(c + 1, 0, sizeof(int) * n);
    cnt = 0;
    for (int l = 1, r = 1; r <= n; r++) {
      add(a[r], 1);
      while (c[a[r]] > now) add(a[l++], -1);
      if (cnt > 1) cmax(ans, r - l + 1);
    }
  }
  for (int i = 1; i <= n; i++)
    if (buf[i] > t && i != p) {
      static int lst[N << 1];
      memset(lst, -1, sizeof lst);
      int s = n;
      lst[s] = 0;
      for (int j = 1; j <= n; j++) {
        s += a[j] == p ? 1 : -(a[j] == i);
        if (lst[s] == -1)
          lst[s] = j;
        else
          cmax(ans, j - lst[s]);
      }
    }
  pr2(ans);
}
int main() {
  int T = 1;
  while (T--) solve();
  return 0;
}
