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++ (GCC 5.4.1) (judge verdict: Accepted)

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 6;
char input[maxn];
int Num[maxn], tmp[maxn], mx, mx_tmp, Tot;

void Add() {
  if (mx_tmp > mx) swap(Num, tmp), swap(mx, mx_tmp);
  for (int i = 0; i <= mx_tmp; i++) {
    Num[i] += tmp[i], Tot += tmp[i];
    while (Num[i] >= 10) Num[i + 1]++, Num[i] -= 10, Tot -= 9;
  }
  for (int i = mx_tmp + 1; i <= mx && Num[i] >= 10; i++)
    while (Num[i] >= 10) Num[i + 1]++, Num[i] -= 10, Tot -= 9;
  while (Num[mx + 1]) mx++;
}

int main() {
  scanf("%s", input), mx = strlen(input);
  reverse(input, input + mx), mx--;
  for (int i = 0; i <= mx; i++) Tot += Num[i] = input[i] - '0';
  memcpy(tmp, Num, sizeof(tmp)), mx_tmp = mx;
  for (int i = 1; i <= 8; i++) Add();
  memset(tmp, 0, sizeof(tmp)), tmp[mx_tmp = 0] = 9;
  for (int i = 0; i <= 528180; i++) {
    if (Tot <= i * 9) return printf("%d\n", i), 0;
    Add();
  }
  printf("-1");
  return 0;
}