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 Fread

#ifdef Fread
#define getchar() ((p1 == p2 && p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin)) ? EOF : *p1 ++)
char buf[1 << 21], *p1, *p2;
#endif // Fread

template <typename T>
void r1(T &x) {
	x = 0;
	char c(getchar());
	int f(1);
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(; isdigit(c);c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}

const int maxn = 60;
const int maxm = 6e2 + 5;

typedef int room[maxn];

int n, m;
char s[maxn];
int f[maxn][maxn][maxm][2];
const int inf = 0x3f3f3f3f;
int mxx, mxsum;
int dfs(int i,int sum,int x, int flag) {
    if(i == n) return sum ? inf : 0;
    if(sum > mxsum || sum < -mxsum || x > mxx || x < -mxx) return inf;
    if(f[i][sum + mxsum][x + mxx][flag == 1] != -1) return f[i][sum + mxsum][x + mxx][flag == 1];
    #define res f[i][sum + mxsum][x + mxx][flag == 1]
    res = min(dfs(i, sum, x + flag, flag) + n - i, min(dfs(i + 1, sum * 10 + (int)(s[i + 1]) - x, x, 1), dfs(i + 1, sum * 10 + (int)(s[i + 1]) - x, x, -1)));
    return res;
}
// 最高位是 1
signed main() {
	int i, j;
	scanf("%s", s + 2);
	n = strlen(s + 2) + 1;
	s[1] = '0'; // 方便转移
	for(i = 1; i <= n; ++ i) s[i] ^= 48;
//	puts("ZZZ");
    memset(f, -1, sizeof(f));
    mxx = 5 * (n + 1), mxsum = (mxx + 9) / 10 + 1;
    printf("%d\n", dfs(0, 0, 0, 1));
	return 0;
}