#include "bits/stdc++.h" using namespace std; using ll=long long; using ld=long double; using vi=vector; using vvi=vector; using vll=vector; using vvll=vector; using pii=pair; #define rep(i,n) for(int i=0;i<(n);i++) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define ALL(v) v.begin(),v.end() #define pb push_back templatebool chmax(T &a, const T &b) {if (abool chmin(T &a, const T &b) {if (bvoid printv(vector v){ll n=v.size(); rep(i,n){cout<void printvv(vector> v){for(auto V:v) printv(V);} //constexpr int INF=1001001001; //constexpr int mod=1e9+7; //constexpr int mod=998244353; int main(){ int n; cin>>n; string s=to_string(n); int m=(int)s.length(); vi dp(2); rep(j,m){ vi nx(2); rep(b,2){ int lim=b?(s[j]-'0'):9; for(int i=0;i<=lim;i+=3) nx[b&&i==lim]+=dp[b]; } int lim=j?9:s[j]-'0'; for(int i=3;i<=lim;i+=3) nx[j==0&&i==lim]++; swap(dp,nx); } int ans=dp[0]+dp[1]-3; //cout<