#include #include #include void solve() { int n; std::cin >> n; int ans = 0; std::string s; while (n--) { char c; std::cin >> c; if (c == '1' || c == '9') { s.push_back(c); } else { ++ans; } } int c1 = 0, c9 = 0; for (char c : s) { if (c == '1') { ++c1; } else { if (c1 > 0) { ++ans; --c1; } else { ++c9; } } } ans += c1 / 2; c1 %= 2; if (c1 == 1 && c9 >= 2) ++ans; std::cout << ans << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }