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 rep(i, a, b) for(int i = a; i <= b; i++)
#define REP(i, a, b) for(int i = b; i >= a; i--)
using namespace std;
const int N = 55, J = 30, K = 155, inf = 1e7;

void cmin(int &x, int y) {if(x > y) x = y;}
void cmax(int &x, int y) {if(x < y) x = y;}

int n, f[N][J * 2 + 1][K * 2 + 1]; //f[i][j][k] 表示 i+1为还需要增量j 第0位受到增量k 时的最小花费。 
char a[N];

inline void upd(int i, int j, int k, int v) {
	if(-J <= j && j <= J && -K <= k && k <= K) 
		cmin(f[i][j + J][k + K], v);
}

int main() {
	scanf("%s", a);
	for(n = 0;a[n]; n++) a[n] -= '0';
	reverse(a, a + n);
	memset(f, 1, sizeof f);
	f[n][J][K + a[0]] = 0;
	REP(i, 1, n) {
		int x = a[i];
		rep(j, -J, J) rep(k, -K, K) if(f[i][j + J][k + K] < inf) 
			rep(d, -3, 3) upd(i - 1, -x + d * 10, k + d, f[i][j + J][k + K] + (i + 1) * abs(j + x - d));
	}
	int ans = inf;
	rep(j, -J, J) rep(k, -K, K) 
		cmin(ans, f[0][j + J][k + K] + abs(j + k));
	printf("%d\n", ans); return 0;
}

