#include using namespace std; using ll = long long; using P = pair; vector

RLE(const vector& v) { int tar = v.front(); int cnt = 0; vector

res; for (int x : v) { if (tar == x) cnt++; else { res.emplace_back(tar, cnt); tar = x; cnt = 1; } } if (cnt > 0) res.emplace_back(tar, cnt); return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector

v = RLE(a); int sz = v.size(); vector dp(sz + 1, 0); dp[1] = v.front().second; for (int i = 1; i < sz; i++) { dp[i + 1] = max(dp[i] + max(v[i].second - 1, 0), dp[i - 1] + v[i].second); } cout << dp[sz] << "\n"; return 0; }