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: Wrong Answer)

#include <cstdio>
#include <cstring>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define iter_r(i, n) for (int i = n; i >= 1; --i)

#define NR 501000

int a[NR], n, p[NR];
char s[NR];

void inc() {
	++a[n];
	iter_r(i, n) {
	//	printf("!!%d %d\n", i, a[i]);
		if (a[i] >= 10) {
			a[i] -= 10;
			++a[i - 1];
		} else {
			for (int j = i; j <= n; ++j)
				p[j] = (a[j] == a[j - 1] ? p[j - 1] : j);
			break;
		}
	}
}

int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	a[0] = -1;
	iter(i, n) {
		a[i] = s[i] - '0';
		p[i] = (a[i] == a[i - 1] ? p[i - 1] : i);
	}

	int lst = 0, ans = 0;
	iter(i, n) {
		if (a[i] > a[i + 1] || i == n) {
//			printf("!%d %d %d %d\n", i, a[i], a[i-1], n);
			inc(); ++ans; 
			if (p[i] != i) {
				for (int j = p[i]; j <= i; ++j) {
					for (; i < n && a[i] <= a[i + 1]; ++i)
						;
					bool exit = false;
					if (a[j] != a[i] || i == n) exit = true; 
					inc(); ++ans;
					if (exit) break;

				}
			}
			
		}
	}

	printf("%d\n", ans);

	return 0;
}