#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector money(1, 1); int k = 2; while((ll)k * (k + 1) / 2 <= N){ money.emplace_back(k * (k + 1) / 2); ++k; } int n = money.size(); ll ans = 1e+17; for(int i = n - 1; i >= 0; --i){ ll cnt = N / money[i]; int rest = N - money[i] * cnt; while(rest > 0){ int j = prev(upper_bound(begin(money), end(money), rest)) - begin(money); cnt += rest / money[j]; rest -= rest / money[j] * money[j]; } chmin(ans, cnt); } cout << ans << '\n'; return 0; }