func_code_string: #include <bits/stdc++.h>   using namespace std;   const double EPS = 0.0000001;   const double PI = acos(-1);   const long long INFLL = 0x7FFFFFFFFFFFFFFF;   const int INF = 0x7FFFFFFF;   template <typename T>   inline void next(T &num) {     char c;     num = 0;     do {       c = getchar_unlocked();     } while (c != EOF && c ==     && c ==   n  && c ==   t );     int sign = (c ==  -  ? -1 : 1);     if (c !=  - ) num += (c -  0 );     while ((c = getchar_unlocked()) != EOF && c !=   n  && c !=   t  &&            c !=    ) {       num *= 10;       num += (c -  0 );     }     num *= sign;   }   inline string getstr() {     string str;     char k;     while ((k = getchar_unlocked()) ==     || k ==   n ) {       k = getchar_unlocked();       if (k ==     || k ==   n )         continue;       else         break;     }     str.push_back(k);     while ((k = getchar_unlocked()) != EOF && k !=   n  && k !=   t  &&            k !=   v  && k !=   0  && k !=    )       str.push_back(k);     return str;   }   const int M = 50005;   long long n, a[M];   long long ans;   void dfs(long long n, int p, long long now) {     if (now > ans) return;     if (!n) {       ans = min(ans, now);       return;     }     if (!p) return;     int need = n / a[p];     dfs(n - need * a[p], p - 1, now + p * need);     dfs((need + 1) * a[p] - n, p - 1, now + p * (need + 1));   }   int main() {     cin >> n;     for (int i = int(1), _b = int(16); i <= _b; i++) a[i] = a[i - 1] * 10 + 1;     ans = n;     dfs(n, 16, 0);     cout << ans;     return 0;   }   