#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; } } n = s.length(); std::vector dp(n + 1, 0); dp[0] = ans; for (int i = 0; i < n; ++i) { dp[i + 1] = std::max(dp[i + 1], dp[i]); if (s.substr(i, 2) == "11" || s.substr(i, 2) == "19") { dp[i + 2] = std::max(dp[i + 2], dp[i] + 1); } if (s.substr(i, 3) == "991") { dp[i + 3] = std::max(dp[i + 3], dp[i] + 1); } } std::cout << dp.back() << std::endl; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }