#include #include #include #define llinf 4154118101919364364 unsigned long long seed; unsigned long long xorshift(){ seed=seed^(seed<<13); seed=seed^(seed>>7); seed=seed^(seed<<17); return seed; } long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;} char s[524288]; char move[8][16]={ "click", "buy", "sell", "reinforce", "enhclick", "nothing" }; char namebuild[8][16]={ "#", "hand", "lily", "factory", "casino", "grimoire" }; long long bvaluebuild[8]={ 0, 150, 2000, 30000, 600000, 10000000 }; long long tvaluebuild[8][512]={0}; long long ismove(char str[]){ long long i; for(i=0;i<=5;i++){ if(strcmp(move[i],str)==0){ return i; } } return -1; } long long isbuild(char str[]){ long long i; for(i=1;i<=5;i++){ if(strcmp(namebuild[i],str)==0){ return i; } } return -1; } void calcvbuild(){ long long i,j,w; for(i=1;i<8;i++){ for(j=1;j<512;j++){ tvaluebuild[i][j]=llinf; } tvaluebuild[i][1]=bvaluebuild[i]; for(j=2;j<512;j++){ w=llceil(6*tvaluebuild[i][j-1],5); if(w>1000000000000000000){ break; } tvaluebuild[i][j]=w; } } } long long eval(char cmd[10005][16],char inbuild[10005][16]){ long long i,j,n=10000,r=0,ft=0,k=1,sf=0,id,ks,bp; long long madebuild[8]={ 1, 1, 10, 120, 2000, 25000 }; long long enhbuild[8]={ 15, 1500, 20000, 300000, 6000000, 100000000 }; long long buildown[8]={ 0, 0, 0, 0, 0, 0 }; for(i=0;i=ks){ r-=ks; madebuild[id]*=2; enhbuild[id]*=10; } else{ } } } else if(strcmp(cmd[i],move[4])==0){ ks=enhbuild[0]; if(sf==1){ ks=llceil(9*ks,10); } if(r>=ks){ r-=ks; madebuild[0]*=2; enhbuild[0]*=10; } else{ } } else if(strcmp(cmd[i],move[5])==0){ } else{ } for(j=1;j<=5;j++){ r+=(madebuild[j]*buildown[j]*k); } if(ft>0){ft--;} sf=0; if(s[i]=='B'){ r+=llceil(r,100); } else if(s[i]=='F'){ ft=20; } else if(s[i]=='S'){ sf=1; } } return r; } int main(void){ long stt,nt; calcvbuild(); struct timeval tv; gettimeofday(&tv, NULL); seed=(tv.tv_sec*1000000+tv.tv_usec); stt=seed; long long i,j,n,m,k,a,b,c,h,w,r=0,l,t; char dum[16]; char cmd[10005][16]={0}; char bcmd[10005][16]={0}; char inbuild[10005][16]={0}; char binbuild[10005][16]={0}; scanf("%lld%s",&n,s); while(1){ for(i=0;i<16;i++){ if(i==15){ strcpy(cmd[i],"enhclick"); } else{strcpy(cmd[i],"click");} } for(i=16;i1){a++;} strcpy(cmd[i],move[a]); if(a!=4){ a=xorshift()%5; a++; strcpy(inbuild[i],namebuild[a]); } } else{strcpy(cmd[i],"click");} } w=eval(cmd,inbuild); if(r9000000){break;} } for(i=0;i