func_code_string: #include <bits/stdc++.h>   using namespace std;   void solutionC();   int main() {     solutionC();     return EXIT_SUCCESS;   }   int n, a[500002], b[500002];   bool check() {     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) return false;       if (s == 1 && a[i] != 0) return false;     }     return true;   }   void change() {     b[0] = a[0];     b[n - 1] = a[n - 1];     for (int i = 1; i < n - 1; ++i) {       int s = a[i] + a[i - 1] + a[i + 1];       if (s == 2 && a[i] != 1) {         b[i] = 1;         continue;       }       if (s == 1 && a[i] != 0) {         b[i] = 0;         continue;       }       b[i] = a[i];     }     for (int i = 0; i < n; ++i) a[i] = b[i];   }   void out() {     for (int i = 0; i < n; ++i) {       if (i) cout <<    ;       cout << a[i];     }     cout << endl;   }   void solve() {     int l = 1;     vector<pair<int, int>> e;     for (int i = 1; i < n; ++i) {       if (a[i] != a[i - 1]) {         ++l;       } else {         if (l >= 3) e.emplace_back(i - l, i - 1);         l = 1;       }     }     if (l >= 3) e.emplace_back(n - l, n - 1);     int ans = 0;     for (auto it : e) {       int d = it.second - it.first;       if (d % 2 == 0) {         ans = max(ans, d / 2);         assert(a[it.first] == a[it.second]);         for (int i = it.first; i <= it.second; ++i) a[i] = a[it.first];       } else {         assert(a[it.first] != a[it.second]);         ans = max(ans, (d - 1) / 2);         for (int i = it.first; i <= it.second; ++i)           if (i - it.first < it.second - i)             a[i] = a[it.first];           else             a[i] = a[it.second];       }     }     cout << ans << endl;     out();   }   void bf() {     for (int l = 3; l < 24; ++l) {       n = l;       int mx = 0;       cout <<  n:   << l << endl;       for (int bm = 0; bm < (1 << l); ++bm) {         for (int i = 0; i < n; ++i) a[i] = (bm & (1 << i)) > 0;         int cnt = 0;         while (!check()) {           cnt++;           change();           if (cnt > n * n * 2) {             cout <<  fnd:  ;             out();             break;           }         }         mx = max(mx, cnt);       }       cout <<  mx:   << mx << endl;     }   }   void solutionC() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     solve();   }   