#include #include #include using namespace std; int main() { regex re("^1(0+)7$"); string N; cin >> N; smatch sm; if (regex_match(N, sm, re)) { string sms = sm[0]; int cnt = count(sms.begin(), sms.end(), '0'); cout << max(cnt - 8, 8 - cnt) << endl; } return 0; }