#include using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define pb emplace_back typedef long long ll; typedef pair pint; const int N=10000; string S; ll tot=0; vector mov={"click","buy","sell","reinforce","enhclick"}; vector nam={"hand","lily","factory","casino","grimoire"}; ll bcost[5]={150,2000,30000,600000,10000000},rcost[6]={150,20000,300000,6000000,100000000,15}; ll base[5]={1,10,120,2000,25000}; int satu[5]={0,7,7,7,14}; int numfa[5],numref[6]; int feverend=0,pfac=1; bool disc=false; pint ans[N]; inline void nxphase(int turn){ if(S[turn]=='B') tot+=(tot+99)/100; else if(S[turn]=='F') feverend=turn+20,pfac=7; else if(S[turn]=='S') disc=true; else disc=false; if(feverend==turn) pfac=1; return; } inline ll get_c(){ ll ret=0; rep(i,5){ ret+=(base[i]<=rcost[5]){ ll tcos=rcost[5]; if(disc) tcos=(tcos*9+9)/10; tot-=tcos; rcost[5]*=10;++numref[5]; ans[turn]={4,0}; } else{ ans[turn]={0,0};tot+=(1ll<=bcost[i]){ ll tcos=bcost[i]; if(disc) tcos=(tcos*9+9)/10; tot-=tcos; bcost[i]=(bcost[i]*6+4)/5;++numfa[i]; ans[turn]={1,i}; } else{ ans[turn]={0,0};tot+=(1ll<=rcost[3]){ ll tcos=rcost[3]; if(disc) tcos=(tcos*9+9)/10; tot-=tcos; rcost[3]*=10;++numref[3]; ans[turn]={3,3}; } else if(numref[4]==2&&numref[3]==1&&tot>=rcost[3]){ ll tcos=rcost[3]; if(disc) tcos=(tcos*9+9)/10; tot-=tcos; rcost[3]*=10;++numref[3]; ans[turn]={3,3}; } else if(turn<8500&&cnt<2&&tot>=rcost[4]){ ll tcos=rcost[4]; if(disc) tcos=(tcos*9+9)/10; tot-=tcos; rcost[4]*=10;++numref[4]; ans[turn]={3,4}; ++cnt; cerr<>drop>>S; init(); cerr<>ds; } return 0; }