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
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define INF (~(1<<31))
#define inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-8
#define PI 3.141592653589793238462643383
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define all(v) (v).begin(),(v).end()
#define dbg(x,y) cout<<(x)<<" = "<<(y)<< endl;
#define per(i,a,b) for(int i = a; i >= b; --i)
#define rep(i,a,b) for(int i = a; i <= b; ++i)
#define fi first
#define se second
#define ls (rt<<1)
#define rs (rt<<1|1)
#define ll long long
#define int ll
typedef bitset<2010> bt;
typedef unsigned long long ull;
typedef complex<double> comp;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;

const ll N = 4e2 + 4;
const ll M = 1e9 + 7;
const ll MAXN = 2e18 + 7;
const ll Mod = 998244353;
//const ll Mod = 1e9 + 7;

int _,i,j,k,n,m,p,s,T,t,l,r,o,u,v,w,x,y,z,ans,nex,sum,num,len,en,sx,sy,tx,ty,th,ma,mi,mod,cnt,la,op,res,flag,cas,bk,ret,mid,now,tmp,rt;
int c[N],dp[55][530][640];
char ch;
vector<int> g[N],h;
string s1,s2,s3,s4;

signed main()
{
    int T = 1;
    //scanf("%lld",&T);
    while(T--){
        cin >> s1;
        s1="00"+s1;
        n=s1.size();
        s1+=' ';
        reverse(all(s1));
        memset(dp,inf,sizeof dp);
        dp[n+1][260][320]=0;
        for(i = n;i >= 1;i--){
            x=s1[i]-'0';
            for(j = -255;j <= 255;j++){  //前差j
                for(k = -255;k <= 255;k++){   //后有k个111
    for(l = -6;l <= 6;l++){
        if(abs(j*10+x-l-k)<260) dp[i][j*10+x-k-l+260][k+l+320]=min(dp[i][j*10+x-l-k+260][k+l+320],dp[i+1][j+260][k+320]+i*abs(l));
    }
                }
            }
        }
        mi=MAXN;
        for(i = 0;i < 640;i++) mi=min(mi,dp[1][260][i]);
        printf("%lld\n",mi);
    }
    return 0;
}






