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>
#ifdef ALGO
#include "el_psy_congroo.hpp"
#else
#define DUMP(...) 1145141919810
#define CHECK(...) (__VA_ARGS__)
#endif

template<typename T> inline void minify(T& a, T b) { if (a > b) a = b; }

const int INF = 0x3f3f3f3f;
const int kN = 50 + 5;
int n;
int a[kN];

const int kCntBalance = 250;
const int kCarryBalance = 250;
int cache[kN][kCntBalance * 2 + 1][kCarryBalance * 2 + 1];

int calc(int at, int cnt, int carry) {
  if (at == -1) {
    return carry == 0 ? 0 : INF;
  }
  if (std::abs(cnt) > kCntBalance || std::abs(carry) > kCarryBalance) return INF;
  int& ret = cache[at][cnt + kCntBalance][carry + kCarryBalance];
  if (ret != -1) return ret;
  ret = INF;
  for (int i = -9; i <= 9; ++i) {
    minify(ret, calc(at - 1, cnt + i, (carry + a[at] - cnt - i) * 10) + std::abs(i) * (at + 1));
  }
  return ret;
}

int solve() {
  memset(cache, -1, sizeof(cache));
  return calc(n, 0, 0);
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::istream& reader = std::cin;

  std::string s;
  reader >> s;
  n = s.length();
  for (int i = 0; i < n; ++i) {
    a[n - 1 - i] = s[i] - '0';
  }
  std::cout << solve() << std::endl;
}