#include #include #include #include using namespace std; constexpr int16_t pop_count(const int16_t a) { return a == INT16_C(0) ? INT16_C(0) : (a & INT16_C(1)) + pop_count(a >> INT16_C(1)); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int16_t N, i; cin >> N; vector dp(N, INT16_C(-1)); dp[0] = INT16_C(1); queue q; q.push(INT16_C(0)); while (!q.empty()) { const auto temp = pop_count(q.front() + INT16_C(1)); if (q.front() - temp >= INT16_C(0) && dp[q.front() - temp] == INT16_C(-1)) dp[q.front() - temp] = dp[q.front()] + INT16_C(1), q.push(q.front() - temp); if (q.front() + temp < N && dp[q.front() + temp] == INT16_C(-1)) dp[q.front() + temp] = dp[q.front()] + INT16_C(1), q.push(q.front() + temp); q.pop(); } cout << dp[N - INT16_C(1)] << '\n'; return 0; }