//#pragma GCC optimize("Ofast") //#pragma GCC target("avx") //#undef LOCAL #include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template using V = vector; template using VV = V>; #ifdef LOCAL struct PrettyOS { ostream& os; bool first; template auto operator<<(T&& x) { if (!first) os << ", "; first = false; os << x; return *this; } }; template void dbg0(T&&... t) { (PrettyOS{cerr, true} << ... << t); } #define dbg(...) \ do { \ cerr << __LINE__ << " : " << #__VA_ARGS__ << " = "; \ dbg0(__VA_ARGS__); \ cerr << endl; \ } while (false); #else #define dbg(...) #endif template ostream& operator<<(ostream& os, const pair& p) { return os << "P(" << p.first << ", " << p.second << ")"; } template ostream& operator<<(ostream& os, const V& v) { os << "["; for (auto d : v) os << d << ", "; return os << "]"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; string s; cin >> n >> s; int ans = 0; V used(n); for (int i = 0; i < n; i++) { if (s[i] == '3' || s[i] == '7' || s[i] == '5') { used[i] = true; ans++; continue; } } { //19 V ones; for (int i = 0; i < n; i++) { if (used[i]) continue; if (s[i] == '1') { ones.push_back(i); } else { if (ones.size()) { int j = ones.back(); ones.pop_back(); used[j] = true; used[i] = true; ans++; } } } } { //991 V nines; for (int i = 0; i < n; i++) { if (used[i]) continue; if (s[i] == '1') { if (nines.size() >= 2) { int j0 = nines.back(); nines.pop_back(); int j1 = nines.back(); nines.pop_back(); used[j0] = used[j1] = used[i] = true; ans++; } } else { nines.push_back(i); } } } int oc = 0; for (int i = 0; i < n; i++) { if (used[i]) continue; if (s[i] == '1') oc++; } ans += oc / 2; cout << ans << endl; return 0; }