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>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define mp make_pair
#define endl '\n'

string s;
int ans = 1;

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> s;
    int n = s.length();
    reverse(s.begin(), s.end());
    int hi = n - 1, lo = n - 1;
    while(lo - 1 >= 0){
        if(s.back() == '0'){
            lo--, hi--;
            s.pop_back();
            continue;
        }
        if(s[lo] > s[lo - 1]){
            ans++;
            int prev = 0;
            //cout << "LO HI" << lo << ' ' << hi << endl;
            while(lo + 1 <= hi && s[lo] == s[lo + 1]){
                lo++;
            }
            for(int i = hi; i >= lo; i--) s.pop_back();
            hi = s.length() - 1;
            lo = s.length() - 1;
            //cout << lo << ' ' << hi << endl;
            s[0]++;
            for(int i = 0; i < s.length() - 1; i++){
                if(s[i] > '9'){
                    s[i] = '0';
                    s[i + 1]++;
                }
                else break;
            }
            /*for(int i = s.length() - 1; i >= 0; i--) cout << s[i];
            cout << endl;*/
        }
        else lo--;
    }
    cout << ans << endl;
    return 0;
}