#include #include #include #include using namespace std; typedef long long ll; bool done[100010]; struct Data { int l, r, n; Data(int l, int r): l(l), r(r), n(r-l+1) {} }; // ">" のオーバーロード numを基準に大小比較を行う bool operator < (const Data &d1, const Data &d2){ if (d1.n == d2.n) return d1.l > d2.l; return d1.n < d2.n; }; int main() { int n; cin >> n; int bef = -1; int l = 0, r = 0; priority_queue pq; for (int i = 0; i < n; ++i) { int a; cin >> a; if (a == bef) { r = i; } else if (i > 0) { pq.push(Data(l, r)); l = i; r = i; } bef = a; } pq.push(Data(l, r)); ll ans = 0; while (!pq.empty()) { Data d = pq.top(); pq.pop(); int add = d.n; if (done[d.l]) { --add; } else if (d.l != d.r && done[d.r]) { --add; } if (add == 0) continue; ans += add; if (d.l > 0) done[d.l-1] = true; if (d.r < n-1) done[d.r+1] = true; // cerr << d.l << " " << d.r << " " << d.n << " " << ans << endl; } cout << ans << endl; }