#ifndef HIDDEN_IN_VS // 折りたたみ用 // 警告の抑制 #define _CRT_SECURE_NO_WARNINGS // ライブラリの読み込み #include using namespace std; // 型名の短縮 using ll = long long; using ull = unsigned long long; // -2^63 ~ 2^63 = 9e18(int は -2^31 ~ 2^31 = 2e9) using pii = pair; using pll = pair; using pil = pair; using pli = pair; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vl = vector; using vvl = vector; using vvvl = vector; using vvvvl = vector; using vb = vector; using vvb = vector; using vvvb = vector; using vc = vector; using vvc = vector; using vvvc = vector; using vd = vector; using vvd = vector; using vvvd = vector; template using priority_queue_rev = priority_queue, greater>; using Graph = vvi; // 定数の定義 const double PI = acos(-1); int DX[4] = { 1, 0, -1, 0 }; // 4 近傍(下,右,上,左) int DY[4] = { 0, 1, 0, -1 }; int INF = 1001001001; ll INFL = 4004004003094073385LL; // (int)INFL = INF, (int)(-INFL) = -INF; // 入出力高速化 struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp; // 汎用マクロの定義 #define all(a) (a).begin(), (a).end() #define sz(x) ((int)(x).size()) #define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), (x))) #define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), (x))) #define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");} #define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順 #define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順 #define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順 #define repe(v, a) for(const auto& v : (a)) // a の全要素(変更不可能) #define repea(v, a) for(auto& v : (a)) // a の全要素(変更可能) #define repb(set, d) for(int set = 0, set##_ub = 1 << int(d); set < set##_ub; ++set) // d ビット全探索(昇順) #define repis(i, set) for(int i = lsb(set), bset##i = set; i < 32; bset##i -= 1 << i, i = lsb(bset##i)) // set の全要素(昇順) #define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て(昇順) #define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去 #define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了 #define inQ(x, y, u, l, d, r) ((u) <= (x) && (l) <= (y) && (x) < (d) && (y) < (r)) // 半開矩形内判定 // 汎用関数の定義 template inline ll powi(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; } template inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新(更新されたら true を返す) template inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新(更新されたら true を返す) template inline T getb(T set, int i) { return (set >> i) & T(1); } template inline T smod(T n, T m) { n %= m; if (n < 0) n += m; return n; } // 非負mod // 演算子オーバーロード template inline istream& operator>>(istream& is, pair& p) { is >> p.first >> p.second; return is; } template inline istream& operator>>(istream& is, vector& v) { repea(x, v) is >> x; return is; } template inline vector& operator--(vector& v) { repea(x, v) --x; return v; } template inline vector& operator++(vector& v) { repea(x, v) ++x; return v; } #endif // 折りたたみ用 #if __has_include() #include using namespace atcoder; #ifdef _MSC_VER #include "localACL.hpp" #endif //using mint = modint998244353; using mint = static_modint<(int)1e9+7>; //using mint = modint; // mint::set_mod(m); using vm = vector; using vvm = vector; using vvvm = vector; using vvvvm = vector; using pim = pair; #endif #ifdef _MSC_VER // 手元環境(Visual Studio) #include "local.hpp" #else // 提出用(gcc) int mute_dump = 0; int frac_print = 0; #if __has_include() namespace atcoder { inline istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; } inline ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; } } #endif inline int popcount(int n) { return __builtin_popcount(n); } inline int popcount(ll n) { return __builtin_popcountll(n); } inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : 32; } inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : 64; } inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; } inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; } #define dump(...) #define dumpel(v) #define dump_math(v) #define input_from_file(f) #define output_to_file(f) #define Assert(b) { if (!(b)) { vc MLE(1<<30); EXIT(MLE.back()); } } // RE の代わりに MLE を出す #endif // O(n^2) の愚直 ll naive(ll n) { ll res = 0; repi(i, 1, n) { res += popcount(i); } return res; } //【桁の数の取得】O(log n) /* * n を b 進表記したときの桁の数字を上位桁から順に並べたリストを返す. * * 制約:b ≧ 2 */ vi integer_digits(ll n, int b = 10) { // verify : https://atcoder.jp/contests/abc105/tasks/abc105_c Assert(abs(b) >= 2); // n = 0 の場合の例外処理 if (n == 0) return vi{ 0 }; // mod |b| を取れば最下位桁から順に決定していく. vi ds; while (n != 0) { int d = (int)(n % b); //int d = (int)smod(n, abs(b)); // 負数の可能性があるならこっち ds.push_back(d); n = (n - d) / b; } // 上位桁から順になるように並べ直す. reverse(all(ds)); return ds; } // 愚直で学習用データを集める. void zikken() { // bit列 → 値 vector> data; repi(n, 0, 100) { auto res = naive(n); auto ds = integer_digits(n, 2); while (sz(ds) < 10) { data.push_back({ ds, res }); ds.insert(ds.begin(), 0); } } // 整形して出力 string out; out += "data=Association["; for (auto [key, val] : data) { out += "{"; repe(d, key) out += to_string(d) + ","; out.pop_back(); out += "}->" + to_string(val) + ","; } out.pop_back(); out += "];"; cout << out << endl; exit(0); } /* data=Association[{0}->0,{0,0}->0,{0,0,0}->0,{0,0,0,0}->0,{0,0,0,0,0}->0,{0,0,0,0,0,0}->0,{0,0,0,0,0,0,0}->0,{0,0,0,0,0,0,0,0}->0,{0,0,0,0,0,0,0,0,0}->0,{1}->1,{0,1}->1,{0,0,1}->1,{0,0,0,1}->1,{0,0,0,0,1}->1,{0,0,0,0,0,1}->1,{0,0,0,0,0,0,1}->1,{0,0,0,0,0,0,0,1}->1,{0,0,0,0,0,0,0,0,1}->1,{1,0}->2,{0,1,0}->2,{0,0,1,0}->2,{0,0,0,1,0}->2,{0,0,0,0,1,0}->2,{0,0,0,0,0,1,0}->2,{0,0,0,0,0,0,1,0}->2,{0,0,0,0,0,0,0,1,0}->2,{1,1}->4,{0,1,1}->4,{0,0,1,1}->4,{0,0,0,1,1}->4,{0,0,0,0,1,1}->4,{0,0,0,0,0,1,1}->4,{0,0,0,0,0,0,1,1}->4,{0,0,0,0,0,0,0,1,1}->4,{1,0,0}->5,{0,1,0,0}->5,{0,0,1,0,0}->5,{0,0,0,1,0,0}->5,{0,0,0,0,1,0,0}->5,{0,0,0,0,0,1,0,0}->5,{0,0,0,0,0,0,1,0,0}->5,{1,0,1}->7,{0,1,0,1}->7,{0,0,1,0,1}->7,{0,0,0,1,0,1}->7,{0,0,0,0,1,0,1}->7,{0,0,0,0,0,1,0,1}->7,{0,0,0,0,0,0,1,0,1}->7,{1,1,0}->9,{0,1,1,0}->9,{0,0,1,1,0}->9,{0,0,0,1,1,0}->9,{0,0,0,0,1,1,0}->9,{0,0,0,0,0,1,1,0}->9,{0,0,0,0,0,0,1,1,0}->9,{1,1,1}->12,{0,1,1,1}->12,{0,0,1,1,1}->12,{0,0,0,1,1,1}->12,{0,0,0,0,1,1,1}->12,{0,0,0,0,0,1,1,1}->12,{0,0,0,0,0,0,1,1,1}->12,{1,0,0,0}->13,{0,1,0,0,0}->13,{0,0,1,0,0,0}->13,{0,0,0,1,0,0,0}->13,{0,0,0,0,1,0,0,0}->13,{0,0,0,0,0,1,0,0,0}->13,{1,0,0,1}->15,{0,1,0,0,1}->15,{0,0,1,0,0,1}->15,{0,0,0,1,0,0,1}->15,{0,0,0,0,1,0,0,1}->15,{0,0,0,0,0,1,0,0,1}->15,{1,0,1,0}->17,{0,1,0,1,0}->17,{0,0,1,0,1,0}->17,{0,0,0,1,0,1,0}->17,{0,0,0,0,1,0,1,0}->17,{0,0,0,0,0,1,0,1,0}->17,{1,0,1,1}->20,{0,1,0,1,1}->20,{0,0,1,0,1,1}->20,{0,0,0,1,0,1,1}->20,{0,0,0,0,1,0,1,1}->20,{0,0,0,0,0,1,0,1,1}->20,{1,1,0,0}->22,{0,1,1,0,0}->22,{0,0,1,1,0,0}->22,{0,0,0,1,1,0,0}->22,{0,0,0,0,1,1,0,0}->22,{0,0,0,0,0,1,1,0,0}->22,{1,1,0,1}->25,{0,1,1,0,1}->25,{0,0,1,1,0,1}->25,{0,0,0,1,1,0,1}->25,{0,0,0,0,1,1,0,1}->25,{0,0,0,0,0,1,1,0,1}->25,{1,1,1,0}->28,{0,1,1,1,0}->28,{0,0,1,1,1,0}->28,{0,0,0,1,1,1,0}->28,{0,0,0,0,1,1,1,0}->28,{0,0,0,0,0,1,1,1,0}->28,{1,1,1,1}->32,{0,1,1,1,1}->32,{0,0,1,1,1,1}->32,{0,0,0,1,1,1,1}->32,{0,0,0,0,1,1,1,1}->32,{0,0,0,0,0,1,1,1,1}->32,{1,0,0,0,0}->33,{0,1,0,0,0,0}->33,{0,0,1,0,0,0,0}->33,{0,0,0,1,0,0,0,0}->33,{0,0,0,0,1,0,0,0,0}->33,{1,0,0,0,1}->35,{0,1,0,0,0,1}->35,{0,0,1,0,0,0,1}->35,{0,0,0,1,0,0,0,1}->35,{0,0,0,0,1,0,0,0,1}->35,{1,0,0,1,0}->37,{0,1,0,0,1,0}->37,{0,0,1,0,0,1,0}->37,{0,0,0,1,0,0,1,0}->37,{0,0,0,0,1,0,0,1,0}->37,{1,0,0,1,1}->40,{0,1,0,0,1,1}->40,{0,0,1,0,0,1,1}->40,{0,0,0,1,0,0,1,1}->40,{0,0,0,0,1,0,0,1,1}->40,{1,0,1,0,0}->42,{0,1,0,1,0,0}->42,{0,0,1,0,1,0,0}->42,{0,0,0,1,0,1,0,0}->42,{0,0,0,0,1,0,1,0,0}->42,{1,0,1,0,1}->45,{0,1,0,1,0,1}->45,{0,0,1,0,1,0,1}->45,{0,0,0,1,0,1,0,1}->45,{0,0,0,0,1,0,1,0,1}->45,{1,0,1,1,0}->48,{0,1,0,1,1,0}->48,{0,0,1,0,1,1,0}->48,{0,0,0,1,0,1,1,0}->48,{0,0,0,0,1,0,1,1,0}->48,{1,0,1,1,1}->52,{0,1,0,1,1,1}->52,{0,0,1,0,1,1,1}->52,{0,0,0,1,0,1,1,1}->52,{0,0,0,0,1,0,1,1,1}->52,{1,1,0,0,0}->54,{0,1,1,0,0,0}->54,{0,0,1,1,0,0,0}->54,{0,0,0,1,1,0,0,0}->54,{0,0,0,0,1,1,0,0,0}->54,{1,1,0,0,1}->57,{0,1,1,0,0,1}->57,{0,0,1,1,0,0,1}->57,{0,0,0,1,1,0,0,1}->57,{0,0,0,0,1,1,0,0,1}->57,{1,1,0,1,0}->60,{0,1,1,0,1,0}->60,{0,0,1,1,0,1,0}->60,{0,0,0,1,1,0,1,0}->60,{0,0,0,0,1,1,0,1,0}->60,{1,1,0,1,1}->64,{0,1,1,0,1,1}->64,{0,0,1,1,0,1,1}->64,{0,0,0,1,1,0,1,1}->64,{0,0,0,0,1,1,0,1,1}->64,{1,1,1,0,0}->67,{0,1,1,1,0,0}->67,{0,0,1,1,1,0,0}->67,{0,0,0,1,1,1,0,0}->67,{0,0,0,0,1,1,1,0,0}->67,{1,1,1,0,1}->71,{0,1,1,1,0,1}->71,{0,0,1,1,1,0,1}->71,{0,0,0,1,1,1,0,1}->71,{0,0,0,0,1,1,1,0,1}->71,{1,1,1,1,0}->75,{0,1,1,1,1,0}->75,{0,0,1,1,1,1,0}->75,{0,0,0,1,1,1,1,0}->75,{0,0,0,0,1,1,1,1,0}->75,{1,1,1,1,1}->80,{0,1,1,1,1,1}->80,{0,0,1,1,1,1,1}->80,{0,0,0,1,1,1,1,1}->80,{0,0,0,0,1,1,1,1,1}->80,{1,0,0,0,0,0}->81,{0,1,0,0,0,0,0}->81,{0,0,1,0,0,0,0,0}->81,{0,0,0,1,0,0,0,0,0}->81,{1,0,0,0,0,1}->83,{0,1,0,0,0,0,1}->83,{0,0,1,0,0,0,0,1}->83,{0,0,0,1,0,0,0,0,1}->83,{1,0,0,0,1,0}->85,{0,1,0,0,0,1,0}->85,{0,0,1,0,0,0,1,0}->85,{0,0,0,1,0,0,0,1,0}->85,{1,0,0,0,1,1}->88,{0,1,0,0,0,1,1}->88,{0,0,1,0,0,0,1,1}->88,{0,0,0,1,0,0,0,1,1}->88,{1,0,0,1,0,0}->90,{0,1,0,0,1,0,0}->90,{0,0,1,0,0,1,0,0}->90,{0,0,0,1,0,0,1,0,0}->90,{1,0,0,1,0,1}->93,{0,1,0,0,1,0,1}->93,{0,0,1,0,0,1,0,1}->93,{0,0,0,1,0,0,1,0,1}->93,{1,0,0,1,1,0}->96,{0,1,0,0,1,1,0}->96,{0,0,1,0,0,1,1,0}->96,{0,0,0,1,0,0,1,1,0}->96,{1,0,0,1,1,1}->100,{0,1,0,0,1,1,1}->100,{0,0,1,0,0,1,1,1}->100,{0,0,0,1,0,0,1,1,1}->100,{1,0,1,0,0,0}->102,{0,1,0,1,0,0,0}->102,{0,0,1,0,1,0,0,0}->102,{0,0,0,1,0,1,0,0,0}->102,{1,0,1,0,0,1}->105,{0,1,0,1,0,0,1}->105,{0,0,1,0,1,0,0,1}->105,{0,0,0,1,0,1,0,0,1}->105,{1,0,1,0,1,0}->108,{0,1,0,1,0,1,0}->108,{0,0,1,0,1,0,1,0}->108,{0,0,0,1,0,1,0,1,0}->108,{1,0,1,0,1,1}->112,{0,1,0,1,0,1,1}->112,{0,0,1,0,1,0,1,1}->112,{0,0,0,1,0,1,0,1,1}->112,{1,0,1,1,0,0}->115,{0,1,0,1,1,0,0}->115,{0,0,1,0,1,1,0,0}->115,{0,0,0,1,0,1,1,0,0}->115,{1,0,1,1,0,1}->119,{0,1,0,1,1,0,1}->119,{0,0,1,0,1,1,0,1}->119,{0,0,0,1,0,1,1,0,1}->119,{1,0,1,1,1,0}->123,{0,1,0,1,1,1,0}->123,{0,0,1,0,1,1,1,0}->123,{0,0,0,1,0,1,1,1,0}->123,{1,0,1,1,1,1}->128,{0,1,0,1,1,1,1}->128,{0,0,1,0,1,1,1,1}->128,{0,0,0,1,0,1,1,1,1}->128,{1,1,0,0,0,0}->130,{0,1,1,0,0,0,0}->130,{0,0,1,1,0,0,0,0}->130,{0,0,0,1,1,0,0,0,0}->130,{1,1,0,0,0,1}->133,{0,1,1,0,0,0,1}->133,{0,0,1,1,0,0,0,1}->133,{0,0,0,1,1,0,0,0,1}->133,{1,1,0,0,1,0}->136,{0,1,1,0,0,1,0}->136,{0,0,1,1,0,0,1,0}->136,{0,0,0,1,1,0,0,1,0}->136,{1,1,0,0,1,1}->140,{0,1,1,0,0,1,1}->140,{0,0,1,1,0,0,1,1}->140,{0,0,0,1,1,0,0,1,1}->140,{1,1,0,1,0,0}->143,{0,1,1,0,1,0,0}->143,{0,0,1,1,0,1,0,0}->143,{0,0,0,1,1,0,1,0,0}->143,{1,1,0,1,0,1}->147,{0,1,1,0,1,0,1}->147,{0,0,1,1,0,1,0,1}->147,{0,0,0,1,1,0,1,0,1}->147,{1,1,0,1,1,0}->151,{0,1,1,0,1,1,0}->151,{0,0,1,1,0,1,1,0}->151,{0,0,0,1,1,0,1,1,0}->151,{1,1,0,1,1,1}->156,{0,1,1,0,1,1,1}->156,{0,0,1,1,0,1,1,1}->156,{0,0,0,1,1,0,1,1,1}->156,{1,1,1,0,0,0}->159,{0,1,1,1,0,0,0}->159,{0,0,1,1,1,0,0,0}->159,{0,0,0,1,1,1,0,0,0}->159,{1,1,1,0,0,1}->163,{0,1,1,1,0,0,1}->163,{0,0,1,1,1,0,0,1}->163,{0,0,0,1,1,1,0,0,1}->163,{1,1,1,0,1,0}->167,{0,1,1,1,0,1,0}->167,{0,0,1,1,1,0,1,0}->167,{0,0,0,1,1,1,0,1,0}->167,{1,1,1,0,1,1}->172,{0,1,1,1,0,1,1}->172,{0,0,1,1,1,0,1,1}->172,{0,0,0,1,1,1,0,1,1}->172,{1,1,1,1,0,0}->176,{0,1,1,1,1,0,0}->176,{0,0,1,1,1,1,0,0}->176,{0,0,0,1,1,1,1,0,0}->176,{1,1,1,1,0,1}->181,{0,1,1,1,1,0,1}->181,{0,0,1,1,1,1,0,1}->181,{0,0,0,1,1,1,1,0,1}->181,{1,1,1,1,1,0}->186,{0,1,1,1,1,1,0}->186,{0,0,1,1,1,1,1,0}->186,{0,0,0,1,1,1,1,1,0}->186,{1,1,1,1,1,1}->192,{0,1,1,1,1,1,1}->192,{0,0,1,1,1,1,1,1}->192,{0,0,0,1,1,1,1,1,1}->192,{1,0,0,0,0,0,0}->193,{0,1,0,0,0,0,0,0}->193,{0,0,1,0,0,0,0,0,0}->193,{1,0,0,0,0,0,1}->195,{0,1,0,0,0,0,0,1}->195,{0,0,1,0,0,0,0,0,1}->195,{1,0,0,0,0,1,0}->197,{0,1,0,0,0,0,1,0}->197,{0,0,1,0,0,0,0,1,0}->197,{1,0,0,0,0,1,1}->200,{0,1,0,0,0,0,1,1}->200,{0,0,1,0,0,0,0,1,1}->200,{1,0,0,0,1,0,0}->202,{0,1,0,0,0,1,0,0}->202,{0,0,1,0,0,0,1,0,0}->202,{1,0,0,0,1,0,1}->205,{0,1,0,0,0,1,0,1}->205,{0,0,1,0,0,0,1,0,1}->205,{1,0,0,0,1,1,0}->208,{0,1,0,0,0,1,1,0}->208,{0,0,1,0,0,0,1,1,0}->208,{1,0,0,0,1,1,1}->212,{0,1,0,0,0,1,1,1}->212,{0,0,1,0,0,0,1,1,1}->212,{1,0,0,1,0,0,0}->214,{0,1,0,0,1,0,0,0}->214,{0,0,1,0,0,1,0,0,0}->214,{1,0,0,1,0,0,1}->217,{0,1,0,0,1,0,0,1}->217,{0,0,1,0,0,1,0,0,1}->217,{1,0,0,1,0,1,0}->220,{0,1,0,0,1,0,1,0}->220,{0,0,1,0,0,1,0,1,0}->220,{1,0,0,1,0,1,1}->224,{0,1,0,0,1,0,1,1}->224,{0,0,1,0,0,1,0,1,1}->224,{1,0,0,1,1,0,0}->227,{0,1,0,0,1,1,0,0}->227,{0,0,1,0,0,1,1,0,0}->227,{1,0,0,1,1,0,1}->231,{0,1,0,0,1,1,0,1}->231,{0,0,1,0,0,1,1,0,1}->231,{1,0,0,1,1,1,0}->235,{0,1,0,0,1,1,1,0}->235,{0,0,1,0,0,1,1,1,0}->235,{1,0,0,1,1,1,1}->240,{0,1,0,0,1,1,1,1}->240,{0,0,1,0,0,1,1,1,1}->240,{1,0,1,0,0,0,0}->242,{0,1,0,1,0,0,0,0}->242,{0,0,1,0,1,0,0,0,0}->242,{1,0,1,0,0,0,1}->245,{0,1,0,1,0,0,0,1}->245,{0,0,1,0,1,0,0,0,1}->245,{1,0,1,0,0,1,0}->248,{0,1,0,1,0,0,1,0}->248,{0,0,1,0,1,0,0,1,0}->248,{1,0,1,0,0,1,1}->252,{0,1,0,1,0,0,1,1}->252,{0,0,1,0,1,0,0,1,1}->252,{1,0,1,0,1,0,0}->255,{0,1,0,1,0,1,0,0}->255,{0,0,1,0,1,0,1,0,0}->255,{1,0,1,0,1,0,1}->259,{0,1,0,1,0,1,0,1}->259,{0,0,1,0,1,0,1,0,1}->259,{1,0,1,0,1,1,0}->263,{0,1,0,1,0,1,1,0}->263,{0,0,1,0,1,0,1,1,0}->263,{1,0,1,0,1,1,1}->268,{0,1,0,1,0,1,1,1}->268,{0,0,1,0,1,0,1,1,1}->268,{1,0,1,1,0,0,0}->271,{0,1,0,1,1,0,0,0}->271,{0,0,1,0,1,1,0,0,0}->271,{1,0,1,1,0,0,1}->275,{0,1,0,1,1,0,0,1}->275,{0,0,1,0,1,1,0,0,1}->275,{1,0,1,1,0,1,0}->279,{0,1,0,1,1,0,1,0}->279,{0,0,1,0,1,1,0,1,0}->279,{1,0,1,1,0,1,1}->284,{0,1,0,1,1,0,1,1}->284,{0,0,1,0,1,1,0,1,1}->284,{1,0,1,1,1,0,0}->288,{0,1,0,1,1,1,0,0}->288,{0,0,1,0,1,1,1,0,0}->288,{1,0,1,1,1,0,1}->293,{0,1,0,1,1,1,0,1}->293,{0,0,1,0,1,1,1,0,1}->293,{1,0,1,1,1,1,0}->298,{0,1,0,1,1,1,1,0}->298,{0,0,1,0,1,1,1,1,0}->298,{1,0,1,1,1,1,1}->304,{0,1,0,1,1,1,1,1}->304,{0,0,1,0,1,1,1,1,1}->304,{1,1,0,0,0,0,0}->306,{0,1,1,0,0,0,0,0}->306,{0,0,1,1,0,0,0,0,0}->306,{1,1,0,0,0,0,1}->309,{0,1,1,0,0,0,0,1}->309,{0,0,1,1,0,0,0,0,1}->309,{1,1,0,0,0,1,0}->312,{0,1,1,0,0,0,1,0}->312,{0,0,1,1,0,0,0,1,0}->312,{1,1,0,0,0,1,1}->316,{0,1,1,0,0,0,1,1}->316,{0,0,1,1,0,0,0,1,1}->316,{1,1,0,0,1,0,0}->319,{0,1,1,0,0,1,0,0}->319,{0,0,1,1,0,0,1,0,0}->319]; これを全自動スライド bitDP 学習器にぶち込んで係数列を自動生成する. */ ll solve(ll n) { auto s = bitset<40>(n).to_string(); dump(s); // -------------------- 生成器からの出力を貼る -------------------- vvl coef = { {0, 0, -4, 0, 2, 3, -1}, {0, 0, -4, 0, 1, 4, -1}, {0, 0, -4, 0, 0, 5, -1}, {0, 0, -4, 0, 0, 4, 0}, {0, 0, -4, 0, -1, 5, 0}, {0, 0, -4, 0, -1, 4, 1}, {0, 0, -4, 0, -1, 3, 2}, {0, 0, -4, 0, 0, 0, 4} }; // これも貼る. vl dp = { -1, 0, 1, 0, 1, 2, 4 }; // -------------------------------------------------------------- // ここ以降は書き換える必要はない. int B = msb(sz(coef)) - 1; repe(si, s) { vl ndp; ndp.reserve(sz(dp)); int offset = 1; rep(b, B) { int d = si - '0'; int w = 1 << b; ndp.insert(ndp.end(), dp.begin() + (offset + d * w), dp.begin() + (offset + (d + 1) * w)); offset += 2 * w; } int k0 = (si - '0') << B; int k1 = k0 + (1 << B) - 1; repi(k, k0, k1) { ll tmp = 0; rep(t, sz(dp)) tmp += dp[t] * coef[k][t]; ndp.push_back(tmp); } dp = move(ndp); } return dp[0]; } int main() { // input_from_file("input.txt"); // output_to_file("output.txt"); // zikken(); //【方法】 // 愚直を書いて集めた学習データをもとにスライド bitDP のコードを自動生成する. int T; cin >> T; rep(hoge, T) { dump("========================="); ll n; cin >> n; cout << solve(n) << "\n"; } }