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)

#include <bits/stdc++.h>
#define pb push_back
using namespace std;

string n, s;

bool ok(long long k) {
	string w = s;
	string x = to_string(9ll * k);
	if (w.size() < x.size()) {
		int dif = x.size() - w.size();
		for (int i = 0; i < dif; i++) w = "0" + w;
	} else {
		int dif = w.size() - x.size();
		for (int i = 0; i < dif; i++) x = "0" + x;
	}
	int len = w.size();
	int carry = 0;
	for (int i = len - 1; i >= 0; i--) {
		int add = (w[i] - '0') + (x[i] - '0') + carry;
		carry = add / 10;
		w[i] = (add % 10) + '0';
	}
	while (carry) {
		int add = carry % 10;
		string c;
		c.pb(carry + '0');
		w = c + w;
		carry /= 10;
	}
	long long sum = 0;
	for (int i = 0; i < w.size(); i++) sum += w[i] - '0';
	return sum <= 9ll * k;
}

void subtract() {
	int carry = 0;
	for (int i = s.size() - 1; i >= 0; i--) {
		s[i] -= carry;
		if (s[i] >= '0') carry = 0;
		s[i] = max(s[i], '0'); 
		if (s[i] < n[i]) carry++;
		s[i] = ((s[i] - '0' - (n[i] - '0') + 10) % 10) + '0';
	}
}

int main() {
	cin >> n;
	s = n + "0";
	n = "0" + n;
	subtract();
	long long low = 0, high = 1000000000000ll, mid;
	while (low < high) {
		long long mid = low + high >> 1ll;
		if (ok(mid)) high = mid;
		else low = mid + 1;
	}
	cout << low << endl;
	return 0;
}