#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
struct Line
{
int start{};
int end{};
int weight{};
};
static const int size = 100;
int main()
{
std::ifstream fin{"input.txt"};
int N;
fin >> N;
std::vector<Line> lines(size);
for (int i{}; i < N; i++)
{
int num;
fin >> num;
Line& line = lines[num - 1];
if (line.start == 0)
line.start = i;
line.end = i;
line.weight++;
}
fin.close();
std::sort(lines.begin(), lines.end(), [](const Line& a, const Line& b) {
return b.start > a.start;
});
std::vector<int> best(size);
for (int i{}; i < size; i++)
{
Line& line = lines[i];
best[i] = line.weight;
for (int j{}; j < i; j++)
if (lines[j].end < line.start)
best[i] = std::max(best[i], best[j] + line.weight);
}
std::ofstream fout{"output.txt"};
fout << *std::max_element(best.begin(), best.end());
fout.close();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnN0cnVjdCBMaW5lCnsKICAgIGludCBzdGFydHt9OwogICAgaW50IGVuZHt9OwogICAgaW50IHdlaWdodHt9Owp9OwoKc3RhdGljIGNvbnN0IGludCBzaXplID0gMTAwOwoKaW50IG1haW4oKQp7CiAgICBzdGQ6Omlmc3RyZWFtIGZpbnsiaW5wdXQudHh0In07CiAgICAKICAgIGludCBOOwogICAgZmluID4+IE47CiAgICAKICAgIHN0ZDo6dmVjdG9yPExpbmU+IGxpbmVzKHNpemUpOwogICAgCiAgICBmb3IgKGludCBpe307IGkgPCBOOyBpKyspCiAgICB7CiAgICAgICAgaW50IG51bTsKICAgICAgICBmaW4gPj4gbnVtOwogICAgICAgIExpbmUmIGxpbmUgPSBsaW5lc1tudW0gLSAxXTsKICAgICAgICAKICAgICAgICBpZiAobGluZS5zdGFydCA9PSAwKQogICAgICAgICAgICBsaW5lLnN0YXJ0ID0gaTsKICAgICAgICBsaW5lLmVuZCA9IGk7CiAgICAgICAgbGluZS53ZWlnaHQrKzsKICAgIH0KICAgIAogICAgZmluLmNsb3NlKCk7CiAgICAKICAgIHN0ZDo6c29ydChsaW5lcy5iZWdpbigpLCBsaW5lcy5lbmQoKSwgW10oY29uc3QgTGluZSYgYSwgY29uc3QgTGluZSYgYikgewogICAgICAgIHJldHVybiBiLnN0YXJ0ID4gYS5zdGFydDsgICAKICAgIH0pOwoKICAgIHN0ZDo6dmVjdG9yPGludD4gYmVzdChzaXplKTsKICAgIGZvciAoaW50IGl7fTsgaSA8IHNpemU7IGkrKykKICAgIHsKICAgICAgICBMaW5lJiBsaW5lID0gbGluZXNbaV07CiAgICAgICAgYmVzdFtpXSA9IGxpbmUud2VpZ2h0OwogICAgICAgIAogICAgICAgIGZvciAoaW50IGp7fTsgaiA8IGk7IGorKykgICAgICAgICAgICAKICAgICAgICAgICAgaWYgKGxpbmVzW2pdLmVuZCA8IGxpbmUuc3RhcnQpCiAgICAgICAgICAgICAgICBiZXN0W2ldID0gc3RkOjptYXgoYmVzdFtpXSwgYmVzdFtqXSArIGxpbmUud2VpZ2h0KTsKICAgIH0KICAgCiAgICBzdGQ6Om9mc3RyZWFtIGZvdXR7Im91dHB1dC50eHQifTsKICAgIGZvdXQgPDwgKnN0ZDo6bWF4X2VsZW1lbnQoYmVzdC5iZWdpbigpLCBiZXN0LmVuZCgpKTsKICAgIGZvdXQuY2xvc2UoKTsKICAgIAogICAgcmV0dXJuIDA7Cn0=