func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};   int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};   int dr4[] = {0, 1, -1, 0};   int dc4[] = {1, 0, 0, -1};   int n;   int a[N];   set<pair<int, int> > s;   set<int> end_idx;   int sz[N];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i + 1];     }     int c = 1;     for (int i = 2; i <= n; i++) {       if (a[i] != a[i - 1]) {         s.insert({-c, i - 1});         end_idx.insert(i - 1);         sz[i - 1] = c;         c = 1;       } else         c++;     }     s.insert({-c, n});     end_idx.insert(n);     sz[n] = c;     int ans = 0;     while (!s.empty()) {       auto it = *s.begin();       s.erase(s.begin());       end_idx.erase(it.second);       ans++;       auto idx = end_idx.lower_bound(it.second);       if (idx != end_idx.begin() && idx != end_idx.end()) {         int rgt = *idx;         idx--;         int lft = *idx;         if (a[lft] == a[rgt]) {           s.erase(s.find({-sz[lft], lft}));           s.erase(s.find({-sz[rgt], rgt}));           end_idx.erase(lft);           sz[rgt] += sz[lft];           s.insert({-sz[rgt], rgt});         }       }     }     cout << ans;   }   