#include using namespace std; int main() { int n; cin >> n; if (n == 0) { cout << 4 << endl; return 0; } int r1 = 1, r2 = 2, tn = n; while (tn) { switch (tn % 10) { case 1: case 2: case 3: case 5: case 7: r1 += 2; break; case 0: case 4: case 6: case 9: r1 += 3; break; case 8: r1 += 4; break; } tn /= 10; } tn = n; while (tn) { switch (tn % 10) { case 1: case 2: case 3: case 5: case 7: r2 += 1; break; case 0: case 4: case 6: case 9: r2 += 3; break; case 8: r2 += 5; break; } tn /= 10; } cout << min(r1, r2) << endl; return 0; }