#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
_AX=0x13;
geninterrupt(0x10);
clock_t T=clock();
srand(time(NULL));
printf("%c[3;28f Nivel=1",27);
char far*q=(char far*)0xA0000000;
char E,far*Q[275][49];
char A[][4][4]={";<=>","2=HS",";<=>","2=HS",
"<GHI","<=GR",";<=H","1<GH",
"=FGH","1<GH","<=>G","<=HS",
";<GH","2=<G",";<GH","2=<G",
"=>GH","<GHS","=>GH","<GHS",
"<FGH","1<=G","<=>H","=GHS",
"<=GH","<=GH","<=GH","<=GH"};
int Y[25],G[]={1,2,3,0};
int e[256],f[275],a,g,x,y;
int b=256,c=274,d=49,n=61956,p=6,L=0,M=9;
while(d--) e[d]=d/7*320+d%7;
for(y=25;y--;Y[y]=0,n-=2472)
for(x=11;x--;f[c--]=c/11,n-=8)
for(a=8*(y%24<1||x%10<1),d=49;d--;)
*(Q[c][d]=q+n+e[d])=a;
while(b--) e[b]=11;
e[72]=0;
e[75]=-1;
e[77]=1;
for(a=7;a--;) for(g=4;g--;)
for(n=4;n--;) A[a][g][n]-=48;
Inicio:
for(g=n=0;n<4;n++)
if(!*Q[c=A[a=p][0][n]+4][0])
for(d=49;d--;*Q[c][d]=a+1)
*(Q[c][d]+17048)=0;
else while(1) if(getch()==27)
return 0;
p=rand()%7;
while(n--)
for(c=A[p][0][n],d=49;d--;)
*(Q[c][d]+17080)=p+1;
n=x=c=4;
do{
while(E=kbhit()) getch();
do if(kbhit()) E=getch();
while(!E&&clock()-T<M);
if(E==27&&getch()==27) return 0;
if(E=='-') printf("%c[3;35f%u",27,10-(M+=M<10));
if(E=='+') printf("%c[3;35f%u",27,10-(M-=M>1));
x+=E=e[E];
b=E?g:G[g];
while(n--)
for(y=A[a][g][n]+c,d=49;d--;)
*Q[y][d]=0;
while(++n<4)
if(*Q[A[a][b][n]+x][0]) break;
if(n<4) x=-1;
else if(c!=x) c=x;
else g=b;
for(n=0;n<4;n++)
for(y=A[a][g][n]+c,d=49;d--;)
*Q[y][d]=a+1;
if(E==11) T=clock();
else x=c;
}while(x+1);
for(n=0;n<4;n++)
Y[y=f[A[a][g][n]+c]]++;
do while(Y[x=y]>8)
do{
if(x==y) printf("%c[5;28fLineas=%u",27,++L);
Y[--x]-=Y[x+1]=Y[x];
c=11*x;
for(n=9;n--;)
if(*Q[++c][0]+*Q[c+11][0])
for(b=x?*Q[c][0]:0,d=49;d--;)
*Q[c][d]-=*Q[c+11][d]=b;
}while(Y[x+1]);
while(Y[--y]);
goto Inicio;
}