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 For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define B 500
#define inf 0x3f3f3f3f
char s[55];
int a[55],len,res;
int f[55][1003][1003];

signed main()
{
	cin>>s+1,len=strlen(s+1)+3;
	For(i,1,len-3)a[i+3]=s[i]-'0';
	memset(f,63,sizeof f),f[0][B][B]=0,res=inf;
	For(i,1,len)
		For(j,-B,B)
			For(k,-i*6,i*6)
			{
				if(f[i-1][j+B][k+B]==inf)continue;
				For(p,-6,6)
				{
					int x=j*10+k+p-a[i];
					if(x>=-B&&x<=B)f[i][x+B][k+p+B]=min(f[i][x+B][k+p+B],f[i-1][j+B][k+B]+abs(p)*(len-i+1));
				}
			}
	For(i,0,2*B)res=min(res,f[len][B][i]);
	cout<<res;
	return 0;
}