/* -*- coding: utf-8 -*- * * 1849.cc: No.1849 Three Times Value - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { ll n; scanf("%lld", &n); int k = 0; for (ll m = n; m > 0; m /= 10) k++; //printf("k=%d\n", k); int l = k / 3, r = k % 3; if (l == 0) { puts("0"); return 0; } ll t = 1; for (int i = 0; i < l; i++) t *= 10; ll x; if (r == 0) { x = n; for (int i = k; i > l; i--) x /= 10; } else { x = 0; for (int i = 0; i < l; i++) x = x * 10 + 9; } if (x * (t * t + t + 1) > n) x--; printf("%lld\n", x); return 0; }