Problem: You are given a positive (greater than zero) integer n.

You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. 

Among all possible representations, you have to find the one that uses the minimum number of ones in total.

Input

The single line contains one integer n (1 ≤ n < 10^{50}).

Output

Print one integer x — the minimum number of ones, such that there exist a representation of n as the sum of integers (possibly negative) that uses x ones in total.

Examples

Input


24


Output


6


Input


102


Output


7

Solution (in CPP):

Solution:
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2021/3/7 8:31 下午
*
================================================================*/
#include <bits/stdc++.h>

#define VI vector<int>
#define ll long long
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
using namespace std;

namespace IO {
    template<class T>
    void _R(T &x) { cin >> x; }
    void _R(int &x) { scanf("%d", &x); }
    void _R(ll &x) { scanf("%lld", &x); }
    void _R(double &x) { scanf("%lf", &x); }
    void _R(char &x) { x = getchar(); }
    void _R(char *x) { scanf("%s", x); }
    void R() {}
    template<class T, class... U>
    void R(T &head, U &... tail) {_R(head),R(tail...);}
    template<class T>
    void _W(const T &x) { cout << x; }
    void _W(const int &x) { printf("%d", x); }
    void _W(const ll &x) { printf("%lld", x); }
    void _W(const double &x) { printf("%.16f", x); }
    void _W(const char &x) { putchar(x); }
    void _W(const char *x) { printf("%s", x); }
    template<class T, class U>
    void _W(const pair<T, U> &x) {_W(x.first),putchar(' '),_W(x.second);}
    template<class T>
    void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
    void W() {}
    template<class T, class... U>
    void W(const T &head, const U &... tail) {_W(head),putchar(sizeof...(tail) ? ' ' : '\n'),W(tail...);}
}
using namespace IO;


const int maxn = 55;
const int mod = 1e9+7;

ll qp(ll a, ll n) {
    ll res = 1;
    n %= mod - 1;
    if (n < 0) n += mod - 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll qp(ll a, ll n, int mod) {
    ll res = 1;
    n %= mod - 1;
    if (n < 0) n += mod - 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int C = 50 + 5;
const int X = 500 + 5;
int dp[maxn][C * 2 + 5][X * 2 + 5][2];
char s[maxn];
int n;
const int INF = 0x3f3f3f3f;

int dfs(int pos, int c, int x, int del) {
    if (pos > n) return c ? INF : 0;
    if (c < -C || c > C || x < -X || x > X) return INF;
    int &ans = dp[pos][c + C][x + X][del == 1];
    if (ans != -1) return ans;
    ans = INF;
    ans = min({
        dfs(pos, c, x + del, del) + n - pos + 1,
        dfs(pos + 1, c * 10 + s[pos] - x, x, 1),
        dfs(pos + 1, c * 10 + s[pos] - x, x, -1)
    });
//    if (ans != INF) {
//        dbg1(pos); dbg1(c); dbg1(x); dbg1(del); dbg2(ans);
//    }
    return ans;
}

int main(int argc, char* argv[]) {
    scanf("%s", s + 2);
    n = strlen(s + 2) + 1;
    for (int i = 2; i <= n; ++i) s[i] -= '0';
    memset(dp, -1, sizeof dp);
    W(dfs(1, 0, 0, 1));
    return 0;
}