Problem:
Score : 1300 points

Problem Statement

We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left.
For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are not.

Snuke has an integer N. Find the minimum number of increasing integers that can represent N as their sum.

Constraints

1 \leq N \leq 10^{500000}

Input

The input is given from Standard Input in the following format:

N

Output

Print the minimum number of increasing integers that can represent N as their sum.

Sample Input 1

80

Sample Output 1

2

One possible representation is 80 = 77 + 3.

Sample Input 2

123456789

Sample Output 2

1

123456789 in itself is increasing, and thus it can be represented as the sum of one increasing integer.

Sample Input 3

20170312

Sample Output 3

4

Sample Input 4

7204647845201772120166980358816078279571541735614841625060678056933503

Sample Output 4

31

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

const int mod = (int) 1e9 + 7;

void add(int &x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int mult(int x, int y) {
  return (long long) x * y % mod;
}

int myPower(int x, int pw) {
  int res = 1;
  for (; pw; pw >>= 1) {
    if (pw & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
  }
  return res;
}

void precalc() {
}


const int maxn = (int) 5e5 + 10;
char s[maxn];

int n;

int read() {
  if (scanf("%s", s) < 1) {
    return 0;
  }
  return 1;
}

int a[maxn];

void solve() {
  int n = (int) strlen(s);
  for (int i = 0; i < n; ++i) {
    a[i] = s[i] - '0';
  }
  reverse(a, a + n);
  
  for (int i = 0; i < n; ++i) {
    a[i] *= 9;
  }
  for (int i = 0; i < n; ++i) {
    if (a[i] >= 10) {
      int k = a[i] / 10;
      a[i] %= 10;
      if (i + 1 == n) {
        a[n++] = k;
      } else {
        a[i + 1] += k;
      }
    }
  }

  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += a[i];
  }

  for (int res = 0;; ++res) {
    /*eprintf("res = %d (sum=%d): ", res, sum);
    for (int i = 0; i < n; ++i) {
      assert(0 <= a[i] && a[i] < 10);
      eprintf("%d", a[i]);
    }
    eprintf("\n");
    */
    if (res >= sum && a[0] == 0) {
      printf("%d\n", (res + 8) / 9);
      return;
    }

    ++sum;
    a[0] += 1;
    for (int i = 0; i < n && a[i] >= 10; ++i) {
      a[i] -= 10;
      sum -= 10;
      ++sum;
      if (i + 1 == n) {
        a[n++] = 1;
        break;
      }
      a[i + 1] += 1;
    }
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}