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 N = 510,M = 55,inf = 0x7f7f7f7f ;
int l,f[M][M][N][2],C,X ; char str[N] ;
#define f(pos,c,x,delta) f[pos][c+C][x+X][delta]
inline int dfs(int pos,int c,int x,int delta){
	if(pos == l) return c ? inf : 0 ;
	if(c > C || c < -C || x > X || x < -X) return inf ; 
	if(f(pos,c,x,delta) != -1) return f(pos,c,x,delta) ;
	f(pos,c,x,delta) = min(dfs(pos,c,x+(delta ? 1 : -1),delta)+l-pos,min(dfs(pos+1,c*10+str[pos+1]-x,x,1),dfs(pos+1,c*10+str[pos+1]-x,x,0))) ;
	return f(pos,c,x,delta) ; 
}
int main(){
	//freopen("in.txt","r",stdin) ;
	str[1] = 0 ; scanf("%s",str+2) ;
	l = strlen(str+2)+1 ;
	for(int i = 2 ; i <= l ; i++) str[i] = str[i]-'0' ;
	X = 5*l ; C = X/10+1 ; memset(f,-1,sizeof f) ; 
	printf("%d\n",dfs(0,0,0,1)) ; 
	return 0 ;  
}