#include #include using namespace std; class Sugo{ private: int N; int w[10000]; bool e[10000]; public: Sugo(int n); int fanc(int n); }; Sugo::Sugo(int _N){ N = _N; for(int i = 0; i < N; i++){ e[i] = false; } for(int i = 0; i < N; i++){ int tw = 1,rest = i + 1; while(rest != 1){ if(rest%2) tw++; rest /= 2; } w[i] = tw; } e[N - 1] = true; } int Sugo::fanc(int n){ int c = 0; if(n == 1) return 1; for(int i = 0; i < N; i++){ if(( i + 1 + w[i] == n || i + 1 - w[i] == n )&& !e[i]){ e[i] = true; c += fanc(i + 1) + 1; e[i] = false; } } if(c == 0) return -1; else return c; } int main(){ int n; cin >> n; Sugo t(n); cout << t.fanc(n) << endl; }