#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll mod = 1000000007; #define rep(i,n) for(int i=0;i=0;i--) #define all(x) (x).begin(),(x).end() typedef pair P; int main() { int N; cin >> N; vector as(N); rep(i, N) { cin >> as[i]; } vector

ps; { ll prev = as[0]; ll count = 1; repl(i, 1, N) { if (as[i] != prev) { ps.emplace_back(prev, count); prev = as[i]; count = 0; } ++count; } ps.emplace_back(prev, count); } //dp[i] := ps[i - 1]までの餅のいくつかをずんだ餅に変えた時の、ずんだ餅の個数の最大値 vector dp(ps.size() + 1, -1); dp[0] = 0; dp[1] = ps[0].second; repl(i, 1, ps.size()) { reple(j, 0, i - 1) { dp[i + 1] = max(dp[i + 1], dp[j] + ps[i].second); } dp[i + 1] = max(dp[i + 1], dp[i]); } cout << dp[dp.size() - 1] << endl; return 0; }