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 <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <cstring>
#include <cassert>
#include <chrono>
#include <functional>
#include <random>

using namespace std;

#define X first
#define Y second
//#define all(v) (v).begin(), (v).end()
#define inb push_back
#define mk make_pair

#pragma GCC optimization ("O3")

const int64_t MOD = 998244353;
const int INF = 1000 * 1000 * 1000 + 7;
const int MAX_N = 50 + 7;
const int MAX_B = 2 * 10 * MAX_N;
const int MAX_K = 2 * MAX_N;

int a[MAX_N];
int dp[MAX_N][MAX_B][MAX_K];

int mod10(int x) {
  if (x >= 0) {
    return x % 10;
  } else {
    return (10 - (-x % 10)) % 10;
  }
}

int bal(int x) {
  return x - 10 * MAX_N;
}

int ind(int b) {
  return b + 10 * MAX_N;
}

int kval(int k) {
  return k - MAX_N;
}

int kind(int val) {
  return val + MAX_N;
}

int le(int x, int b, int k) {
  return -mod10(-(k + x - b));
}
int gr(int x, int b, int k) {
  return mod10(k + x - b);
}

void update(int i, int j, int k, int val) {
  if (0 <= j && j < MAX_B) {
    dp[i][j][k] = min(dp[i][j][k], val);
  }
}

int solve() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; ++i) {
    a[i + 1] = s[i] - '0';
  }
  a[0] = 0;
  for (int i = 0 ; i <= n; ++i) {
    for (int j = 0; j < MAX_B; ++j) {
      for (int k = 0; k < MAX_K; ++k) {
        dp[i][j][k] = INF;
      }
    }
  }
  for (int i = 0; i < 2; ++i) {
    dp[0][ind(i)][kind(i)] = (n + 1) * i;
  }

  for (int i = 1; i <= n; ++i) {
    for (int x = 0; x < MAX_B; ++x) {
      for (int k = 0; k < MAX_K; ++k) {
//        if (dp[i - 1][x][k] == INF)
//          continue;

        int b = bal(x);
        int h = le(a[i], b, kval(k));
        int prev_k = (kval(k) + a[i] - h - b) / 10;
        update(i, x + h, k, dp[i - 1][x][kind(prev_k)] + (n + 1 - i) * abs(h));
        h = gr(a[i], b, kval(k));
        prev_k = (kval(k) + a[i] - h - b) / 10;
        update(i, x + h, k, dp[i - 1][x][kind(prev_k)] + (n + 1 - i) * abs(h));
      }
    }
  }

  int ans = INF;
  for (int b = 0; b < MAX_B; ++b) {
    ans = min(ans, dp[n][b][kind(0)]);
  }

  cout << ans << '\n';
  return 0;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
//  precalc();
//   int t;
//   cin >> t;
//   while (t--)
  solve();
  return 0;
}