/* -*- coding: utf-8 -*- * * 910.cc: No.910 素数部分列 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 200000; /* typedef */ /* global variables */ char s[MAX_N + 4]; /* subroutines */ /* main */ int main() { int n; scanf("%d%s", &n, s); int cnt = 0; int n1 = 0, n9 = 0; for (int i = 0; i < n; i++) { if (s[i] == '1') n1++; else if (s[i] == '9') { if (n1 > 0) n1--, cnt++; else n9++; } else cnt++; } int d = min(n9 / 2, n1); cnt += d; n1 -= d; cnt += n1 / 2; printf("%d\n", cnt); return 0; }