#pragma GCC optimize ("O3") // #pragma GCC target ("avx") #include "bits/stdc++.h" // #define NDEBUG using namespace std; using ll = long long int; #define debugos cout #define debug(v) {printf("L%d %s > ",__LINE__,#v);debugos<<(v)< ",__LINE__,#v);for(auto e:(v)){debugos< ",__LINE__,#m);for(int x=0;x<(w);x++){debugos<<(m)[x]<<" ";}debugos<\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){debugos<<(m)[y][x]<<" ";}debugos< f) { if (!assertion) { cerr << "assertion fault:" << endl; f(); abort(); } } template inline ostream& operator <<(ostream &o, const pair p) { o << '(' << p.first << ':' << p.second << ')'; return o; } template inline ostream& _ostream_vecprint(ostream& os, const Vec& a) { os << '['; for (const auto& e : a) os << ' ' << e << ' '; os << ']'; return os; } template inline ostream& operator<<(ostream& o, const vector& v) { return _ostream_vecprint(o, v); } template inline ostream& operator<<(ostream& o, const array& v) { return _ostream_vecprint(o, v); } template inline T& chmax(T& to, const T& val) { return to = max(to, val); } template inline T& chmin(T& to, const T& val) { return to = min(to, val); } void bye(string s, int code = 0) { cout << s << endl; exit(code); } mt19937_64 randdev(8901016); template::value>::type* = nullptr> inline T rand(T l, T h, Random& rand = randdev) { return uniform_int_distribution(l, h)(rand); } template::value>::type* = nullptr> inline T rand(T l, T h, Random& rand = randdev) { return uniform_real_distribution(l, h)(rand); } #if defined(_WIN32) || defined(_WIN64) #define getchar_unlocked _getchar_nolock #define putchar_unlocked _putchar_nolock #elif defined(__GNUC__) #else #define getchar_unlocked getchar #define putchar_unlocked putchar #endif namespace { #define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E) class MaiScanner { public: template void input_integer(T& var) noexcept { var = 0; T sign = 1; int cc = getchar_unlocked(); for (; cc < '0' || '9' < cc; cc = getchar_unlocked()) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked()) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; } inline int c() noexcept { return getchar_unlocked(); } inline MaiScanner& operator>>(int& var) noexcept { input_integer(var); return *this; } inline MaiScanner& operator>>(long long& var) noexcept { input_integer(var); return *this; } inline MaiScanner& operator>>(string& var) { int cc = getchar_unlocked(); for (; !isvisiblechar(cc); cc = getchar_unlocked()); for (; isvisiblechar(cc); cc = getchar_unlocked()) var.push_back(cc); return *this; } template inline void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; class MaiPrinter { public: template void output_integer(T var) noexcept { if (var == 0) { putchar_unlocked('0'); return; } if (var < 0) putchar_unlocked('-'), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putchar_unlocked(stack[--stack_p]); } inline MaiPrinter& operator<<(char c) noexcept { putchar_unlocked(c); return *this; } inline MaiPrinter& operator<<(int var) noexcept { output_integer(var); return *this; } inline MaiPrinter& operator<<(long long var) noexcept { output_integer(var); return *this; } inline MaiPrinter& operator<<(char* str_p) noexcept { while (*str_p) putchar_unlocked(*(str_p++)); return *this; } inline MaiPrinter& operator<<(const string& str) { const char* p = str.c_str(); const char* l = p + str.size(); while (p < l) putchar_unlocked(*p++); return *this; } template void join(IT begin, IT end, char sep = ' ') { for (bool b = 0; begin != end; ++begin, b = 1) b ? *this << sep << *begin : *this << *begin; } }; } MaiScanner scanner; MaiPrinter printer; // enum EMachine { kHand = 0, kLily, kFactory, kCasino, kGrimoire, kClicker }; enum ECommand { kClick = 0, kBuy, kReinforce }; enum EEffect { kNothing = 0, kBonus, kFever, kSale }; inline char* machineToString(EMachine m) { static char* s[] = { "hand", "lily", "factory", "casino", "grimoire" }; return s[(int)m]; } inline EEffect charToEffect(char c) { return c == 'N' ? EEffect::kNothing : c == 'B' ? EEffect::kBonus : c == 'F' ? EEffect::kFever : c == 'S' ? EEffect::kSale : EEffect::kNothing; } // struct Action { ECommand command; EMachine target; Action(ECommand aCommand, EMachine aTarget = EMachine::kHand) :command(aCommand), target(aTarget) { } void print() const { switch (command) { case kClick: printer << "click\n"; break; case kBuy: printer << "buy " << machineToString(target) << '\n'; break; case kReinforce: if (target == EMachine::kClicker) printer << "enhclick" << '\n'; else printer << "reinforce " << machineToString(target) << '\n'; break; default: clog << "invalid command\n"; break; } } }; class State { ll wallet_; array numMachine_; array lvlMachine_; array costBuyMachine_ = { 150, 2000, 30000, 600000, 10000000 }; array costRfMachine_ = { 1500, 20000, 300000, 6000000, 100000000, 15 }; public: State() :wallet_(0) { numMachine_.fill(0); numMachine_[5] = 1; lvlMachine_.fill(0); } // inline ll costBuyMachine(EMachine e) const { return costBuyMachine_[(int)e]; } inline ll costReinforceMachine(EMachine e) const { return costRfMachine_[(int)e]; } inline ll wallet() const { return wallet_; } inline int countOfMachine(EMachine e) const { return numMachine_[(int)e]; } // inline ll efficiency(EMachine e) const { const ll s[] = { 1, 10, 120, 2000, 25000, 1 }; return s[(int)e] * (1ll << lvlMachine_[(int)e])*numMachine_[(int)e]; } inline void buyMachine(EMachine e, bool sale = false) { if (sale) wallet_ -= (costBuyMachine_[(int)e] * 9 + 9) / 10; else wallet_ -= costBuyMachine_[(int)e]; assert(wallet_ >= 0); costBuyMachine_[(int)e] = (costBuyMachine_[(int)e] * 6 + 4) / 5; numMachine_[(int)e] += 1; } inline void reinforceMachine(EMachine e, bool sale = false) { if (sale) wallet_ -= (costRfMachine_[(int)e] * 9 + 9) / 10; else wallet_ -= costRfMachine_[(int)e]; assert(wallet_ >= 0); costRfMachine_[(int)e] = (costRfMachine_[(int)e] * 10); lvlMachine_[(int)e] += 1; } void applyAction(Action act, EEffect eff) { ll fever = eff == EEffect::kFever ? 7 : 1; // action if (act.command == ECommand::kClick) { wallet_ += fever*efficiency(EMachine::kClicker); } else if (act.command == ECommand::kBuy) { buyMachine(act.target, eff == EEffect::kSale); } else if (act.command == ECommand::kReinforce) { reinforceMachine(act.target, eff == EEffect::kSale); } // facility for (int i = 4; i >= 0; --i) { wallet_ += fever*efficiency((EMachine)i); } // bonus if (eff == EEffect::kBonus) { wallet_ += (wallet_ + 99) / 100; } } }; // namespace IN { const int maxTurnCount = 10000; EEffect effects[maxTurnCount]; } // void convertinput(const string& l) { using namespace IN; int fever = 0; int sale = 0; repeat(i, maxTurnCount) { auto e = charToEffect(l[i]); effects[i] = e == EEffect::kBonus ? EEffect::kBonus : EEffect::kNothing; if (fever > 0) { --fever; effects[i] = EEffect::kFever; } if (sale > 0) { --sale; effects[i] = EEffect::kSale; } if (e == EEffect::kFever) { fever = 20; } else if (e == EEffect::kSale) { sale = 1; } } } void generateInput() { using namespace IN; string l; l.reserve(maxTurnCount); int next = rand(0, 200); repeat(i, maxTurnCount) { if (next > 0) { --next; l.push_back('N'); } else { l.push_back("BFS"[rand(0, 2)]); next = rand(100, 200); } } convertinput(l); } void scan() { using namespace IN; int n; scanner >> n; assert(maxTurnCount == n); string l; scanner >> l; convertinput(l); } // namespace Solver { void solve() { State state; repeat(i, IN::maxTurnCount) { Action action(ECommand::kClick); rrepeat(m, 5) { if (state.countOfMachine((EMachine)m) == 0 || state.costBuyMachine((EMachine)m) < state.costReinforceMachine((EMachine)m)) { if (state.costBuyMachine((EMachine)m) <= state.wallet()) { action = Action(ECommand::kBuy, (EMachine)m); break; } } else { if (state.costReinforceMachine((EMachine)m) <= state.wallet()) { action = Action(ECommand::kReinforce, (EMachine)m); break; } } } action.print(); state.applyAction(action, IN::effects[i]); } } } int main() { using namespace IN; scan(); //generateInput(); Solver::solve(); string str; repeat(i, maxTurnCount) { str.clear(); scanner >> str; assert(str == "ok"); } return 0; }