#include using namespace std; typedef unsigned long long ll; typedef vector vi; typedef vector vl; typedef complex P; typedef pair pii; typedef pair pll; #define REP(i,n) for(ll i=0;i> n; vector digit_comb[MAX_DIGIT+1]; REPR(c5,30)REP(c3,30){ if(c5*3+c3>MAX_DIGIT)continue; digit_comb[c5*3+c3].push_back(make_pair((int)c5*3,(int)c3)); } ll beforecnt = 0; ll cnt = 0; ll iter = 0; while(cnt < n){ beforecnt = cnt; ++iter; vector digits = digit_comb[iter]; if(digits.empty())continue; REP(i,digits.size()){ pii c53 = digits[i]; cnt += memo_comb[c53.first+c53.second-1][c53.second]; } } // iter is result digit count vector digits = digit_comb[iter]; // bit 1 means '5' // bit 0 means '3' vi available; REP(i,digits.size())available.push_back(digits[i].first); // ll now = cnt - beforecnt; ll countdown = n-beforecnt-1; ll now = 0; // FOR(t,(1<<(iter-1)),(1<