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: Time Limit Exceeded)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

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

#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);

mt19937 mrand(random_device{} ()); 

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

void precalc() {
}

const int maxn = (int) 5e5 + 5;
int n;
char tmp[maxn];
int a[maxn];

int read() {
  if (scanf("%s", tmp) < 1) {
    return false;
  }
  n = strlen(tmp);
  for (int i = 0; i < n; i++) {
    a[i] = tmp[n - i - 1] - '0';
  }
  return true;
}

void add(int &n) {
  int i;
  for (i = 0; i < n; i++) {
    if (a[i] < 9) {
      a[i]++;
      return;
    }
    a[i] = 0;
  }
  if (i == n) {
    a[n++] = 1;
  }
}

void solve() {
  int res = 0;
  while (n) {
    while (n && !a[n - 1]) {
      n--;
    }
    if (!n) {
      break;
    }
    int cur = 0;
    int lst = n;
    while (n && a[n - 1] >= cur) {
      if (a[n - 1] > cur) {
        lst = n - 1;
      }
      cur = a[n - 1];
      n--;
    }
    res++;
    if (!n) {
      break;
    }
    n = lst;
    add(n);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}