#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// Function to count subarrays with at most `k` distinct elements
ll count(ll arr[], int n, int k) {
ll i = 0, j = 0, count = 0;
unordered_map<ll, ll> freq;
while (j < n) {
freq[arr[j]]++;
while (freq.size() > k) {
freq[arr[i]]--;
if (freq[arr[i]] == 0) {
freq.erase(arr[i]);
}
i++;
}
count += (j - i + 1);
j++;
}
return count;
}
int main() {
ll n;
cin >> n;
ll b[n];
for (ll i = 0; i < n; i++) cin >> b[i];
ll tot = n * (n + 1) / 2; // Total number of subarrays
ll v = ceil(tot / 2.0); // Half of total subarrays, rounded up
ll left = 1, right = n, r = n;
while (left <= right) {
ll mid = (left + right) / 2;
if (count(b, n, mid) >= v) {
r = mid;
right = mid - 1;
} else {
left = mid + 1;
}
}
cout << r << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKCi8vIEZ1bmN0aW9uIHRvIGNvdW50IHN1YmFycmF5cyB3aXRoIGF0IG1vc3QgYGtgIGRpc3RpbmN0IGVsZW1lbnRzCmxsIGNvdW50KGxsIGFycltdLCBpbnQgbiwgaW50IGspIHsKICAgIGxsIGkgPSAwLCBqID0gMCwgY291bnQgPSAwOwogICAgdW5vcmRlcmVkX21hcDxsbCwgbGw+IGZyZXE7CgogICAgd2hpbGUgKGogPCBuKSB7CiAgICAgICAgZnJlcVthcnJbal1dKys7CgogICAgICAgIHdoaWxlIChmcmVxLnNpemUoKSA+IGspIHsKICAgICAgICAgICAgZnJlcVthcnJbaV1dLS07CiAgICAgICAgICAgIGlmIChmcmVxW2FycltpXV0gPT0gMCkgewogICAgICAgICAgICAgICAgZnJlcS5lcmFzZShhcnJbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGkrKzsKICAgICAgICB9CgogICAgICAgIGNvdW50ICs9IChqIC0gaSArIDEpOwogICAgICAgIGorKzsKICAgIH0KCiAgICByZXR1cm4gY291bnQ7Cn0KCmludCBtYWluKCkgewogICAgbGwgbjsKICAgIGNpbiA+PiBuOwogICAgbGwgYltuXTsKICAgIAogICAgZm9yIChsbCBpID0gMDsgaSA8IG47IGkrKykgY2luID4+IGJbaV07CiAgICAKICAgIGxsIHRvdCA9IG4gKiAobiArIDEpIC8gMjsgLy8gVG90YWwgbnVtYmVyIG9mIHN1YmFycmF5cwogICAgbGwgdiA9IGNlaWwodG90IC8gMi4wKTsgLy8gSGFsZiBvZiB0b3RhbCBzdWJhcnJheXMsIHJvdW5kZWQgdXAKICAgIAogICAgbGwgbGVmdCA9IDEsIHJpZ2h0ID0gbiwgciA9IG47CiAgICB3aGlsZSAobGVmdCA8PSByaWdodCkgewogICAgICAgIGxsIG1pZCA9IChsZWZ0ICsgcmlnaHQpIC8gMjsKICAgICAgICBpZiAoY291bnQoYiwgbiwgbWlkKSA+PSB2KSB7CiAgICAgICAgICAgIHIgPSBtaWQ7CiAgICAgICAgICAgIHJpZ2h0ID0gbWlkIC0gMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBsZWZ0ID0gbWlkICsgMTsKICAgICAgICB9CiAgICB9CiAgICAKICAgIGNvdXQgPDwgciA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0=