Second Half

upd on 22/4/24

#warning add [-std=c++14 -lgdi32 -lwinmm] to compiler option!!!

#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>

#define col(x)SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x)
#define cps(x,y)SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),{y,x})
#define out(a,b,c,d)TextOut(Sc.Hdc,a,b,c,d)
#define stc(a)SetTextColor(Sc.Hdc,a)
#define px(a,b,c)Sc.Plot(a,b,c)
#define gks(a)(GetKeyState((islower(a))?toupper(a):a)&32768)
#define D int
#define I if
#define E else
#define EI else if
#define F for
#define W while
#define RE return
#define CN continue
#define BK break
#define FL double
#define BlockSz 18
using namespace std;
typedef long long LD;

D aa[3000][3000],DsID,upd[3000][3000];
struct CuSO4 {
 HDC Hdc;
 HANDLE Hout;
 FL DeltaX,DeltaY;
 FL Rat;
 CuSO4(bool k){
  I(!k)RE;
  Hdc=GetDC(GetConsoleWindow());Hout=GetStdHandle(STD_OUTPUT_HANDLE);
  DWORD dwMode=0;DeltaX=DeltaY=0.0;Rat=1.0;
  GetConsoleMode(Hout,&dwMode);SetConsoleMode(Hout,dwMode|4);
  F(D i=0;i<100;++i){
   F(D j=0;j<100;++j){
    SetPixel(Hdc,i,j,0);
   }}}
 void Plot(D x,D y,D R,D G,D B){
  D clr=R+(G<<8)+(B<<16);upd[x+300][y+300]=DsID;
  I(aa[x+300][y+300]==clr)RE;
  aa[x+300][y+300]=clr;SetPixel(Hdc,y+30,x+30,clr);
 }
 D Get(D x,D y){
  D tmp=GetPixel(Hdc,y+30,x+30),R=(tmp&((1<<8)-1)),G=((tmp>>8)&((1<<8)-1)),B=(tmp>>16);
  RE(R<<16)+(G<<8)+B;
 }
 void Plot(D x,D y,D clr){
  Plot(x,y,(clr>>16),((clr>>8)&((1<<8)-1)),(clr&((1<<8)-1)));
 }
 D Mix(D ca,D cb,FL rt){
  D Ar=(ca>>16);
  D Ag=((ca>>8)&((1<<8)-1));
  D Ab=(ca&((1<<8)-1));
  D Br=(cb>>16);
  D Bg=((cb>>8)&((1<<8)-1));
  D Bb=(cb&((1<<8)-1));
  D R=D(floor(rt*FL(Ar)+(1.0-rt)*FL(Br)));
  D G=D(floor(rt*FL(Ag)+(1.0-rt)*FL(Bg)));
  D B=D(floor(rt*FL(Ab)+(1.0-rt)*FL(Bb)));
  RE(max(0,min(255,R))<<16)+(max(0,min(255,G))<<8)+max(0,min(255,B));
 }} Sc(1);
struct RGen {
 D _sS,_cS,CurC;
 RGen(){
  CurC=0;_cS=D(time(0));_sS=_cS;srand(_cS);
 }
 RGen(D Seed){
  CurC=0;_cS=Seed;_sS=_cS;srand(_cS);
 }
 void Srand(D Seed){
  CurC=0;_cS=Seed;_sS=_cS;srand(_cS);
 }
 D Rand(){
  ++CurC;
  I(CurC==0x8000){
   CurC=0;
   _cS +=(_sS^0x66CCFF)+1;
   srand(_cS);
  }
  RE rand();
 }
 D Rand(D Mod){
  RE (((Rand()>>1)<<16)|Rand()|((Rand()&1)<<15))%Mod;
 }} Rnd;
struct CT {
 D LenX,LenY,FX,FY,Color;char Name;
 D Bl[50][90];
 CT(){
  LenX=LenY=0;Color=7;
  memset(Bl,0,sizeof(Bl));
 }
 void Init(string str,D clr,char name){
  LenX=LenY=0;Name=name;
  Color=clr;
  D CurY=0;
  F(unsigned D i=0;i<str.size();++i){
   char ch=str[i];
   I(ch=='|'){
    ++LenX;CurY=0;
   }
   EI(ch=='*')Bl[LenX][CurY++]=1;
   EI(ch=='.')Bl[LenX][CurY++]=0;
   EI(ch=='?')Bl[LenX][CurY++]=2;
   LenY=max(LenY,CurY);
  }}} BsT[35],tO[4],Ts[35][4];
vector<CT> SpTp[35];
D SFile=1;
D LenX=40,DisX=21,LenY=10;
D MvsLi=15;
D NTmLi=500,LTmLi=500;
D NxtT=5;
D AEnabled=0;
D GLi=8;
D SALi=20;
D RndFunc=1;
D EnH=1;
D Gravity=1;
D AByTm=0;
D KWall=1;
D RSys=1;
D Sp2S=1;
D Sp180=1;
D SdwT=1;
D InitRot=0;
D AllowSp=2;
D OSp=0;
D B2BTp=1;
D DecMark=1;
D GoalLs=0;
D LCG=1;
D DAS=300;
D ARR=0;
D SDD=10; 
D ARE=-20;
D LCD=-50;
D InitHR=1;
D BsGH=0;
D GTp=1;
D ExG=0;
D StartV=0;
D VUpLs=10;
D VUpTm=0;
D VUpTs=0;
D VUpA=0;
D MaxV=0;
D VTp=1;
D DifFac=100;
D DefaultR=0;
D Zen=1;
D LCSt=1;
D LCLi=-1;
D PartTopOut=0;
D BlindLv=0;
D AByT=0;
D BFRate=100;
D GoalTp=0;
D FixedFac=0;
D TmLiS=0;
D SndEff=1;
D CDrop=1;
D DropDelayToG=15;
D U1=0,U2=0,U3=0,U4=1,U5=0;

D BEL = 0;

ifstream fin;D Cg[100],CgT=0,Opt=0,LimL[100],LimR[100],DsTp[100],DefVal[100],Multiplier[100];FL VMp;
D *Poi[100];string Name[100],CgName[100];D CCnt[100];LD TmLi;
void Read(string _Name,D &x,D _LimL,D _LimR,D _DsTp=0,D _Multiplier=1){
 D r;++Opt;DefVal[Opt]=x;Cg[Opt]=CgT;++CCnt[CgT];
 Poi[Opt]=&x;Name[Opt]=_Name;
 LimL[Opt]=_LimL;LimR[Opt]=_LimR;
 DsTp[Opt]=_DsTp;Multiplier[Opt]=_Multiplier;
 I(fin>>r)x=r;
}
char GetKey(){
 I(gks(VK_SHIFT))RE VK_SHIFT;
 char r=getch();W(kbhit())r=getch();
 RE r;
}
D _stcl[100],Sight;
void DsHint(){
 cps(0,3);col(7<<4);printf("↑");
 col(14);printf(" ");
 col(7<<4);printf("↓");
 col(14);printf(" Toggle Option, ");
 col(7<<4);printf("Z");
 col(14);printf(" ");
 col(7<<4);printf("X");
 col(14);printf(" Toggle Category, ");
 col(7<<4);printf("←");
 col(14);printf(" ");
 col(7<<4);printf("→");
 col(14);printf(" ");
 col(7<<4);printf("L");
 col(14);printf(" ");
 col(7<<4);printf("R");
 col(14);printf(" ");
 col(7<<4);printf("D");
 col(14);printf(" Adjust, ");
 col(7<<4);printf("Space");
 col(14);printf(" ");
 col(7<<4);printf("Enter");
 col(14);printf(" Confirm");
}
void DsKeyHint(){
 cps(0,3);col(7<<4);printf("↑");
 col(14);printf(" ");
 col(7<<4);printf("↓");
 col(14);printf(" Toggle Option, ");
 col(7<<4);printf("Z");
 col(14);printf(" ");
 col(7<<4);printf("X");
 col(14);printf(" Toggle Category, ");
 col(7<<4);printf("G");
 col(14);printf(" Edit Key, ");
 col(7<<4);printf("Space");
 col(14);printf(" ");
 col(7<<4);printf("Enter");
 col(14);printf(" Confirm");
}
FL ScrMul = 1.0;
FL CScrMul(){
 FL r = 1.0;
 I(!InitHR)r+=0.02;
 r+=(5-NxtT)*0.05;
 I(AllowSp==1)r+=0.1;
 I(!AllowSp)r+=0.25;
 I(!SdwT)r+=0.03;
 I(!EnH)r+=0.3;
 I(!RndFunc)r+=0.5;
 I(RndFunc==2)r-=0.5;
 I(RndFunc==3||RndFunc==4)r+=0.4;
 I(RndFunc==5)r+=0.35;
 I(RndFunc==6)r+=0.3;
 I(RndFunc==7)r+=0.25;
 I(RndFunc==8)r+=0.3;
 I((MvsLi>=0)&&(MvsLi<15))r+=0.003*double(15-MvsLi); 
 I((!KWall)||(!RSys)||(RSys==4)||(RSys==5))r+=0.2;
 EI(RSys==2)r-=0.1;
 EI(RSys==3)r+=0.1;
 I(!Sp2S)r+=0.05;
 I(!Sp180)r+=0.05;
 I(!B2BTp)r+=0.1;
 I(OSp)r-=0.02;
 I(PartTopOut)r+=0.02;
 I(LenX==DisX)r+=0.02;
 I((BlindLv==2)||((BlindLv==1)&&(LCD<0)))r+=(SdwT)?0.4:2.5; 
 EI(BlindLv==1)r+=(SdwT)?0.3:2.0;
 I(!LCG)r+=0.4;
 I(LCG==2)r-=0.4;
 I(FixedFac)r+=2.0;
 I(LCSt>1)r+=min(0.05,0.005*double(LCSt-1));
 I((LCLi>=1)&&(LCLi<4))r+=0.01*double(4-LCLi);
 I(!LCLi)r+=3.0;
 I(AEnabled)r+=min(0.1,BFRate*0.0001);
 I(Zen)r*=0.6;
 I(ARE>=0)r*=(0.6+0.4*pow(0.97,(ARE+10)*0.02));
 I(LCD>=0)r*=(0.8+0.2*pow(0.98,(LCD+10)*0.02));
 I((!NTmLi)||(!Gravity))r*=0.2;
 EI(NTmLi<0)r*=3.0;
 E r*=min(3.0,0.2*max(0.2,500.0/0.2/double(NTmLi)));
 I(!LTmLi)r*=0.5;
 EI(LTmLi<0)r*=1.5;
 E r*=min(2.0,0.1*max(0.5,500.0/0.1/double(LTmLi)));
 I(LenY<=10)r*=double(LenY-1)*double(LenY-1)/81.0;
 I((NTmLi)&&(Gravity)&&(DisX<22))r*=min(1.5,1.0+double(22-DisX)*0.03);
 E r*=double(LenY)*0.1;
 I((RndFunc==1)&&(LenY>=((U4)?14:5))&&(!U5))r*=0.05;
 I((Gravity)&&(NTmLi))r*=3.0-2.0*pow(0.9,min(DisX+1,Gravity)-1);
 r*=(0.1*U3*15+U4*50+2.0*U5*200)/(U1*15+U2*7+U3*15+U4*50+U5*200);
 RE r;
}
D K_LEFT = VK_LEFT;
D K_RIGHT = VK_RIGHT;
D K_SOFTDROP = VK_DOWN;
D K_HARDDROP = ' ';
D K_ROT = VK_UP;
D K_CCW = 'z';
D K_CW = 'x';
D K_180 = 'a';
D K_HOLD = 'c';
D K_REFRESH = 'g';
D K_PAUSE = 'q';
D K_HINT = 't';
D K_RETRY = 'r';
D K_CON = 'o';
D K_UNDO = 'u';
D K_UP = VK_UP;
D K_ADDLAYER = 'f';
D K_DELLAYER = 'd';
D K_LOCK = 's';
D K_SKIP = 'w';
D K_DECLV = 'e';
D K_INCLV = 'r';
D K_EDIT = '`';
D K_FILLCOL = 'f';
D K_FILLROW = 'e';
D K_DELCOL = 'd';
D K_SIGHT = 'q';
D K_HOLDPLACE = 'h';
string KName(char ch) {
 I(ch==VK_SHIFT)RE "Shift";
 I(ch==' ')RE "Space";
 I(ch==VK_UP)RE "↑";
 I(ch==VK_DOWN)RE "↓";
 I(ch==VK_LEFT)RE "←";
 I(ch==VK_RIGHT)RE "→";
 I((ch=='\r')||(ch=='\n'))RE "Enter";
 I(ch=='\t')RE "Tab";
 I(ch==VK_CONTROL)RE "Ctrl";
 I(islower(ch))ch=toupper(ch);
 RE string("")+ch;
}
char InputKey(D _){
 F(;;){
  I(_){
   I(gks(VK_SHIFT))RE VK_SHIFT;
   I(gks(VK_CONTROL))RE VK_CONTROL;
  }
  I(gks(VK_UP))RE VK_UP;
  I(gks(VK_DOWN))RE VK_DOWN;
  I(gks(VK_LEFT))RE VK_LEFT;
  I(gks(VK_RIGHT))RE VK_RIGHT;
  I(kbhit()){
   char r=getch();while(kbhit())r=getch();
   RE r;
  }
 }
}
char config_location[100] = "config_0419a.txt";
void SettingsBoard(){
 fin.open(config_location);
 fin.clear();fin.clear();++DisX;
 Read("Save Options at Local",SFile,0,1,2);
 CgName[++CgT]=" GENERAL ";
 Read("Delayed Auto Shift ms",DAS,0,2000,0,50);
 Read("Auto Repeat Rate ms",ARR,-10,500,0,10);
 Read("Goal Lines",GoalLs,0,10000,1);
 Read("Time Limit",TmLiS,0,10000,1,5);
 Read("Soft Drop Delay ms",SDD,-10,500,0,2);
 Read("Appearance Delay ms",ARE,-20,2000,6,20);
 Read("Line Clear Delay ms",LCD,-50,5000,6,50);
 Read("Initial Operations",InitHR,0,1,2);
 Read("Shown Next Pieces",NxtT,0,5,1);
 Read("Shadow Piece",SdwT,0,1,2);
 Read("Hold Function",EnH,0,1,2);
 Read("Piece Generation Function",RndFunc,0,10,11);
 Read("Drop Delay ms",NTmLi,-5,10000,1,5);
 Read("Lock Delay ms",LTmLi,-10,10000,1,10);
 Read("Lock Delay Reset Limit",MvsLi,-1,1000,6);
 Read("Width of Board",LenY,2,80);
 Read("Height of Board",DisX,2,39);
 Read("B2B Detect Type",B2BTp,0,1,13);
 Read("Sound Effect",SndEff,0,1,2);
 CgName[++CgT]=" LEVELING ";
 Read("Start Level",StartV,0,1000);
 Read("Max Level",MaxV,0,1000,1);
 Read("Level Per Lines",VUpLs,0,1000,1);
 Read("Level Per Time",VUpTm,0,100000,1,5);
 Read("Level Per Piece",VUpTs,0,2500,1,1);
 Read("Level Per Attack",VUpA,0,2500,1,1);
 Read("Difficulty Factor ‰",DifFac,0,500,0,5);
 Read("Difficulty Shift Mode",VTp,0,2,7);
 CgName[++CgT]=" ROTATION ";
 Read("Default Rotate",DefaultR,0,1,8);
 Read("Rotate System",RSys,0,6,5);
 Read("Inital Facing",InitRot,0,3,10);
 Read("Enable Kick Wall",KWall,0,1,2);
 Read("Enable 2-Side Rotate",Sp2S,0,1,2);
 Read("Enable 180° Rotate",Sp180,0,1,2);
 Read("Detected Spins",AllowSp,0,2,12);
 Read("Kick Wall For O Piece",OSp,0,1,2);
 CgName[++CgT]=" MISC ";
 Read("Practice Mode",Zen,0,1,2);
 Read("Partial Top Out",PartTopOut,0,1,2);
 Read("Continuous Animation",CDrop,0,1,2);
 Read("Gravity",Gravity,0,80,1);
 Read("Gravity Transfer Threshold",DropDelayToG,0,1000,1,5);
 Read("Hind Field",BlindLv,0,2,9);
 Read("Height With Buffer",LenX,2,40);
 Read("Line Clear Gravity",LCG,0,2,3);
 Read("Fixed Facing",FixedFac,0,1,2);
 Read("Line Clear Threshold",LCSt,1,40);
 Read("Single Line Clear Limit",LCLi,-1,40,6);
 Read("Highlight Cleared Line",DecMark,0,1,2);
 Read("Single Piece Weight",U1,0,180);
 Read("Domino Piece Weight",U2,0,180);
 Read("Tromino Piece Weight",U3,0,90);
 Read("Tetromino Piece Weight",U4,0,25);
 Read("Pentomino Piece Weight",U5,0,10);
 CgName[++CgT]=" SURVIVAL ";
 Read("Dig Mode",GoalTp,0,1,2);
 Read("Base Garbage Height",BsGH,0,80,1);
 Read("Send Garbage By Time",AByTm,0,10000000,1,50);
 Read("Send Garbage By Piece",AByT,0,1000,1);
 Read("Backfire Attack",AEnabled,0,1,2);
 Read("Backfire Rate %",BFRate,10,1000,0,10);
 Read("Single Attack Limit",SALi,0,50,1);
 Read("Garbage Type",GTp,0,7,4);
 Read("Exploding Garbage",ExG,0,1,2);
 Read("Garbage Gap",GLi,0,50,1);
 CgName[++CgT]=" KEYS ";
 Read("Move Left",K_LEFT,0,0,-1);
 Read("Move Right",K_RIGHT,0,0,-1);
 Read("Soft Drop",K_SOFTDROP,0,0,-1);
 Read("Hard Drop",K_HARDDROP,0,0,-2);
 Read("Default Rotate",K_ROT,0,0,-2);
 Read("CCW Rotate",K_CCW,0,0,-2);
 Read("CW Rotate",K_CW,0,0,-2);
 Read("180° Rotate",K_180,0,0,-2);
 Read("Hold",K_HOLD,0,0,-2);
 Read("Refresh",K_REFRESH,0,0,-1);
 Read("Pause",K_PAUSE,0,0,-1);
 Read("Hint",K_HINT,0,0,-1);
 Read("Retry",K_RETRY,0,0,-1);
 Read("Hold For Debug",K_CON,0,0,-2);
 Read("Undo [Hold Debug]",K_UNDO,0,0,-1);
 Read("Move Up [Hold Debug]",K_UP,0,0,-1);
 Read("Add Layer [Hold Debug]",K_ADDLAYER,0,0,-1);
 Read("Remove Layer [Hold Debug]",K_DELLAYER,0,0,-1);
 Read("Force Lock [Hold Debug]",K_LOCK,0,0,-1);
 Read("Skip Piece [Hold Debug]",K_SKIP,0,0,-1);
 Read("Decrease Level [Hold Debug]",K_DECLV,0,0,-1);
 Read("Increase Level [Hold Debug]",K_INCLV,0,0,-1);
 Read("Enter Edit Mode [Hold Debug]",K_EDIT,0,0,-1);
 Read("Fill Column [Edit Mode]",K_FILLCOL,0,0,-1);
 Read("Clear Column [Edit Mode]",K_DELCOL,0,0,-1);
 Read("Fill Row [Edit Mode]",K_FILLROW,0,0,-1);
 Read("Sight [Hold Debug]",K_SIGHT,0,0,-1);
 Read("Place And Move [Edit Mode]",K_HOLDPLACE,0,0,-1);
 fin.clear();fin.close();
 D Sel=1,CurCg=1,BU=1,EditKey=0;
 F(;;){
  D _=0;
  I(BU){
   system("cls");
   I(CurCg==CgT) DsKeyHint();
   E DsHint();
   cps(1,2);
   F(D i=1;i<=CgT;++i){
    col((CurCg==i)?10:7);cout<<CgName[i];
    col(8);I(i<CgT)printf("|");
   }
  }
  D SelI=1;
  F(D i=1;i<=Opt;++i){
   I((Cg[i])&&(Cg[i]!=CurCg))CN;
   cps((++_)+1,35);
   col((Sel==_)?15:7);I(Sel==_)SelI=i;
   I(!DsTp[i])printf("%d   ",max(-1,*Poi[i]));
   EI(DsTp[i]==1){
    I(*Poi[i]<0){
     col((Sel==_)?9:1);printf("MIN      ");
	}
    EI(*Poi[i])printf("%d   ",*Poi[i]);
    E{
     col((Sel==_)?12:4);
     printf("NO      ");
    }}
   EI(DsTp[i]==6){
    I(*Poi[i]>=0)printf("%d   ",*Poi[i]);
    E {
     col((Sel==_)?12:4);
     printf("NO      ");
    }}
   EI((DsTp[i]==2)||(DsTp[i]==9)){
    I(*Poi[i]==1){
     col((Sel==_)?10:2);
     printf("YES      ");
    }
    EI(*Poi[i]==2){
     col((Sel==_)?9:1);
     printf("ALL      ");
    }
    E {
     col((Sel==_)?12:4);
     printf("NO       ");
    }}
   EI(DsTp[i]==3){
    I(*Poi[i]==2){
     col((Sel==_)?9:1);
     printf("CHAIN");
    }
    EI(*Poi[i]==1){
     col((Sel==_)?10:2);
     printf("YES  ");
    }
    E {
     col((Sel==_)?12:4);
     printf("NO   ");
    }}
   EI(DsTp[i]==4){
    I(*Poi[i]==7)printf("SLAB   ");
    EI(*Poi[i]==6)printf("BUBBLE ");
    EI(*Poi[i]==5)printf("REVERSE");
    EI(*Poi[i]==4)printf("COPY   ");
    EI(*Poi[i]==3)printf("BOARD  ");
    EI(*Poi[i]==2)printf("RANDOM ");
    EI(*Poi[i]==1)printf("CHEESE ");
    E printf("EMPTY  ");
   }
   EI(DsTp[i]==5){
    I(*Poi[i]==6)printf("TR-X");
    EI(*Poi[i]==5)printf("rNRS");
    EI(*Poi[i]==4)printf("lNRS");
    EI(*Poi[i]==3)printf("ARS ");
    EI(*Poi[i]==2)printf("ASC ");
    EI(*Poi[i]==1)printf("SRS ");
    E printf("ORS ");
   }
   EI(DsTp[i]==7){
    I(*Poi[i]==2)printf("EXP");
    EI(*Poi[i]==1)printf("DIV");
    E printf("DEC");
   }
   EI(DsTp[i]==8){
    I(*Poi[i]==1)printf("CW ");
    E printf("CCW");
   }
   EI(DsTp[i]==10){
    I(*Poi[i]==1)printf("L");
    EI(*Poi[i]==2)printf("D");
    EI(*Poi[i]==3)printf("R");
    E printf("U");
   }
   EI(DsTp[i]==11){
    I(*Poi[i]==0)printf("RAND");
    EI(*Poi[i]==1)printf("BAG ");
    EI(*Poi[i]==2)printf("FIX ");
    EI(*Poi[i]==3)printf("LNRS");
    EI(*Poi[i]==4)printf("RNRS");
    EI(*Poi[i]==5)printf("TGM1");
    EI(*Poi[i]==6)printf("TGM2");
    EI(*Poi[i]==7)printf("TGM3");
    EI(*Poi[i]==8) printf("CII ");
    EI(*Poi[i]==9) printf("PAIR");
    E printf("DRGT");
   }
   EI(DsTp[i]==12){
    I(*Poi[i]==0)printf("NONE");
    EI(*Poi[i]==1)printf("DEF ");
    E printf("ALL ");
   }
   EI(DsTp[i]==13){
    I(*Poi[i]==0)printf("DEF ");
    E printf("SEP ");
   }
   EI(DsTp[i]<0){
   	I((EditKey)&&(Sel==_))col((Sel==_)?10:2),printf("<Input Here>");
   	E printf("%s           ",KName(*Poi[i]).c_str());
   }
   D co=0;col(co=(Sel==_)?7:8);
   I((!BU)&&(_stcl[i]==co))CN;
   cps(_+1,3); _stcl[i]=co;
   cout<<Name[i];printf("    ");
  }
  cps(22,3);col(14);I(CurCg!=CgT)printf("Score Multipler : %.2f%%          ",CScrMul()*100.0);
  BU=0;char ch;
  I(EditKey)ch=InputKey(DsTp[SelI]==-2);
  E ch=GetKey();
  I(isupper(ch))ch=tolower(ch);
  I(CurCg!=CgT)EditKey=0;
  I(EditKey){
   *Poi[SelI]=ch,EditKey=0;W(kbhit())getch();
  }
  EI(((ch==107)||(ch==109))&&((DsTp[SelI]==2)||(DsTp[SelI]==8)))*Poi[SelI]^=1;
  EI((ch=='\r')||(ch=='\n')||(ch==' '))BK;
  EI(ch==104)Sel=(Sel==1)?CCnt[CurCg]+1:Sel-1;
  EI(ch==112)Sel=(Sel==CCnt[CurCg]+1)?1:Sel+1;
  EI(ch=='z')CurCg=((CurCg==1)?CgT:CurCg-1),Sel=BU=1;
  EI(ch=='x')CurCg=((CurCg==CgT)?1:CurCg+1),Sel=BU=1;
  EI(CurCg==CgT){
   I(ch=='g')EditKey^=1;
  }
  EI(ch==107){
   I(DsTp[SelI]==10)*Poi[SelI]=(*Poi[SelI]+3)&3;
   E *Poi[SelI]=max(*Poi[SelI]-Multiplier[SelI],LimL[SelI]);
  }
  EI(ch==109){
   I(DsTp[SelI]==10)*Poi[SelI]=(*Poi[SelI]+1)&3;
   E *Poi[SelI]=min(*Poi[SelI]+Multiplier[SelI],LimR[SelI]);
  }
  EI(ch=='l')*Poi[SelI]=LimL[SelI];
  EI(ch=='r')*Poi[SelI]=LimR[SelI];
  EI(ch=='d')*Poi[SelI]=DefVal[SelI];
  DisX=min(DisX,LenX);I(U1+U2+U3+U4+U5==0)U4=1;
 }
 I(SFile){
  ofstream fout(config_location);
  F(D i=1;i<=Opt;++i)fout<<*Poi[i]<<" ";
  fout.clear();fout.close();
 }
 VMp=0.001*FL(DifFac);TmLi=TmLiS*1000LL;
 ScrMul=CScrMul();--DisX;system("cls");
}

D WTC,TDy[910];
D H;D HAv;
D STs,SLs,SD,SInp,SFInp,SA,Ren,SF,SFF,Clu,B2B[100];
D FSTs,FSLs,FSD,FSInp,FSFInp,FSA,FSF,FSFF;
D ARe,AQu[1000],CRe,CQu[1000];
D B[50][90];D C[50][90],Gst[50][90],ACol[100];
D BMark[50][90],M[50][90],_m[50][90],SpPoi[50][90],TSpPoi[35][50][90],_spt[50][90];
D TQu[100],QuLen;
LD BegTm,Sr,ASr;
D OnGround,MsRe,Debug;
D ResB,V,Win,TLE;
string MsA="          ";D MsCA;
string MsB="          ";D MsCB;
char Title[500];

CT RT(CT T,D K=1){
 K=(K%4+4)%4;
 W(K--){
  CT NewT;NewT.Color=T.Color;NewT.Name=T.Name;
  NewT.LenX=T.LenY;NewT.LenY=T.LenX;
  F(D i=0;i<T.LenX;++i){
   F(D j=0;j<T.LenY;++j)NewT.Bl[j][T.LenX-i-1]=T.Bl[i][j];
  }
  T=NewT;
 }
 RE T;
}
CT FrameDrop(CT T){
 D DropDis=0;
 F(D i=0;i<T.LenX;++i){
  D f=0;
  F(D j=0;j<T.LenY;++j){
   I(T.Bl[i][j]){
    f=1;BK;
   }}
  I(f)BK;
  E ++DropDis;
 }
 F(D i=DropDis;i<T.LenX;++i){
  F(D j=0;j<T.LenY;++j)T.Bl[i-DropDis][j]=T.Bl[i][j];
 }
 F(D i=T.LenX-DropDis;i<T.LenX;++i){
  F(D j=0;j<T.LenY;++j)T.Bl[i][j]=0;
 }
 RE T;
}
D TID,TC=7;
D CheckT(D i,D j){
 I(((i<0)||(i>=LenX))||((j<0)||(j>=LenY)))RE 1;
 I(TID==TC)RE 0;
 RE((B[i][j]!=0)&&(!C[i][j]));
}
D ShiftColor(D clr){
 I(clr<0)RE 0xFDD000;
 clr &= 1023;
 I(!clr)RE 0;
 I(!RSys){
  I(clr==11)RE 0xFF0000;
  I(clr==14)RE 0x0000FF;
  I(clr==12)RE 0x00FFFF;
  I(clr==10)RE 0x00FF00;
  I(clr==1)RE 0xDDDDDD;
  I(clr==6)RE 0xFF00FF;
  I(clr==13)RE 0xA85400;
 }
 I(RSys==6){
  I(clr==11)RE 0xFFA500;
  I(clr==6)RE 0xFFE211;
  I(clr==14)RE 0x00FF00;
  I(clr==10)RE 0x66CCFF;
 }
 I(RSys==5){
  I((clr==11)||(clr==13)||(clr==14))RE 0xDDDDDD;
  I((clr==10)||(clr==1))RE 0xEE0000;
  I((clr==6)||(clr==12))RE 0x808040;
 }
 I(RSys==4){
  I(clr==11)RE 0xBBBBBB;
  I(clr==1)RE 0xAAAAAA;
  I(clr==6)RE 0x777777;
  I(clr==14)RE 0xDDDDDD;
  I(clr==10)RE 0x888888;
  I(clr==13)RE 0xCCCCCC;
  I(clr==12)RE 0x999999;
 }
 I(RSys==3){
  I(clr==11)RE 0xEE0000;
  I(clr==10)RE 0xEE82EE;
  I(clr==13)RE 0x00FFCC;
  I(clr==12)RE 0x00FF00;
 }
 I(clr==11)clr=0x66CCFF;
 EI(clr==1)clr=0x0080FF;
 EI(clr==6)clr=0xFFA500;
 EI(clr==14)clr=0xFFE211;
 EI(clr==10)clr=0x33EE00;
 EI(clr==13)clr=0xEE82EE;
 EI(clr==12)clr=0xEE0000;
 EI(clr==15)clr=0xFFFFFF;
 EI(clr==3)clr=0x39C5BB;
 EI(clr==2)clr=0x006666;
 EI(clr==16)clr=0xFAAFBE;
 EI(clr==17)clr=0x00FFCC;
 EI(clr==18)clr=0x99FFFF;
 EI(clr==19)clr=0x66FFCC;
 EI(clr==20)clr=0xDF3782;
 EI(clr==21)clr=0xB17D43;
 EI(clr==22)clr=0x9E00FF;
 EI(clr==23)clr=0x5F630E;
 EI(clr==24)clr=0x9999FF;
 EI(clr==25)clr=0x00FFFF;
 EI(clr==26)clr=0x00CCCC;
 EI(clr==27)clr=0x00AA00;
 EI(clr==28)clr=0xAA0000;
 EI(clr==29)clr=0xFF5000;
 EI(clr==30)clr=0x0000FF;
 EI(clr==31)clr=0xE2FF00;
 EI(clr==32)clr=0xA4FF00;
 EI(clr==33)clr=0x66FF66;
 EI(clr==34)clr=0xFF6666;
 EI(clr==35)clr=0xFFFF00;
 EI(clr==36)clr=0xFDD000;
 E clr=0xAAAAAA;
 RE clr;
}
D ComboColor(D x){
 --x;I(x<=5)RE Sc.Mix(0x0080FF,0x39C5BB,x*0.2);
 x-=5;I(x<=5)RE Sc.Mix(0x9999FF,0x0080FF,x*0.2);
 x-=5;I(x<=5)RE Sc.Mix(0xEE82EE,0x9999FF,x*0.2);
 x-=5;RE Sc.Mix(0xEE0000,0xEE82EE,x*0.2);
}
D B2BColor(D x){
 I(x<0)RE 0x888888;
 I(x<=50)RE Sc.Mix(0xFFA500,0xFFE211,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0xEE0000,0xFFA500,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0xEE82EE,0xEE0000,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0x9999FF,0xEE82EE,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0x0080FF,0x9999FF,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0x66CCFF,0x0080FF,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0x39C5BB,0x66CCFF,x*0.02);
 x-=50;I(x<=50)RE Sc.Mix(0x00FFCC,0x39C5BB,x*0.02);
 x-=50;RE Sc.Mix(0xFFFFFF,0x00FFCC,x*0.02);
}
D ReverseColor(D tmp){
 D R=(tmp&((1<<8)-1));
 D G=((tmp>>8)&((1<<8)-1));
 D B=(tmp>>16);
 RE(R<<16)+(G<<8)+B;
}
struct Particle {
	double x, y, r, dr, dx, dy, ax, ay; int clr;
};
vector<Particle> PQu, NPQu;
char LKey='!';bool ARep=0,FullSp=0;
string PreA="          ",PreB=PreA;
char B2BT[100],ComboT[100];
char SrT[100],VT[100],VMpT[100],CluT[100],RecordT[100],TmT[100],TmDotT[100],TT[100],InpSpeedT[100],TSpeedT[100],LT[100],LSpeedT[100],AT[100],ASpeedT[100];
bool BU=1;FL BonusMp;LD FinalSr;
D lren=0,lb2b=0,hclr=0,_si,_wl,_clu,_tle;
LD _sc,MaxSr,_msc,_lv;
D _bd[50][90],_at[50][90],_dt[50][90],_ak[50][90],_de[50][90],_rs[50][90],HM[50][90],Hint=0,_hint,_hm[50][90];
LD ldt=0;
LD GoalTm;D _gt,_ntl,_ntlp,_gr;
D Auto=0;
string AFile[3], RFile[3];
D TmBel() {
 LD tm=chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count()%100;
 RE int(tm/25LL);
}
void Patk() {
 BEL=max(BEL,0);BEL=min(BEL,2);
 I(!BEL)RE;
 D lst=-1,la=0;
 F(;;){
  D Bel=TmBel();
  I(Bel==BEL-1){
   FILE* in = fopen(RFile[BEL].c_str(),"r");
   I(in){
    D x;
    W(fscanf(in,"%d",&x)>0){
     I(x!=lst)lst=x,x=la=Rnd.Rand(LenY);
     E x=la;
     I(ARe<1000)AQu[++ARe]=x;
	}
	fclose(in);
   }
   FILE* out = fopen(RFile[BEL].c_str(),"w");
   fclose(out);
  }
  I(CRe&&Bel==BEL+1){
   FILE* out = fopen(AFile[BEL].c_str(),"a+");
   W(CRe){
   	fprintf(out," %d",CQu[CRe-1]);--CRe;
   }
   fclose(out);
  }
  BK;
 }
}
void DsTm(){
 Patk();
 LD CurTm=clock()-BegTm;
 I((TmLi)&&(CurTm>TmLi)&&(!Win)){
  Win=TLE=1;GoalTm=CurTm;FinalSr=Sr;
  FSTs=STs;FSLs=SLs;FSD=SD;FSInp=SInp;FSFInp=SFInp;FSA=SA;FSF=SF;FSFF=SFF;
  D sz=BlockSz;
  F(D i=0;i<=DisX;++i){
      F(D j=0;j<LenY;++j){
       D lx=(DisX-i+5)*sz-80,ly=j*sz+200;
       F(D d=0;d<5;++d)PQu.push_back((Particle){lx+Rnd.Rand(sz),ly+Rnd.Rand(sz),Rnd.Rand(15)*0.1+0.2,0.01,0.5,0,0,0,(Rnd.Rand(2))?0xEE0000:0x9999FF});
	  }
  }
 }
 LD cur=clock();I(cur-ldt<5)RE;
 ldt=cur;
 I((!(gks(K_LEFT)))&&(!(gks(K_RIGHT)))&&(!(gks(K_SOFTDROP))))LKey='!';
 FL Sec=FL((GoalTm)?GoalTm:(((!TLE)&&(TmLi))?TmLi-cur+BegTm:cur-BegTm))*0.001+0.001;
 D SecI=D(floor(Sec));
 I((BU)||(SecI!=_si)||(_gt!=(!GoalTm))||(TLE!=_tle)){
  _si=SecI;_gt=!GoalTm;_tle=TLE;
  stc(0);out(38,235,TmT,strlen(TmT));sprintf(TmT,"%03d : %02d",SecI/60,SecI%60,D(floor((Sec-FL(SecI))*100.0)));
  stc((TLE)?0x0000EE:((GoalTm)?0xCCFF00:0xFFFF99));out(38,235,TmT,strlen(TmT));
 }
 stc(0);out(90,235,TmDotT,strlen(TmDotT));sprintf(TmDotT,".%02d",D(floor((Sec-FL(SecI))*100.0)));stc((TLE)?0x0000EE:((GoalTm)?0xCCFF00:0xFFFF99));out(90,235,TmDotT,strlen(TmDotT));
 Sec=((GoalTm)?GoalTm:cur-BegTm)*0.001+0.001;
 stc(0);out(90,295,TSpeedT,strlen(TSpeedT));sprintf(TSpeedT,"%.2f /s",FL((Win)?FSTs:STs)/Sec);stc(0xFFCC66);out(90,295,TSpeedT,strlen(TSpeedT));
 stc(0);out(90,355,LSpeedT,strlen(LSpeedT));sprintf(LSpeedT,"%.2f /m",FL((Win)?FSLs:SLs)*60.0/Sec);stc(0xFFCC66);out(90,355,LSpeedT,strlen(LSpeedT));
 stc(0);out(90,415,ASpeedT,strlen(ASpeedT));sprintf(ASpeedT,"%.2f /m",FL((Win)?FSA:SA)*60.0/Sec);stc(0xFFCC66);out(90,415,ASpeedT,strlen(ASpeedT));
}
char InitH='!',InitR='!';LD LGTm,AreStart;
vector<pair<D,D> > DelPx;
void CheckKey(D InAre){
 LD nw = clock();
 I((!(gks(K_LEFT)))&&(!(gks(K_RIGHT)))&&(!(gks(K_SOFTDROP))))LKey='!';
 EI((InAre)&&(InitHR)&&(gks(K_LEFT))){
  LKey=K_LEFT;I(LGTm<AreStart)LGTm=nw;
  I(nw-LGTm>=DAS)ARep=1;
 }
 EI((InAre)&&(InitHR)&&(gks(K_RIGHT))){
  LKey=K_RIGHT;I(LGTm<AreStart)LGTm=nw;
  I(nw-LGTm>=DAS)ARep=1;
 }
 EI((InAre)&&(InitHR)&&(gks(K_SOFTDROP))){
  LKey=K_SOFTDROP;I(LGTm<AreStart)LGTm=nw;
  I(nw-LGTm>=DAS)ARep=1;
 }
 I((InAre)&&(InitHR)&&(InAre)){
  I(gks(K_ROT))InitR=K_ROT;
  I(gks(K_CCW))InitR=K_CCW;
  I(gks(K_CW))InitR=K_CW;
  I(gks(K_180))InitR=K_180;
  I((gks(VK_SHIFT))||(gks(K_HOLD)))InitH=K_HOLD;
 }
}
D cl,OverCol[100],_oc[100],_cls[100],cls[100],_inp,ThisA,_ta,_ms,_f,_ff,_dbg;char ChainT[100],InpT[100],OcT[100][5],TAT[100],MST[8],FT[100],FPerT[100];
bool LqSp,_lqs,_are,_wn;D MvsLeft=MvsLi,_mvl,_dclr[100],SPTID=0,_btle;
D PixHold[3000][3000],CEff[100][100],NCEff[100][100];pair<char,char> PixBel[3000][3000];
FL HoriDel,VerDel,LDRate;vector<pair<D,D> >CPx,NCPx;
D pp=0,RealDRate,Chain=0,_chain,_mvlf=-1,_mb2b,_b2bp;char MvLiT[100];
void Ds(D InAre=0){
 //I(Auto&&MsB!="GAME OVER "&&((++pp)%10))RE;
 ++DsID;D _BU=BU;I(CDrop)BU=1;
 string CMsB=MsB;W((CMsB.size())&&(CMsB[0]==K_HARDDROP))CMsB=CMsB.substr(1,CMsB.size()-1);
 D ms=((MsA!="          ")&&(!FullSp));
 I(MsB=="GAME OVER ")sprintf(Title,"Σ(°△°|||)GAME OVER ! | %d Line%s Cleared,%06d",SLs,(SLs>1)?"s":"",Sr);
 EI(Win)sprintf(Title,"Challenge Completed! | %d Line%s Cleared,%06d",FSLs,(FSLs>1)?"s":"",FinalSr);
 EI(MsA=="          "){
  I(MsB=="          ")sprintf(Title,"Running... | %d Line%s Cleared,%06lld",SLs,(SLs>1)?"s":" ",Sr);
  EI(MsB=="ALL CLEAR ")sprintf(Title,"ALL CLEAR!!| %d Line%s Cleared,%06lld",SLs,(SLs>1)?"s":" ",Sr);
  E sprintf(Title,"%s! | %d Line%s Cleared,%06lld",CMsB.c_str(),SLs,(SLs>1)?"s":" ",Sr);
 }
 E {
  string ss=MsA.substr(4,6);
  I(MsB=="          ")sprintf(Title,"%s%s | %d Line%s Cleared,%06lld",(ms)?"Mini ":"",ss.c_str(),SLs,(SLs>1)?"s":" ",Sr);
  EI(MsB=="ALL CLEAR ")sprintf(Title,"%s%s★ALL CLEAR!!| %d Line%s Cleared,%06lld",(ms)?"Mini ":"",ss.c_str(),SLs,(SLs>1)?"s":" ",Sr);
  E sprintf(Title,"%s%s★%s! | %d Line%s Cleared,%06lld",(ms)?"Mini ":"",ss.c_str(),CMsB.c_str(),SLs,(SLs>1)?"s":" ",Sr);
 }
 //SetConsoleTitle(Title);
 D sz=BlockSz,nwhclr=(EnH)?((HAv)?0xFFFFFF:0x888888):0;
 I((nwhclr!=hclr)||(BU)){
  hclr=nwhclr;stc(hclr);out(155,30,"H O L D",7);
 }
 I((NxtT)&&(BU)){
  stc(0xFFFFFF);out((LenY-1)*sz+sz-1+280,30,"N E X T",7);
 }
 I((ms!=_ms)||(LqSp!=_lqs)||(BU)){
  stc(0);out(70,120,MST,strlen(MST));_ms=ms;_lqs=LqSp;
  I(_lqs)sprintf(MST,"Liquid");
  EI(ms)sprintf(MST,"Mini");
  E sprintf(MST,"");
  stc(Sc.Mix(0xAAAAAA,0,double(MsRe-100)/150.0));out(70,120,MST,strlen(MST));
 }
 I((_chain!=Chain)||(BU)){
  stc(0);out(80,105,ChainT,strlen(ChainT));_chain=Chain;
  I(Chain<=1)sprintf(ChainT,"");
  E sprintf(ChainT,"%d Chain",Chain);
  stc(Sc.Mix(0xD0FD,0,double(MsRe-100)/150.0));out(80,105,ChainT,strlen(ChainT));
 }
 I((PreA!=MsA)||(BU)){
  stc(0);out(70,135,PreA.c_str(),10);D clr=ShiftColor(MsCA);
  I(CDrop)clr=Sc.Mix(clr,0,double(MsRe-100)/150.0);
  stc(ReverseColor(clr));PreA=MsA;out(70,135,MsA.c_str(),10);
 }
 I((PreB!=MsB)||(BU)){
  stc(0);out(60,150,PreB.c_str(),10);D clr=ShiftColor(MsCB);
  I(CDrop)clr=Sc.Mix(clr,0,double(MsRe)/250.0);
  stc(ReverseColor(clr));PreB=MsB;out(60,150,MsB.c_str(),10);
 }
 I((lren!=max(0,Ren-1))||(BU)){
  lren=max(0,Ren-1);stc(0);out(70,165,ComboT,strlen(ComboT));
  D clr=Sc.Mix(ComboColor(Ren-1),0,MsRe/250.0);
  I(Ren<2)sprintf(ComboT,"");
  E sprintf(ComboT,"%d  Combo",Ren-1);
  stc(ReverseColor(clr));out(70,165,ComboT,strlen(ComboT));
 }
 I((_ta!=ThisA)||(BU)){
  _ta=ThisA;stc(0);out(70,195,TAT,strlen(TAT));
  D clr=Sc.Mix(B2BColor(_ta*15),0,MsRe/250.0);
  I(_ta)sprintf(TAT,"%d  ATK",_ta);
  E sprintf(TAT,"");
  stc(clr);out(70,195,TAT,strlen(TAT));
 }
 D MB2B=0, B2Bp=TC;
 F(D i=TC;i>=0;--i){
  I(B2B[i]>MB2B)MB2B=B2B[i],B2Bp=i;
 }
 I(((MB2B!=_mb2b)||(B2Bp!=_b2bp))||(BU)){ // B2B here!!!!!!
  stc(0);out(50,180,B2BT,strlen(B2BT));
  D clr=ShiftColor(BsT[B2Bp].Color);
  //I(!B2BTp)clr=0xFDD000;
  I((MB2B<2)||((MB2B<19)&&(B2BTp)))clr=0x888888;
  I(!MB2B)clr=0;
  I(!B2BTp) sprintf(B2BT,"B2B  x%d",MB2B-1);
  EI(B2Bp==TC)sprintf(B2BT,"  B2B %3d%%",MB2B);
  E sprintf(B2BT,"%c-B2B %3d%%",BsT[B2Bp].Name,MB2B);
  stc(ReverseColor(clr));out(50,180,B2BT,strlen(B2BT));
  _mb2b=MB2B;_b2bp=B2Bp;
 }
 FL Sec=FL(clock()-BegTm)*0.001+0.001;stc(0xFFFFFF);
 I(BU)out(55,220,"Time",4);
 I(BU)out(90,265,"Pieces",6);
 I(BU)out(90,325,"Lines",5);
 I(BU)out(10,-30+325,"Inputs",6);
 I(BU)out(90,385,"Attack",6);
 I(BU)out(10,-30+385,"Finesse",7);
 stc(0);out(90,280,TT,strlen(TT));sprintf(TT,"%d",(Win?FSTs:STs));
 stc(0x00FF00);out(90,280,TT,strlen(TT));
 stc(0);out(90,340,LT,strlen(LT));
 I((GoalLs)&&(GoalTp))sprintf(LT,"%d /%d +%d",(Win?FSD:SD),GoalLs,(Win?FSLs:SLs)-(Win?FSD:SD));
 EI(GoalLs){
  I(Win?FSD:SD)sprintf(LT,"%d +%d /%d",(Win?FSLs:SLs)-(Win?FSD:SD),(Win?FSD:SD),GoalLs);
  E sprintf(LT,"%d /%d",(Win?FSLs:SLs),GoalLs);
 }
 E{
  I(Win?FSD:SD)sprintf(LT,"%d +%d",(Win?FSLs:SLs)-(Win?FSD:SD),(Win?FSD:SD));
  E sprintf(LT,"%d",(Win?FSLs:SLs));
 }
 stc(((GoalLs)&&(((GoalTp)?SD:SLs)>=GoalLs))?0xCCFF00:0x00FF00);out(90,340,LT,strlen(LT));stc(0);out(90,400,AT,strlen(AT));
 sprintf(AT,"%d",(Win?FSA:SA));stc(0x00FF00);out(90,400,AT,strlen(AT));
 I((_inp!=SInp)||(_wn!=Win)||(BU)){
  stc(0);out(10,-30+340,InpT,strlen(InpT));sprintf(InpT,"%d",(Win)?FSInp:SInp);
  stc(0x00FF00);out(10,-30+340,InpT,strlen(InpT));
  stc(0);out(10,-30+355,InpSpeedT,strlen(InpSpeedT));sprintf(InpSpeedT,"%.2f /p",FL((Win)?FSInp:SInp)/FL((Win?FSTs:STs)+1));stc(0xFFCC66);out(10,-30+355,InpSpeedT,strlen(InpSpeedT));
 }
 I((_f!=SF)||(_ff!=SFF)||(_wn!=Win)||(BU)){
  stc(0);out(10,-30+400,FT,strlen(FT));
  I((Win)?FSFF:SFF)sprintf(FT,"%d +%d",(Win)?FSF:SF,(Win)?FSFF:SFF);
  E sprintf(FT,"%d",(Win)?FSF:SF);
  stc(0x00FF00);out(10,-30+400,FT,strlen(FT));
  stc(0);out(10,-30+415,FPerT,strlen(FPerT));sprintf(FPerT,"%.2f%%",100.0*FL((Win)?FSF:SF)/FL(max(1,(Win?FSTs:STs))));
  stc(0xFFCC66);out(10,-30+415,FPerT,strlen(FPerT));
 }
 DsTm();
 D sx=5*sz-80,ex=(DisX+5)*sz+sz-1-80;
 D sy=200,ey=(LenY-1)*sz+sz-1+200;
 D ATKp=ex-sz*min(DisX,ARe)-10;I(!ARe)ATKp+=20;
 sx-=10;ex+=10;sy-=10;ey+=10;
 I((BU)||(_lv!=V)){
  stc(0);out(ey+50,385,VT,strlen(VT));out(ey+50,400,VMpT,strlen(VMpT));
  I(MaxV)sprintf(VT,"Lv. %d /%d",V,MaxV);
  E sprintf(VT,"Lv. %d",V);
  sprintf(VMpT,"x %.3f",BonusMp);
  stc(((MaxV)&&(V>=MaxV))?0x0000EE:0xEE82EE);
  out(ey+50,385,VT,strlen(VT));
  stc(0x00FFFF);
  out(ey+50,400,VMpT,strlen(VMpT));
 }
 I((MvsLi)&&((BU)||(_mvlf!=MvsLeft))){
  _mvlf=MvsLeft;stc(0);
  out(((sy+ey)>>1)-30,ex+38,MvLiT,strlen(MvLiT));
  stc(ReverseColor(Sc.Mix(0x00FFCC,0x39C5BB,(MvsLi<=1000&&MvsLi>0)?(double(MvsLeft)/double(MvsLi)):bool(MvsLi))));sprintf(MvLiT,"%d",min(99,max(0,MvsLeft)));
  out(((sy+ey)>>1)-30,ex+38,MvLiT,strlen(MvLiT));
 }
 I((BU)||(_sc!=Sr)||(_dbg!=Debug)||(_wn!=Win)||(_btle!=TLE)){
  _sc=Sr;stc(0);out((sy+ey)>>1,ex+30,SrT,strlen(SrT));_dbg=Debug;_btle=TLE;
  I(Debug)sprintf(SrT,"!@#$%%^&*");
  E sprintf(SrT,"%08lld",(Win)?FinalSr:Sr);
  stc((Debug)?0xFFFF99:((TLE)?0x0000EE:((Win)?0x00FF00:0x00FFFF)));out((sy+ey)>>1,ex+30,SrT,strlen(SrT));
 }
 I(Zen)MaxSr=ASr+Sr;
 E MaxSr=max(MaxSr,(Win)?FinalSr:Sr);
 I((BU)||(_msc!=MaxSr)){
  _msc=MaxSr;stc(0);out((sy+ey)>>1,ex+45,RecordT,strlen(RecordT));sprintf(RecordT,"%08lld",MaxSr);stc(0xFF9999);out((sy+ey)>>1,ex+45,RecordT,strlen(RecordT));
 }
 D _ex=ex;
 D ssz=15,tdel=ey+ssz*5+65;
 I(BU){
  #define kout(b,c)out(tdel,b,KName(c).c_str(),KName(c).size())
  #define kout2(b,c1,c2)out(tdel,b,(KName(c1)+KName(c2)).c_str(),KName(c1).size()+KName(c2).size())
  stc(0x666600);kout(60,K_LEFT);kout(75,K_RIGHT);I(!FixedFac)kout2(90,(DefaultR?K_CW:K_CCW),K_ROT);
  I((Sp2S)&&(!FixedFac))kout(105,(DefaultR?K_CCW:K_CW));
  I((Sp180)&&(!FixedFac))kout(120,K_180);
  kout(135,K_SOFTDROP);kout(150,K_HARDDROP);
  I(EnH)kout(165,K_HOLD);
  kout(180,K_PAUSE);kout(195,K_RETRY);stc(0x666666);out(tdel+65,60,"Move Left",9);out(tdel+65,75,"Move Right",10);
  I(!FixedFac)out(tdel+65,90,(DefaultR?"CW Rotate":"CCW Rotate"),(DefaultR)?9:10);
  I((Sp2S)&&(!FixedFac))out(tdel+65,105,(DefaultR?"CCW Rotate":"CW Rotate"),(DefaultR)?10:9);
  I((Sp180)&&(!FixedFac))out(tdel+65,120,"180° Rotate",12);
  out(tdel+65,135,"Soft Drop",9);out(tdel+65,150,"Hard Drop",9);
  I(EnH)out(tdel+65,165,"Hold",4);
  out(tdel+65,180,"Pause",5);out(tdel+65,195,"Retry",5);
 }
 stc(0x666600);kout(210,K_REFRESH);
 stc(0x666666);out(tdel+65,210,"Refresh",7);
 ex=_ex;bool TopSeal=(DisX+1==LenX);
 F(D i=sx;i<=ex;++i){
  F(D j=sy;j<=ey;++j){
   I((min(ex-i,min(j-sy,ey-j))<10)||((TopSeal)&&(i-sx<10))){
    D clr=Sc.Mix(0xCCCCCC,0x888888,FL(min(min(j-sy,ey-j),min(ex-i,((TopSeal)?i-sx:99))))*0.1);
    I(i>ATKp)clr=Sc.Mix(Sc.Mix(0xFF6666,0xFF3333,FL(min(min(j-sy,ey-j),min(ex-i,((TopSeal)?i-sx:99))))*0.1),clr,min(10,i-ATKp)*0.1);
    I((i-sx<50)&&(!TopSeal))clr=Sc.Mix(clr,0,FL(i-sx)*0.02);
    px(i,j,clr);
   }}}
 D _sx=sx,_sy=sy;_ex=ex;
 sx+=10;sy=ey+30;
 F(D d=0;d<NxtT;++d){
  F(D i=1;i<5;++i){
   F(D j=0;j<5;++j){
    D lx=sx+i*ssz,ly=sy+j*ssz;
    D rx=lx+ssz-1,ry=ly+ssz-1;
    F(D ii=lx;ii<=rx;++ii){
     F(D jj=ly;jj<=ry;++jj){
      I((ii==lx)||(jj==ly)||(ii==rx)||(jj==ry))CN;
      I(!BsT[TQu[d]].Bl[4-i][j]){
       px(ii,jj,0);CN;
      }
      D clr=ShiftColor(BsT[TQu[d]].Color);
      D li=min(ii-lx,jj-ly),ri=min(rx-ii,ry-jj);
      I(li<3)clr=Sc.Mix(clr,0xFFFFFF,0.25*FL(li+1));
      I(ri<3)clr=Sc.Mix(clr,0,0.25*FL(ri));
      px(ii,jj,clr);
     }}}}
  sx += 4*ssz;
 }
 sx=_sx+10;sy=_sy-ssz*4;
 F(D i=1;i<5;++i){
  F(D j=0;j<((U5)?5:4);++j){
   I(!EnH)CN;
   D lx=sx+i*ssz-5,ly=sy+((U5)?j-1:j)*ssz-5;
   D rx=lx+ssz-1,ry=ly+ssz-1;
   F(D ii=lx;ii<=rx;++ii){
    F(D jj=ly;jj<=ry;++jj){
     I((ii==lx)||(jj==ly)||(ii==rx)||(jj==ry))CN;
     I((H==-1)||(!BsT[H].Bl[4-i][j])){
      px(ii,jj,0);CN;
     }
     D clr=ShiftColor((HAv)?BsT[H].Color:8);
     D li=min(ii-lx,jj-ly),ri=min(rx-ii,ry-jj);
     I(li<3)clr=Sc.Mix(clr,0xFFFFFF,0.25*FL(li+1));
     I(ri<3)clr=Sc.Mix(clr,0,0.25*FL(ri));
     px(ii,jj,clr);
    }}}}
 ssz+=3;
 D base=_sy-ssz,beg=_sx+ssz*6,end=max(_ex,beg+10);
 D pp=0;
 I((GoalLs)&&(GoalTp))pp=D(floor(FL(SD)/FL(GoalLs)*FL(end-beg+1)));
 EI(GoalLs)pp=D(floor(FL(SLs)/FL(GoalLs)*FL(end-beg+1)));
 E {
  D cap=10;W(cap<=SLs)cap<<=1;
  pp=D(floor(FL(SLs)/FL(cap)*FL(end-beg+1)));
 }
 FL lpm=FL(SLs*60)/Sec,apm=FL(SA*60)/Sec;
 F(D j=base-2;j<base+12;++j){
  px(beg-1,j,0x888888);px(end+1,j,0x888888);
 }
 F(D j=base;j<base+10;++j){
  px(beg-2,j,0xCCCCCC);px(end+2,j,0xCCCCCC);
 }
 F(D i=beg;i<=end;++i){
  F(D j=base-6;j<base+10;++j){
   I(j==base-4)CN;
   D bel=(end-i)/10;
   I((j<base)&&(j>=base-4)){
    I(!(SLs>>min(bel,30)))px(i,j,0);
    EI((end-i)%10==9)px(i,j,0);
    E px(i,j,((SLs>>bel)&1)?Sc.Mix(0x006666,0x00FFCC,FL(bel)/20.0):0x333333);
    CN;
   }
   I(j<base){
    I(!(STs>>min(bel,30)))px(i,j,0);
    EI((end-i)%10==9)px(i,j,0);
    E px(i,j,((STs>>bel)&1)?Sc.Mix(0x0080FF,0x39C5BB,FL(bel)/20.0):0x333333);
    CN;
   }
   D clr=(end-i<pp)?0x00FF00:0x333333;
   I(j==base+6)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.5:0.1);
   I(j==base+7)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.3:0.05);
   px(i,j,clr);
  }}
 CheckKey(InAre);
 base-=20;D cap=10;W(cap<=SA)cap<<=1;
 pp=D(floor(FL(SA)/FL(cap)*FL(end-beg+1)));
 F(D j=base-2;j<base+12;++j){
  px(beg-1,j,0x888888);px(end+1,j,0x888888);
 }
 F(D j=base;j<base+10;++j){
  px(beg-2,j,0xCCCCCC);px(end+2,j,0xCCCCCC);
 }
 F(D i=beg;i<=end;++i){
  F(D j=base-3;j<base+10;++j){
   D bel=(end-i)/10;
   I(j<base){
    I(!(SA>>min(bel,30)))px(i,j,0);
    EI((end-i)%10==9)px(i,j,0);
    E px(i,j,((SA>>bel)&1)?Sc.Mix(0xEE0000,0xFFFF00,FL(bel)/20.0):0x333333);
    CN;
   }
   D clr=(end-i<pp)?0xEE0000:0x333333;
   I(j==base+6)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.3:0.1);
   I(j==base+7)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.2:0.05);
   px(i,j,clr);
  }}
 base-=20;beg-=15;
 F(D i=5;i>=0;--i){
  F(D ii=-6;ii<=6;++ii){
   F(D jj=-6;jj<=6;++jj){
    I(ii*ii+jj*jj>48)CN;
    D clr=0;
    I(cl>i){
     clr=0xFFFFFF;
    }
    I((MsA!="          ")&&((i==4)||((i==5)&&(FullSp))))clr=ShiftColor(BsT[SPTID].Color);
    I((i<4)&&(MsB=="ALL CLEAR "))clr=0x00FFCC;
    clr=Sc.Mix((i>=4)?0x333333:0x888888,clr,FL(ii*ii+jj*jj)/49.0);
    px(beg+ii,base+jj,clr);
   }}
  beg+=15;
 }
 base+=3;beg+=5;end=max(end,beg+10);
 pp=D(floor(lpm/60.0*FL(LenY)*0.1*FL(end-beg+1)));
 F(D j=base-2;j<base+12;++j){
  px(beg-1,j,0x888888);px(end+1,j,0x888888);
 }
 F(D j=base;j<base+10;++j){
  px(beg-2,j,0xCCCCCC);px(end+2,j,0xCCCCCC);
 }
 CheckKey(InAre);
 D lst=-1,rem=0;
 F(D i=beg;i<=end;++i){
  F(D j=base;j<base+10;++j){
   D clr=(end-i<pp)?Sc.Mix(0x66CCFF,0x0080FF,FL(end-i)/FL(end-beg+1)):0x333333;
   D nw=(end-i)*60/(end-beg+1);
   I((nw!=lst)||(rem)){
    I(lst>=0)clr=(end-i<pp)?0x333333:0x666666;
    I(rem)--rem;
    EI(lst%5==0)rem=2;
    EI(lst%10==0)rem=5;
    lst=nw;
   }
   I(j==base+6)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.5:0.1);
   I(j==base+7)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.3:0.05);
   px(i,j,clr);
  }}
 base-=15;pp=D(floor(apm/100.0*FL(LenY)*0.1*FL(end-beg+1)));
 F(D j=base-2;j<base+12;++j){
  px(beg-1,j,0x888888);px(end+1,j,0x888888);
 }
 F(D j=base;j<base+10;++j){
  px(beg-2,j,0xCCCCCC);px(end+2,j,0xCCCCCC);
 }
 lst=-1;rem=0;
 F(D i=beg;i<=end;++i){
  F(D j=base;j<base+10;++j){
   D clr=(end-i<pp)?Sc.Mix(0xFFFF00,0xEE0000,FL(end-i)/FL(end-beg+1)):0x333333;
   D nw=(end-i)*100/(end-beg+1);
   I((nw!=lst)||(rem)){
    I(lst>=0)clr=(end-i<pp)?0x333333:0x666666;
    I(rem)--rem;
    EI(lst%5==0)rem=2;
    EI(lst%10==0)rem=5;
    lst=nw;
   }
   I(j==base+6)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.3:0.1);
   I(j==base+7)clr=Sc.Mix(0xFFFFFF,clr,(end-i<pp)?0.2:0.05);
   px(i,j,clr);
  }}
 CheckKey(InAre);
 D DropLen=LenX;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   Gst[i][j]=0;
   I(C[i][j]){
    D Len=0;W(!CheckT(i-Len-1,j))++Len;
    DropLen=min(DropLen,Len);
   }}}
 F(D i=1;i<min(ARe,DisX);++i){
  I(AQu[i]!=AQu[i-1])ACol[i]=!ACol[i-1];
  E ACol[i]=ACol[i-1];
 }
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j])Gst[i-DropLen][j]=1;
  }}
 F(D i=1;i<min(ARe,DisX);++i){
  I(AQu[i]!=AQu[i-1])ACol[i]=!ACol[i-1];
  E ACol[i]=ACol[i-1];
 }
 D WLv=0;DelPx.clear();
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(CheckT(i,j))WLv=min(i+1,DisX-2);
  }}
 F(D j=0;j<LenY;++j){
  OverCol[j]=0;
  F(D i=DisX+1;i<LenX;++i){
   I(CheckT(i,j))OverCol[j]=i-DisX;
  }
  I((BU)||(OverCol[j]!=_oc[j])){
  	stc(0);out(j*sz+230,_sx+24,OcT[j],strlen(OcT[j]));_oc[j]=OverCol[j];
  	I(_oc[j])sprintf(OcT[j],"%2d",OverCol[j]);
  	E sprintf(OcT[j],"");
  	stc((_oc[j])?0x0000EE:0);out(j*sz+230,_sx+24,OcT[j],strlen(OcT[j]));
  }
 }
 I((_clu!=Clu)||(BU)){
  _clu=Clu;stc(0);out((sy+ey)/2+35,_sx+9,CluT,strlen(CluT));
  D clr=0xD0F0;clr=Sc.Mix(clr,0,(MsRe-150)/100.0);
  I(Clu)sprintf(CluT,"%d Clutch",Clu);
  E sprintf(CluT,"");
  stc(clr);out((sy+ey)/2+35,_sx+9,CluT,strlen(CluT));
 }
 D TDC=-1;
 D LCT=LenX,LCR=LCLi;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(!B[i][j]){
    --LCT;BK;
   }
  }
 }
 D InLcd=((InAre==2)&&(LCT>=LCSt));_wn=Win;
 D CDropAv=(CDrop)&&(!InAre);
 D HoriNeg=(HoriDel<0.0);HoriDel=abs(HoriDel);
 HoriDel=max(0.0,HoriDel-max(0.3,0.3*HoriDel));I(HoriNeg)HoriDel=-HoriDel;
 D VerNeg=(VerDel<0.0);VerDel=abs(VerDel);
 VerDel=max(0.0,VerDel-max(0.3,0.3*VerDel));I(VerNeg)VerDel=-VerDel;
 I(CDrop){
  F(Particle p : PQu){
   D x=round(p.x),y=round(p.y),r=ceil(p.r);
   F(D i=-r;i<=r;++i){
    F(D j=-r;j<=r;++j){
     I(FL(i*i+j*j)>p.r*p.r)CN;
     D nx=x+i,ny=y+j;I((min(nx,ny)<0)||(max(nx,ny)>=3000))CN;
     I(PixHold[nx][ny]==DsID)CN;
     Sc.Plot(nx,ny,p.clr);PixHold[nx][ny]=DsID;
     I(PixBel[nx][ny].first)NCEff[PixBel[nx][ny].first-1][PixBel[nx][ny].second-1]=1;
     E NCPx.push_back(make_pair(nx,ny));
	}
   }
   Particle np=p;np.dx+=np.ax;np.dy+=np.ay;
   np.x+=np.dx;np.y+=np.dy;np.r-=np.dr*(Auto?5:1)*max(1.0,double(DisX*LenY)/420.0);
   I(np.r>=0.0)NPQu.push_back(np);
  }
  PQu.swap(NPQu);NPQu.clear();
  F(pair<D,D> p:CPx){
   I(upd[p.first+300][p.second+300]!=DsID)Sc.Plot(p.first,p.second,0);
  }
  CPx.swap(NCPx);NCPx.clear();
 }
 E PQu.clear();
 I(CDropAv){
  LDRate=(_ntl>0)?min(double(DropLen),_gr*double(max(min(_ntl,_ntlp),0))/double(_ntl)):0;
  D DRate=(_ntl>0)?round(sz*LDRate):0,HRate=round(sz*HoriDel);
  DRate+=round(sz*VerDel);RealDRate=DRate;
  F(D i=min(LenX-1,DisX+1);i>=0;--i){
   D lx=(DisX-i+5)*sz-80+DRate,rx=lx+sz-1;
   F(D j=0;j<LenY;++j){
    D ly=j*sz+200+HRate,ry=ly+sz-1;
   	I(!C[i][j])CN;CheckKey(InAre);
   	F(D ii=lx;ii<=rx;++ii){
    F(D jj=ly;jj<=ry;++jj){
     I((PixHold[ii][jj]==DsID)||(!PixBel[ii][jj].first)||(ii<0))CN;
     D di=min(ii-lx,rx-ii),dj=min(jj-ly,ry-jj);
     ++di;++dj;
     I((ii==rx)||(jj==ry)||(ii==lx)||(jj==ly))CN;
     D clr=ShiftColor(B[i][j]);
     D li=min(ii-lx,jj-ly),ri=min(rx-ii,ry-jj);
     I(li<=4)clr=Sc.Mix(0xFFFFFF,clr,(5-li)*0.1);
     I(ri<=3)clr=Sc.Mix(0,clr,(3-ri)*0.1);
     I(min(di,dj)>3)clr=Sc.Mix(0xFFFFFF,clr,FL(min(di,dj)-3)*0.1*((MvsLi<=1000&&MvsLi!=0)?FL(min(MvsLi,MvsLeft))/FL(MvsLi):bool(MvsLi)));
     PixHold[ii][jj]=DsID;px(ii,jj,clr);
     I(PixBel[ii][jj].first)NCEff[PixBel[ii][jj].first-1][PixBel[ii][jj].second-1]=1;
    }}
   }
  }
 }
 BU=_BU;
 F(D i=DisX;i>=0;--i){
  cls[i]=1;F(D j=0;j<LenY;++j)I(!B[i][j])cls[i]=0;
  I((InAre!=2)||(LCT<LCSt)||(!LCR))cls[i]=0;
  I(cls[i])--LCR;
  D lx=(DisX-i+5)*sz-80,rx=lx+sz-1;
  D WDis=(LenY>=4)?1:3;
  I((DisX>WDis+1)&&(i==DisX-WDis)){
   F(D jj=200;jj<=LenY*sz+199;++jj){
    I((jj/5)&1)px(rx,jj,Sc.Mix(0xEE0000,0x888888,FL(WLv)/FL(DisX-2)*FL(WLv)/FL(DisX-2)*FL(WLv)/FL(DisX-2)));
   }}
  D DClr=1;F(D j=0;j<LenY;++j)I((!B[i][j])&&(!Gst[i][j]))DClr=0;I(cls[i])++TDC;
  F(D j=0;j<LenY;++j){
   D pB=B[i][j];I(((C[i][j])&&(CDropAv))||(((!C[i][j])||((!InLcd)&&(BlindLv==2)))&&(!Sight)&&((BlindLv==2)||((BlindLv==1)&&(!InLcd)))))B[i][j]=0;
   I(!SdwT)Gst[i][j]=0;
   D ly=j*sz+200,ry=ly+sz-1,Spt=((SpPoi[i][j])&&(WLv+7>=DisX))?(TSpPoi[TQu[0]][i][j]?2:1):0;
   I((!BU)&&(!CEff[i][j])&&((!HM[i][j])||(Hint==_hint))&&(_hm[i][j]=HM[i][j])&&((!CDropAv)||((!C[i][j])&&(!C[i+1][j])))&&(_spt[i][j]==Spt)&&((!Spt)||(WLv==_wl))&&((!Gst[i][j])||(_dclr[i]==DClr))&&((!C[i][j])||(_mvl==MvsLeft))&&(_cls[i]==cls[i])&&((!C[i][j])||(_are==(InAre==2)))&&(M[i][j]==_m[i][j])&&((ResB>i)==_rs[i][j])&&(BMark[i][j]==_de[i][j])&&(Gst[i][j]==_dt[i][j])&&((ARe<=i)==_ak[i][j]||1)&&(_bd[i][j]==B[i][j])&&(_at[i][j]==C[i][j])){
    B[i][j]=pB;CN;
   }CheckKey(InAre);
   _m[i][j]=M[i][j];_hm[i][j]=HM[i][j];CEff[i][j]=0;_spt[i][j]=Spt;_rs[i][j]=(ResB>i);_bd[i][j]=B[i][j];_at[i][j]=C[i][j];_dt[i][j]=Gst[i][j];_ak[i][j]=(ARe<=i);_de[i][j]=BMark[i][j];
   F(D ii=lx;ii<=rx;++ii){
    F(D jj=ly;jj<=ry;++jj){PixBel[ii][jj]=make_pair(i+1,j+1);
     I(PixHold[ii][jj]==DsID)CN;
     D di=min(ii-lx,rx-ii),dj=min(jj-ly,ry-jj);++di;++dj;
     I((ii==rx)||(jj==ry)||(ii==lx)||(jj==ly)){
      I((ii==rx)&&(DisX>2)&&(i==DisX-WDis)&&((jj/5)&1))CN;
      EI((!B[i][j])&&(Gst[i][j])&&(di+dj>2))px(ii,jj,(DClr)?0x39C5BB:0x666666);
      E px(ii,jj,(0&&ARe>i)?0xFF6666:(((i<DisX-WDis)?0x191919:0x101010)));
      CN;
     }
     I((Hint)&&(HM[i][j])&&(min(di,dj)>2)){
      Sc.Plot(ii,jj,Sc.Mix(0,ShiftColor(BsT[TID].Color),(min(di,dj)&1)?0.6:0.8));CN;
	 }
     I(!B[i][j]){
      I((Gst[i][j])&&(min(di,dj)<3))px(ii,jj,Sc.Mix((DClr)?0x39C5BB:0x888888,0,0.25*FL(4-min(di,dj))));
      EI((Spt)&&(max(di,dj)>3)&&(abs(di-dj)<Spt))px(ii,jj,Sc.Mix((Spt==2)?0xEE0000:0x006666,0,0.2*min(5,WLv-DisX+8)));
      EI((SpPoi[i][j])&&(di>3)&&(di==dj))px(ii,jj,0x333333);
      EI((0&&ARe>i)&&((ii+5-jj%5)%5<2))px(ii,jj,Sc.Mix((ACol[i]==4)?0xEE0000:0xFF6666,0,0.3));
      EI((ResB>i)&&((ii+jj)%2))px(ii,jj,Sc.Mix(0xEE0000,0,0.5));
      EI((BMark[i][j])&&(DecMark)&&((ii+jj)%5<2))px(ii,jj,0x333333);
      E px(ii,jj,((!M[i][j])||(min(di,dj)<3))?0:Sc.Mix(ShiftColor(M[i][j]),0,FL(min(6,min(di,dj))*2)/FL(sz)));
      CN;
     }
     D clr=ShiftColor(B[i][j]);
     I(cls[i])clr=Sc.Mix(0x00FFCC,0x99FFFF,TDC*0.25+FL(rx-ii)/FL(rx-lx+1)*0.25);
     D li=min(ii-lx,jj-ly),ri=min(rx-ii,ry-jj);
     I(li<=4)clr=Sc.Mix(0xFFFFFF,clr,(5-li)*0.1);
     I(ri<=3)clr=Sc.Mix(0,clr,(3-ri)*0.1);
     I((C[i][j])&&(InAre!=2)){
      I(min(di,dj)>3)clr=Sc.Mix(0xFFFFFF,clr,FL(min(di,dj)-3)*0.1*((MvsLi<=1000&&MvsLi!=0)?FL(min(MvsLi,MvsLeft))/FL(MvsLi):bool(MvsLi)));
     }
     EI(C[i][j]){
      I((ii+jj)%8<5)clr=Sc.Mix(0xFFFFFF,clr,0.1*(5-(ii+jj)%8));
	 }
     E {
      I(((B[i][j]>>10)==1)&&(min(di,dj)==4))clr=Sc.Mix(0,clr,0.1);
      I(((B[i][j]>>10)==1)&&(min(di,dj)>4))clr=Sc.Mix(0xFFFFFF,clr,FL(min(di,dj)-4)*0.06);
      I(((B[i][j]>>10)==0)&&(min(di,dj)==4))clr=Sc.Mix(0,clr,0.1);
      I(((B[i][j]>>10)==0)&&(min(di,dj)==5))clr=Sc.Mix(0,clr,0.15);
      I(((B[i][j]>>10)==0)&&(min(di,dj)>5))clr=Sc.Mix(0xFFFFFF,clr,FL(min(di,dj)-4)*0.06);
      I((((B[i][j]>>10)==2)||(B[i][j]<0))&&(min(di,dj)>3))clr=Sc.Mix((B[i][j]<0)?0xFFFF00:0x333333,clr,FL(min(di,dj)-3)*0.1);
      I((B[i][j]>>10)==3)clr=Sc.Mix(0,clr,0.04*(min(di,dj)&1)*FL(max(3,min(di,dj))));
      I(0&&ARe>i)clr=Sc.Mix(clr,0xEE0000,0.7);
     }
     I((Spt)&&(max(di,dj)>3)&&(abs(di-dj)<Spt)){
      clr=Sc.Mix((Spt==2)?0xEE0000:0x00FFCC,clr,0.2*min(5,WLv-DisX+8));
	 }
     px(ii,jj,clr);I(cls[i])DelPx.push_back(make_pair(ii,jj));
    }}B[i][j]=pB;}
  _cls[i]=cls[i];_dclr[i]=DClr;CheckKey(InAre);
 }CDropAv=CDrop;
 I(CDropAv){
  F(D i=0;i<LenX;++i){
   F(D j=0;j<LenY;++j)I(NCEff[i][j])CEff[i][j]=1;
  }
 }
 BU=0;_wl=WLv;_are=(InAre==2);_mvl=MvsLeft;_hint=Hint;
}
#define CkU() CkD(1)
D CkD(D del=-1){
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I((C[i][j])&&(CheckT(i+del,j)))RE 0;
  }}
 RE 1;
}
#define CkR() CkL(1)
D CkL(D del=-1){
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I((C[i][j])&&(CheckT(i,j+del)))RE 0;
  }}
 RE 1;
}
D MvDown(bool _=0){
 I(!CkD())RE 0;
 D _x=0,_y=0;
 F(D i=0;i+1<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i+1][j]){
    C[i][j]=1;B[i][j]=B[i+1][j];
   }
   EI(C[i][j]){
    C[i][j]=B[i][j]=0;_x=i;_y=j;
   }}}
 F(D j=0;j<LenY;++j){
  I(C[LenX-1][j]){
   C[LenX-1][j]=B[LenX-1][j]=0;_x=LenX-1;_y=j;
  }}
 I((_)&&(!B[_x][_y]))B[_x][_y]=Ts[TC][0].Color;
 RE 1;
}
D MvUp(bool _=0){
 I(!CkU())RE 0;
 D _x=0,_y=0;
 F(D i=LenX-1;i>=1;--i){
  F(D j=0;j<LenY;++j){
   I(C[i-1][j]){
    C[i][j]=1;B[i][j]=B[i-1][j];
   }
   EI(C[i][j]){
    C[i][j]=B[i][j]=0;_x=i;_y=j;
   }}}
 F(D j=0;j<LenY;++j){
  I(C[0][j]){
   C[0][j]=B[0][j]=0;_x=0;_y=j;
  }}
 I((_)&&(!B[_x][_y]))B[_x][_y]=Ts[TC][0].Color;
 RE 1;
}
D MvLeft(bool _=0){
 I(!CkL())RE 0;
 D _x=0,_y=0;
 F(D j=0;j+1<LenY;++j){
  F(D i=0;i<LenX;++i){
   I(C[i][j+1]){
    C[i][j]=1;B[i][j]=B[i][j+1];
   }
   EI(C[i][j]){
    C[i][j]=B[i][j]=0;_x=i;_y=j;
   }}}
 F(D i=0;i<LenX;++i){
  I(C[i][LenY-1]){
    C[i][LenY-1]=B[i][LenY-1]=0;_x=i;_y=LenY-1;
  }}
 I((_)&&(!B[_x][_y]))B[_x][_y]=Ts[TC][0].Color;
 RE 1;
}
D MvRight(bool _=0){
 I(!CkR())RE 0;
 D _x=0,_y=0;
 F(D j=LenY-1;j>=0;--j){
  F(D i=0;i<LenX;++i){
   I(C[i][j-1]){
    C[i][j]=1;B[i][j]=B[i][j-1];
   }
   EI(C[i][j]){
    C[i][j]=B[i][j]=0;_x=i;_y=j;
   }}}
 F(D i=0;i<LenX;++i){
  I(C[i][0]){
   C[i][0]=B[i][0]=0;_x=i;_y=0;
  }
 }
 I((_)&&(!B[_x][_y]))B[_x][_y]=Ts[TC][0].Color;
 RE 1;
}
D GR,NY;
D TryR(CT T,D x,D y){
 F(D i=0;i<T.LenX;++i){
  F(D j=0;j<T.LenY;++j){
   I((T.Bl[i][j])&&(CheckT(x+i,y+j))){
    NY=j;RE 0;
   }
  }}
 GR=1;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j]){
    C[i][j]=0;B[i][j]=0;
   }}}
 F(D i=0;i<T.LenX;++i){
  F(D j=0;j<T.LenY;++j){
   I(T.Bl[i][j]){
    C[x+i][y+j]=1;B[x+i][y+j]=T.Color;
   }}}
 RE 1;
}
vector<pair<D,D> > K[4][4],IK[4][4],OK[4][4];D KX,KY;
D R(CT OldT,CT NewT,D From,D To){
 D FirstCX=-1,FirstCY=-1;KX=0;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j]){
    FirstCY=j;BK;
   }}
  I(FirstCY>=0){
   FirstCX=i;BK;
  }}
 D FirstTX=-1,FirstTY=-1;
 F(D i=0;i<OldT.LenX;++i){
  F(D j=0;j<OldT.LenY;++j){
   I(OldT.Bl[i][j]){
    FirstTY=j;BK;
   }}
  I(FirstTY>=0){
   FirstTX=i;BK;
  }}
 D BaseX=FirstCX-FirstTX;KX=KY=0;
 D BaseY=FirstCY-FirstTY;
 I(TryR(NewT,BaseX,BaseY)){
  GR=0;RE 1;
 }
 I(!KWall)RE 0;
 From=(From+InitRot)&3;To=(To+InitRot)&3;
 vector<pair<D,D> >KT=K[From][To];
 I(NewT.Color==BsT[0].Color)KT=IK[From][To];
 I(NewT.Color==BsT[3].Color)KT=OK[From][To];
 F(D i=11;i<TC;++i)I(NewT.Color==BsT[i].Color)KT=OK[From][To];
 F(pair<D,D> p : KT){
  I(TryR(NewT,BaseX+p.second,BaseY+p.first)){
  	KX=p.second;KY=p.first;GR=(KX<=-2);RE 1;
  }
  I((RSys==3)&&((NewT.Color==BsT[1].Color)||(NewT.Color==BsT[2].Color)||(NewT.Color==BsT[5].Color))&&(NY==1))RE 0;}
 RE 0;
}
D FNY;
D NoPlc(CT T,D x,D y){
 F(D i=0;i<T.LenX;++i){
  F(D j=0;j<T.LenY;++j){
   I((T.Bl[i][j])&&(CheckT(x+i,y+j))){
    FNY=j;RE 1;
   }
  }}
 RE 0;
}
D CkSp(){
 RE (!CkU())&&(!CkD())&&(!CkL())&&(!CkR());
}
void RemoveC(){
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j]){
    C[i][j]=B[i][j]=0;
   }}}}
vector<pair<D,D> >C8={{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
D PreSet[110][110][4],PreStuck[100][100][4],Stuck;
D QPlc(D TID,D x,D y,D d){
 I(PreSet[x+5][y+5][d]==-1){
  PreSet[x+5][y+5][d]=NoPlc(Ts[TID][d],x,y);PreStuck[x+5][y+5][d]=(FNY==1);
 }
 Stuck=PreStuck[x+5][y+5][d];RE PreSet[x+5][y+5][d];
}
void Exp(D x,D y){
 I(B[x][y]==-1){
  B[x][y]=8;D sz=BlockSz;
  D lx=(DisX-x+5)*sz-80,rx=lx+sz-1,ly=y*sz+200,ry=ly+sz-1;
  FL theta=Rnd.Rand(1000)*0.001*2.0*acos(-1.0);
  PQu.push_back((Particle){FL(lx+rx)*0.5,FL(ly+ry)*0.5,3.0,0.02,-2.0,(Rnd.Rand(11)-5)*0.1,0.2,0,0xFFFF00});
 }
 I((x>0)&&(B[x-1][y]<0))Exp(x-1,y);
 I(B[x+1][y]<0)Exp(x+1,y);
 I((y>0)&&(B[x][y-1]<0))Exp(x,y-1);
 I(B[x][y+1]<0)Exp(x,y+1);
}
D FinalDrop(){
 D Sp=CkSp();
 FullSp=1;D lx=LenX-1,ly=LenY-1,rx=0,ry=0,clr=0;
 bool _o=0,_dot=0;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j]){
   	Exp(i,j);
    lx=min(lx,i);ly=min(ly,j);rx=max(rx,i);ry=max(ry,j);clr=B[i][j]&63;
    I(CheckT(i+3,j))_o=1;
    I(CheckT(i+2,j))_dot=1;
   }
  }
 }
 F(D i=lx;i<=rx;++i){
  F(D j=ly;j<=ry;++j){
   I(!B[i][j])FullSp=0;
  }
 }
 I((!TID)||(TID==3)||(TID==8)||(TID==11)){
  F(D i=max(0,lx-1);i<=min(LenX-1,rx+1);++i){
  	F(D j=max(0,ly-1);j<=min(LenY-1,ry+1);++j){
     I(B[i][j])CN;
     D tot=0;
     F(pair<D,D>p:C8){
      D ni=i+p.first,nj=j+p.second;
      I((!CheckT(ni,nj))&&(C[ni][nj]))++tot;
	 }
	 I(tot>=((TID==10)?1:(((TID==3)||(TID==9))?2:3)))FullSp=0;
	}
  }
 }
 I(((TID==3)||(TID==10))&&(!_o))FullSp=0;
 I((TID==10)&&(!_dot))FullSp=0;
 //I(Sp)FullSp=1;
 I(((KX<=-2)&&((KY<=-1)||(KY>=1)))&&((clr==13)||(clr==10)||(clr==12)))FullSp=1;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(C[i][j]){
    I(Sp)B[i][j]|=(1024*3);
    C[i][j]=0;
   }}}
 RE Sp;
}
D Fin[50][90][4];queue<pair<pair<D,D>,D> > Qu;
D Mode=0;D Ri,Rj,Rd;pair<LD,LD> MinG,LstMnF;D TB[100][100];
D PV[100][100],TPV[100][100],PTop,PBot,PCnt=0;
void Pit(D x,D y){
 I((min(x,y)<0)||(x>=LenX)||(y>=LenY)||(TB[x][y])||(PV[x][y]))RE;
 PV[x][y]=1;PTop=max(PTop,x);PBot=min(PBot,x);++PCnt;
 Pit(x-1,y);Pit(x+1,y);Pit(x,y-1);Pit(x,y+1);
}
void TPit(D x,D y){
 I((min(x,y)<0)||(x>=LenX)||(y>=LenY)||(TB[x][y])||(TPV[x][y]))RE;
 TPV[x][y]=1;
 TPit(x-1,y);TPit(x+1,y);TPit(x,y-1);TPit(x,y+1);
}
D CMod=0,CASp=0;
D MakeSp(D TID,D UID){
 D FstP=99;
 I(((UID==H)?TQu[0]:H)==TID)FstP=0;
 F(D i=1;i<NxtT;++i){
  I(TQu[i]==TID)FstP=min(FstP,i);
 } 
 //I(FstP==99)RE 0;
 F(CT T:SpTp[TID]){
  F(D i=DisX;i>=-1;--i){
   F(D j=-1;j<LenY;++j){
   	D _=1;
    F(D ii=0;ii<T.LenX;++ii){
     D pi=i+ii;
     F(D jj=0;jj<T.LenY;++jj){
      D pj=j+jj,cur=0;
      I(min(pi,pj)<0||pi>=LenX||pj>=LenY)cur=1;
      EI((!TB[pi][pj])&&(!TPV[pi][pj]))cur=2;
      EI(TB[pi][pj])cur=1;
      I(T.Bl[ii][jj]!=2&&T.Bl[ii][jj]!=cur){
       _=0;BK;
	  }
	 }
	 F(D jj=0;jj<j;++jj)I(!TB[pi][jj]&&!TPV[pi][jj])_=0;
     F(D jj=j+T.LenY+1;jj<LenY;++jj)I(!TB[pi][jj]&&!TPV[pi][jj])_=0;
	 I(!_)BK;
	}
	I(_)RE 7;
   }
  }
 }
 RE 0;
}
void FillSp(D TID){
 F(CT T:SpTp[TID]){
  F(D i=DisX;i>=-1;--i){
   F(D j=-1;j<LenY;++j){
   	D _=1;
    F(D ii=0;ii<T.LenX;++ii){
     D pi=i+ii;
     F(D jj=0;jj<T.LenY;++jj){
      D pj=j+jj,cur=0;
      I(min(pi,pj)<0||pi>=LenX||pj>=LenY)cur=1;
      EI((!TB[pi][pj])&&(!TPV[pi][pj]))cur=2;
      EI(TB[pi][pj])cur=1;
      I(T.Bl[ii][jj]!=2&&T.Bl[ii][jj]!=cur){
       _=0;BK;
	  }
	 }
	 F(D jj=0;jj<j;++jj)I(!TB[pi][jj]&&!TPV[pi][jj])_=0;
     F(D jj=j+T.LenY+1;jj<LenY;++jj)I(!TB[pi][jj]&&!TPV[pi][jj])_=0;
	 I(!_)BK;
	}
	I(!_)CN;
    F(D ii=0;ii<T.LenX;++ii){
     D pi=i+ii;
     F(D jj=0;jj<T.LenY;++jj){
      D pj=j+jj,cur=0;
      I(min(pi,pj)<0||pi>=LenX||pj>=LenY)cur=1;
      EI((!TB[pi][pj])&&(!TPV[pi][pj]))cur=2;
      EI(TB[pi][pj])cur=1;
      I(!T.Bl[ii][jj]&&!cur)TB[pi][pj]=1;
	 }
	}
	RE;
   }
  }
 }
 RE;
}
pair<LD,LD> TmpCalc(D _x,D TID) {//Auto=0;
 I(!CASp)CMod=0;
 I((!Auto)&&(!Zen))RE make_pair(0LL,0LL);
 D CurL=0,ClT=0;
 LD f=0LL;
 LD r=0LL,ra=0LL;D ToP=0,Ero=0,Gh=0;
 D SpU=0,SpL=0,SpR=0;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(TB[i][j]==2&&TB[i+1][j]==1)SpU=1;
   I(TB[i][j]==2&&(!j||TB[i][j-1]==1))SpL=1;
   I(TB[i][j]==2&&(j+1==LenY||TB[i][j+1]==1))SpR=1;
  }
 }
 D Sp=SpU*SpL*SpR;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j)I(TB[i][j]==2)r+=(CMod?500:290)*(LenX-i)/4,Gh-=(i+1),++ToP;
  D Cls=1;F(D j=0;j<LenY;++j)I(!TB[i][j])Cls=0;
  I(Cls)++ClT;
  E{
   I(CurL!=i)F(D j=0;j<LenY;++j)TB[CurL][j]=TB[i][j];
   ++CurL;
  }
 }
 F(D i=0;i<ClT;++i)F(D j=0;j<LenY;++j)TB[LenX-i-1][j]=0;
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(TB[i][j]==2)++Ero;
   I(SpPoi[i][j]&&TB[i][j]) RE make_pair(1000000000000000000LL,0LL);
   PV[i][j]=TPV[i][j]=0;
  }
 }
 r+=LD(ClT)*(ToP-Ero);
 I(Sp)ra+=500*ClT;
 I(CMod&&Sp&&!ClT)ra-=30;
 F(D i=LenX-1;i>=0;--i){
  F(D j=0;j<LenY;++j){
   I((TB[i][j])||(PV[i][j]))CN;
   PTop=0;PBot=LenX;Pit(i,j);PCnt=0;
   I(PTop<LenX-1){
    r-=190LL*max(0,PTop-PBot);
   }
   E TPit(i,j);
  }
 } 
 I(CMod&&(!Sp||!ClT)){
  D SpB=0,SpID=-1;
  F(D i=0;i<TC;++i){
   D nxt=MakeSp(i,TID);
   I(nxt>SpB)SpB=nxt,SpID=i;
  }
  I(SpID>=0){
   ra+=100*SpB;//printf("%d",SpB);
  }
 }
 F(D i=0;i<LenX;++i){
  F(D j=0;j<LenY;++j){
   I(i+1<LenX){
    I((TB[i][j]!=0)!=(TB[i+1][j]!=0))r-=260,--ra;
    I((!TB[i][j])&&(TB[i+1][j]))r-=450,ra-=4;
   }
   I(j+1<LenY){
    I((TB[i][j]!=0)!=(TB[i][j+1]!=0))r-=260,--ra;
   }
   I((!TB[i][j])&&((!j)||(TB[i][j-1]))&&((j==LenY-1)||(TB[i][j+1])))--ra;
  }
 }
 F(D i=LenX-1;i>=0;--i){
  D _=0;
  F(D j=0;j<LenY;++j)_|=TB[i][j];
  I(_){
   r-=110*LD(i+1);BK;
  }
 }
 //I(CMod)RE make_pair(-r,-(ra*ToP+Gh));
 RE make_pair(-(ra*ToP+Gh),-r);
}
char PreCh[50][90][4];D PreRep[50][90][4];D Pi[50][90][4],Pj[50][90][4],Pd[50][90][4];
stack<pair<char,bool> > Oper;D ___;