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: Accepted)

#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 1000010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,ans;

char st[maxn];

int A[maxn];

int num[maxn],L,R;

void solve(){
	RREP(i,R,L+1)if(A[num[i]]>A[num[i-1]]){
		R=i;num[R]--;n=num[R];if(L<R&&num[R]==num[R-1])R--;
		
		int j;
		for(j=1;j<=n;j++){
			A[j]++;
			if(A[j]==10)A[j]=0;
			else break;
		}
		
		while(L<=R&&num[L]<=j)L++;
		
		A[n+1]=-1;
		
		RREP(k,j,1)if(A[k]!=A[k+1])num[--L]=k;
		
		return;
	}
	n=0;
	/*RREP(i,n,2)if(A[i]>A[i-1]){
		while(i<n&&A[i+1]==A[i])i++;
		n=i;
		REP(i,1,n-1){
			A[i]++;
			if(A[i]==10)A[i]=0;
			else break;
		}
		A[n]=0;
		while(n&&!A[n])n--;
		return;
	}
	n=0;*/
}

int lst[maxn],m;

void print(){
	REP(i,1,n)lst[i]-=A[i];
	REP(i,1,m)if(lst[i]<0)lst[i]+=10,lst[i+1]-=1;
	while(m&&!lst[m])m--;
	lst[m+1]=0;
/*	RREP(i,m,1){
		printf("%d",lst[i]);
	//	assert(lst[i]>=lst[i+1]);
	}cout<<endl;*/
}

void Work(){
	while(n){
		ans++,solve();
//		print();
//		RREP(i,n,1)cout<<A[i];cout<<endl;
	}
	iout(ans);
}

void Init(){
	scanf("%s",st+1);
	n=strlen(st+1);
	REP(i,1,n)A[i]=st[n-i+1]-'0';
	L=500000;R=L-1;
	REP(i,1,n)if(A[i]!=A[i+1])num[++R]=i;
}

int main(){
	Init();
	Work();
	return 0;
}