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 maxn 55
#define maxm 255
#define inf 0x7fffffff
#define ll long long
#define rint register int
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x<<": "<<x<<endl
#define fgx cerr<<"--------------"<<endl
#define dgx cerr<<"=============="<<endl

using namespace std;
char str[maxn];
int A[maxn],dp[maxn][maxm*2][maxm*2];

inline int read(){
    int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}

int main(){
	scanf("%s",str+1);
	int n=strlen(str+1);
	for(int i=1;i<=n;i++) A[i+4]=str[i]-'0';
	n+=4;
	//for(int i=1;i<=n;i++) cout<<A[i]<<" ";
	//cout<<endl;
	memset(dp,63,sizeof(dp));
	dp[0][250][250]=0;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=500;j++)
			for(int k=0;k<=500;k++)
				for(int t=-6;t<=6;t++)
					if((j-250)*10-A[i]+k+t>=0 && (j-250)*10-A[i]+k+t<=500 && k+t>=0 && k+t<=500) 
						dp[i][(j-250)*10-A[i]+k+t][k+t]=min(dp[i][(j-250)*10-A[i]+k+t][k+t],dp[i-1][j][k]+abs(t*(n-i+1)));
	int ans=inf;
	for(int k=0;k<=500;k++) ans=min(ans,dp[n][250][k]);
	/*for(int i=0;i<=n;i++){
		for(int j=0;j<=500;j++)
			for(int k=0;k<=500;k++)
				if(dp[i][j][k]<100 && j-250>=-10 && j-250<=10) 
					cout<<i<<" "<<j-250<<" "<<k-250<<":"<<dp[i][j][k]<<endl;
	}*/
	printf("%d\n",ans);
	return 0;
}

