#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using i64 = int64_t; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() const int INF = (1 << 30); const i64 INFL = (1LL << 62); const i64 MOD = 1000000007; template T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template T lcm(T a, T b) { return a / gcd(a, b) * b; } template i64 mod_pow(i64 a, i64 n, T mod) { mod = (i64)mod; i64 res = 1, p = a % mod; while (n) { if (n & 1) res = res * p % mod; p = p * p % mod; n >>= 1; } return res; } void print() { std::cout << std::endl; } template void print(const T& first, const A&... rest) { cout << sizeof...(rest) << endl; std::cout << first; if (sizeof...(rest)) std::cout << " "; print(rest...); } template void print(const A&... rest) { print(rest...); } template void print(const std::vector& v) { std::for_each(v.begin(), v.end(), [](A x) { std::cout << x << " "; }); std::cout << std::endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int ans = 0; int l = -1; int r = -1; int cnt_1 = 0; int cnt_9 = 0; rep(i, n) { if (s[i] == '1') ++cnt_1; if ((s[i] != '1') && (s[i] != '9')) { ++ans; } else if (s[i] == '1' && l == -1) { l = i; } else if (s[i] == '9') { r = i; ++cnt_9; } } if (l != -1 && r != -1) { int c1 = 0; int c9 = 0; for (int i = l; i <= r; ++i) { if (s[i] == '1') ++c1; if (s[i] == '9') ++c9; } ans += min(c1, c9); // 19の個数 // 991 int rest9 = cnt_9 - min(c1, c9); int rest1 = cnt_1 - min(c1, c9); if (c9 > c1) { rest9 += c9 - c1; } else { rest1 += c1 - c9; } if (rest9 > 0 && rest1 >= (rest9 / 2)) { ans += (rest9 / 2); rest1 -= (rest9 / 2); } // 11 ans += (max(rest1, 0)) / 2; } else { ans += cnt_1 / 2; } cout << ans << endl; return 0; }