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 <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define spln(i,n) (i==n?'\n':' ')
using namespace std;
int n,m,i,j,l,r,mid,ans;
string st,mem;
bool check(int x)
{
	st=mem;
	int s=x*9,i,j;
	fz1(i,n){
//		cerr<<st<<endl; 
		if(s<st[i]-'0') return 0;
		while(s%10!=(st[i]-'0')) s--;
		if(i+8>=n){
			int t=0;
			fd(j,n,i) t=t*10+st[j]-'0';
			s=min(s,t);
		}
		int t=s;
		fz(j,i,n){
			st[j]-=t%10;
			if(st[j]<'0'){
				st[j+1]--;
				st[j]+=10;
			}
			t/=10;if(!t&&(j==n||st[j+1]>='0')) break;
		}
	}
	return 1;
}
int main()
{
	rdst(st,500005);n=st.length();reverse(st.begin(),st.end());st=" "+st;mem=st;
	l=0;r=n;
	while(l<r){
		mid=(l+r+1)/2;
		if(check(mid)){
			r=mid-1;
			ans=mid;
		}
		else l=mid;
	}
	cout<<ans<<endl;
	return 0;
}