#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
struct Line
{
int start{};
int end{};
int weight{};
};
enum operation {TAKE, DROP};
int optimize(operation op, std::vector<Line>::iterator it, std::vector<Line>::iterator end)
{
int weight{op == TAKE ? it->weight : 0};
int line_end{it->end};
if (op == DROP) ++it;
else while ( ++it != end)
if (it->start > line_end) break;
if (it == end) return weight;
return weight + std::max(optimize(TAKE, it, end),
optimize(DROP, it, end));
}
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;
});
int result{std::max(optimize(TAKE, lines.begin(), lines.end()),
optimize(DROP, lines.begin(), lines.end()))
};
std::ofstream fout{"output.txt"};
fout << result;
fout.close();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGFsZ29yaXRobT4KCnN0cnVjdCBMaW5lCnsKICAgIGludCBzdGFydHt9OwogICAgaW50IGVuZHt9OwogICAgaW50IHdlaWdodHt9Owp9OwoKZW51bSBvcGVyYXRpb24ge1RBS0UsIERST1B9OwoKaW50IG9wdGltaXplKG9wZXJhdGlvbiBvcCwgc3RkOjp2ZWN0b3I8TGluZT46Oml0ZXJhdG9yIGl0LCBzdGQ6OnZlY3RvcjxMaW5lPjo6aXRlcmF0b3IgZW5kKQp7CiAgICBpbnQgd2VpZ2h0e29wID09IFRBS0UgPyBpdC0+d2VpZ2h0IDogMH07CiAgICBpbnQgbGluZV9lbmR7aXQtPmVuZH07CiAgICAKICAgIGlmIChvcCA9PSBEUk9QKSArK2l0OwogICAgZWxzZSB3aGlsZSAoICsraXQgIT0gZW5kKQogICAgICAgICAgICBpZiA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KCkpKQogICAgICAgICAgICAgIH07CiAgIAogICAgc3RkOjpvZnN0cmVhbSBmb3V0eyJvdXRwdXQudHh0In07CiAgICBmb3V0IDw8IHJlc3VsdDsKICAgIGZvdXQuY2xvc2UoKTsKICAgIAogICAgcmV0dXJuIDA7Cn0=