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
#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

std::string str;
const int B = 50;
int f[2][55][20*B+3][10*B+3];

inline int dp(int o,int n,int num,int r){
    // 0-> -1
    // 1->1
    if(n == SZ(str)) return r ? 1e9 : 0;
    if(num+10*B > 20*B || num+10*B < 0 || r+5*B > 10*B || r+5*B < 0){
        return 1e9;
    }
    int &res = f[o][n][num+10*B][r+5*B];
    if(res != -1) return res;
    res = std::min({dp(o,n,num+(o==1?1:-1),r)+SZ(str)-n,dp(o,n+1,num,r*10+str[n]-'0'-num),dp(!o,n+1,num,r*10+str[n]-'0'-num)});
    return res;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin >> str;
    str = "000"+str;CLR(f,-1);
    printf("%d\n",std::min(dp(1,0,0,0),dp(0,0,0,0)));
    return 0;
}
