#include #include #include #include using namespace std; int solve(string str) { int n = str.size(); vector lp(n + 1), rp(n + 1); int l = 0, r = n - 1, cnt = 0; while (true) { while (l != n && str[l] == '9') ++l; while (r != -1 && str[r] == '1') --r; if (l >= r) break; lp[l] = ++cnt; ++l; --r; } l = 0, r = n - 1, cnt = 0; while (true) { while (l != n && str[l] == '1') ++l; ++l; while (l < n && str[l] == '1') ++l; while (r != -1 && str[r] == '9') --r; if (l >= r) break; rp[r + 1] = ++cnt; ++l; --r; } int c1 = 0; for (int i = 0; i < n; ++i) { c1 += (str[i] == '1'); } int mx = 0, ans = 0; for (int i = 0; i <= n; ++i) { mx = max(mx, lp[i]); int n1 = min(mx + rp[i], c1); ans = max(ans, n1 + (c1 - n1) / 2); } return ans; } int main() { int n; string s; cin >> n >> s; string str; int ans = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '1' || s[i] == '9') { str += s[i]; } else { ++ans; } } ans += solve(str); cout << ans << endl; return 0; }