#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; const int INF=1e9+7; int main() { string s; cin>>s; s='0'+s; vector v; for(int i=(int)s.size()-1; i>=0; i--){ int d=s[i]-'0'; if(d>=5){ v.push_back(d-5); v.push_back(1); }else{ v.push_back(d); v.push_back(0); } } reverse(v.begin(), v.end()); int n=v.size(); int dp[2][20020]; dp[0][0]=0; dp[1][0]=INF; for(int i=1; i