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;
const int INF=0x3f3f3f;
int dp[60][510][510];
char s[60];

void minn(int &u,int v)
{
	u=min(u,v);
}

int main()
{
	scanf("%s",s+5);
	for(int i=1;i<=4;++i)
        s[i]='0';
	int l=strlen(s+1);
	memset(dp,0x3f,sizeof(dp));
	dp[0][250][250]=0;
	for(int i=0;i<l;i++)
		for(int j=-250;j<=250;j++)
			for(int k=-250;k<=250;k++)
				for(int h=-6;h<=6;h++)
				{
					int t1=k+h;
					int t2=j*10+s[i+1]-'0'-t1;
					if(abs(t1)>250||abs(t2)>250)
                        continue;
					minn(dp[i+1][t2+250][t1+250],dp[i][j+250][k+250]+abs(h)*(l-i));
				}
	int ans=INF;
	for(int i=-250;i<=250;++i)
		ans=min(ans,dp[l][250][i+250]);
	cout<<ans<<endl;
}