#include #include #include #include using namespace std; int solve(string str) { int n = str.size(); vector used(n); int ans = 0; int l = 0, r = n - 1; while (true) { while (l != n && str[l] == '9') ++l; while (r != -1 && str[r] == '1') --r; if (l >= r) break; used[l] = true, used[r] = true; ++l; --r; ++ans; } l = 0, r = n - 1; while (true) { while (l != n && (used[l] || str[l] == '1')) ++l; ++l; while (l != n && (used[l] || str[l] == '1')) ++l; while (r != -1 && (used[r] || str[r] == '9')) --r; if (l >= r) break; used[r] = true; ++ans; ++l; --r; } int remc = 0; for (int i = 0; i < n; ++i) { if (!used[i] && str[i] == '1') ++remc; } ans += remc / 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; }