#include using namespace std; int main(){ int N; cin >> N; int N2 = N; vector D(11); for(int i=0; i<11; i++){ D[i] = N2 % 10; N2 /= 10; } static int dp[11][2]; dp[10][0] = 1; for(int i=9; i>=0; i--) for(int l=0; l<2; l++) for(int d : {0, 3, 6, 9}){ if(l==0 && d > D[i]) continue; dp[i][l|(d