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:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define dbg1(x) cerr<<#x<<"="<<(x)<<" "
#define dbg2(x) cerr<<#x<<"="<<(x)<<"\n"
const int A=200,B=330,INF=0x3f3f3f3f;
void Min(int &x,int y){x=min(x,y);}
int n,dp[55][A*2+5][B*2+5];
//111111*6=1111111-111111*4-1
//1*6=11-1*5
string s;
int main(){
	cin>>s;
	s="0000"+s;
	memset(dp,INF,sizeof dp);
	dp[0][A][B]=0;
	n=s.length();
	for(int i=0;i<n;++i){
		for(int j=-A;j<=A;++j){
			for(int k=-6*i;k<=6*i;++k){
				if(dp[i][j+A][k+B]==INF)continue;
				//dbg1(i),dbg1(j),dbg1(k),dbg2(dp[i][j+A][k+B]);
				for(int l=-6;l<=6;++l){
					int nk=k+l;
					int nj=j*10+nk-(s[i]-'0');
					if(nj<-A || nj>A)continue;
					Min(dp[i+1][nj+A][nk+B],dp[i][j+A][k+B]+(n-i)*abs(l));
				}
			}
		}
	}
	int ans=INF;
	for(int k=-6*n;k<=6*n;++k){
		ans=min(ans,dp[n][A][k+B]);
	}
	printf("%d\n",ans);
	return 0;
}