// C++11 #include #include #include #include #include #include #include "bits/stdc++.h" #include #include #include #include using namespace std; inline long long GetTSC() { long long lo, hi; asm volatile ("rdtsc": "=a"(lo), "=d"(hi)); return lo + (hi << 32); } inline double GetSeconds() { return GetTSC() / 2.8e9; } struct XorShift { uint64_t x = 88172645463325252ULL; XorShift() {} void setSeed(uint64_t seed) { x = seed; } uint64_t next() { x ^= x << 13; x ^= x >> 7; x ^= x << 17; return x; } int nextInt(int n) { uint64_t upper = 0xFFFFFFFFFFFFFFFFULL / n * n; uint64_t v = next(); while (v >= upper) { v = next(); } return v % n; } double nextDouble() { uint64_t v = next() >> 11; // 53bit return (double)v / (1ULL << 53); } }; const double TO = 9.9; const double eps = 1e-7; const double inf = 1e7; const int N = 10000; const int CLICK = 1; const int FM = 6; const string FS[FM] = {"enhclick", "hand", "lily", "factory", "casino", "grimoire"}; const int FP[FM] = {1, 1, 10, 120, 2000, 25000}; const int FB[FM] = {-1, 150, (int)2e3, (int)3e4, (int)6e5, (int)1e7}; const int FA[FM] = {15, 1500, (int)2e4, (int)3e5, (int)6e6, (int)1e8}; const int BUY = 2; const int SELL = BUY + FM; const int REF = BUY + FM * 2; long bcosts[FM][256]; long acosts[FM][16]; const long amsk[FM] = {7, 7l<<9, 7l<<18, 7l<<27, 7l<<36, 7l<<45}; const long apls[FM] = {1, 1l<<9, 1l<<18, 1l<<27, 1l<<36, 1l<<45}; const int asft[FM] = {0, 9, 18, 27, 36, 45}; const long bmsk[FM] = {0, 63l<<3, 63l<<12, 63l<<21, 63l<<30, 63l<<39}; const long bpls[FM] = {0, 1l<<3, 1l<<12, 1l<<21, 1l<<30, 1l<<39}; const int bsft[FM] = {0, 3, 12, 21, 30, 39}; struct State{ long c; long pro; long pcc; int bi; int cmd; State(){ c = bi = cmd = pcc = 0; pro = 1; } State(long _c, long _pro, long _pcc, int _bi, int _cmd){ c = _c; pro = _pro; pcc = _pcc; bi = _bi; cmd = _cmd; } bool operator<(const State &a) const{ return c != a.c ? c < a.c : pro != a.pro ? pro < a.pro : pcc < a.pcc; } void calc_pro(){ pro = pow(2, pcc & 7); for(int i=1; i> bsft[i] & 63) * pow(2, pcc >> asft[i] & 7); } } vector nextStates(bool bf, bool sf, bool ff, int qi){ vector vs; State s = State(c, pro, pcc, qi, CLICK); if(ff){ s.c += s.pro * 7; }else{ s.c += s.pro; } vs.push_back(s); for(int i=0; i> asft[i] & 7) <= (pcc >> asft[i+1] & 7)) && (pcc >> asft[i] & 7) < 7){ long ac = acosts[i][pcc >> asft[i] & 7]; if(sf) ac -= ac / 10; else if(c - pro >= ac) continue; if(c >= ac){ State sa = State(c-ac, pro, pcc, qi, REF+i); sa.pcc += apls[i]; sa.calc_pro(); if(bf) sa.c += sa.c / 100; if(ff){ sa.c += (sa.pro - pow(2, sa.pcc & 7)) * 7; }else{ sa.c += sa.pro - pow(2, sa.pcc & 7); } vs.push_back(sa); } } if(i==0) continue; if((pcc >> bsft[i] & 63) <= ((pcc >> asft[i] & 7) + 1) * 10 && (pcc >> bsft[i] & 63) < 63){ long bc = bcosts[i][(pcc >> bsft[i] & 63)]; if(sf) bc -= bc / 10; else if(c - pro >= bc) continue; if(c >= bc){ State sb = State(c-bc, pro, pcc, qi, BUY+i); sb.pcc += bpls[i]; sb.calc_pro(); if(bf) sb.c += sb.c / 100; if(ff){ sb.c += (sb.pro - pow(2, sb.pcc & 7)) * 7; }else{ sb.c += sb.pro - pow(2, sb.pcc & 7); } vs.push_back(sb); } } } return vs; } }; ostream& operator<<(ostream& os, const State& s){ os << "S[" << s.c << ", " << log(s.c) / log(10) << ", bi: " << s.bi << ", cmd: " << s.cmd << ", "; os << "P{" << s.pro; for(int i=0; i> bsft[i] & 63) << ", " << (s.pcc >> asft[i] & 7) << ")"; } os << "}]"; } char S[N]; int R[N]; vector Q[N+1]; double starttime, gt; int tt,ctt; XorShift xs; void init(){ int n; scanf("%d%s", &n, S); for(int i=0; i= t; bool bf = S[t] == 'B'; for(const auto &s : Q[t][cqs-1].nextStates(bf,sf,ff,cqs-1)){ nq.push_back(s); } long mp = Q[t][cqs-1].pro; long mc = Q[t][cqs-1].pcc; if(t % 1000 == 999){ cerr << t << ": " << cqs << ", " << Q[t][cqs-1] << endl; } int qc = 1; for(int i=cqs-2; i>=0; i--){ auto qi = Q[t][i]; if(mp < qi.pro || (mp == qi.pro && mc < qi.pcc)){ qc++; mp = qi.pro; mc = qi.pcc; for(const auto &s : qi.nextStates(bf,sf,ff,i)){ nq.push_back(s); } if(qc > 1999) break; } } sf = 0; if(S[t] == 'F'){ ft = t + 20; }else if(S[t] == 'S'){ sf = 1; } } int lqs = Q[N].size(); sort(&Q[N][0], &Q[N][lqs]); int ni = lqs - 1; for(int i=N; i>0; i--){ // if(Q[i][ni].cmd != CLICK) cerr << i << ":: " << Q[i][ni] << endl; R[i-1] = Q[i][ni].cmd; ni = Q[i][ni].bi; } for(int t=0; t=0; i--){ long ac = acosts[i][acount[i]]; long bc = bcosts[i][bcount[i]]; if(sf){ ac -= ac / 10; bc -= bc / 10; } if(ac <= c && tr == REF + i){ c -= ac; acount[i]++; break; } if(i > 0 && bc <= c && tr == BUY + i){ c -= bc; bcount[i]++; break; } } R[t] = tr; long cc = 0; if(tr == CLICK){ cc = bcount[0] * pow(2, acount[0]); } for(int i=1; i= t){ cc *= 7; } // if(t % 1000 == 999) cerr << t << ": " << c << ", cc: " << cc << endl; sf = 0; if(S[t] == 'N'){ }else if(S[t] == 'B'){ c += c / 100 + (c%100 ? 1 : 0); }else if(S[t] == 'F'){ ft = t + 20; }else if(S[t] == 'S'){ sf = 1; } c += cc; } for(int i=0; i= BUY && ri < BUY + FM){ cout << "buy " << FS[ri - BUY] << endl; }else if(ri >= REF && ri < REF + FM){ cout << "reinforce " << FS[ri - REF] << endl; }else if(ri >= SELL && ri < SELL + FM){ cout << "sell " << FS[ri - SELL] << endl; } cin >> s; if(i == 0) cerr << "s: " << s << endl; if(s == "-1") return; if(s[0] == '-'){ cerr << 1 / t << endl; } } } int main() { srand((unsigned) time(NULL)); xs.setSeed(rand() % 65536 || 65537); double mainstart = GetSeconds(); cerr << setprecision(10); init(); cerr << "init_time: " << GetSeconds() - mainstart << endl; solve(); output(); cerr << "main_time: " << GetSeconds() - mainstart << endl; return 0; }