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 <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;

const LL inf = 1e18;
LL f[55][505][505][2] , mxc , mxx , n;
char s[55];

LL dp(LL pos , LL c , LL x , LL delta) { // delta:the updating way of the (pos+1)th position 
	if(pos == n) return c?inf:0;
	if(c < -mxc || c > mxc || x < -mxx || x > mxx) return inf;
	if(f[pos][c + mxc][x + mxx][delta == 1] == -1) f[pos][c + mxc][x + mxx][delta == 1] = min(dp(pos , c , x + delta , delta) + n - pos , min(dp(pos + 1 , c * 10 + s[pos + 1] - '0' - x , x , 1) , dp(pos + 1 , c * 10 + s[pos + 1] - '0' - x , x , -1)));
	return f[pos][c + mxc][x + mxx][delta == 1]; 
}

int main() {
	scanf("%s" , s + 2) , n = strlen(s + 2) + 1; // +1 : pre zero
	mxx = n * 5 , mxc = mxx / 10 + 1;
	s[1] = '0';
	memset(f , -1 , sizeof f);
	printf("%lld" , dp(0 , 0 , 0 , 1)); 
	return 0;
}