#include<time.h>
#include<stdio.h>
#include<conio.h>
char far*q=1999+(char far*)0xB8000000;
char far*Q[1000];
int M=3,a=20,c=59;
int E,b,n,x,y;
int main(){
textmode(C40);
_setcursortype(_NOCURSOR);
clock_t T;
for(y=25;y--;)
for(x=40;x--;*q--=219)
*(Q[n++]=q--)=y<4||y>11?0:b,
b=x%2+!x?b:8-b/8;
Inicio:
T=clock();
do{
if(E=kbhit()) E=getch();
if(E==27&&getch()==E) return 0;
if(E==77&&a&&++*Q[--a]) *Q[a+4]=0;
if(E==75&&a<36&&++*Q[a+4]) *Q[a++]=0;
M+=(E=='-'&&M<5)-(E=='+'&&M>1);
}while(clock()-T<M);
x=c%40<1||c%40>38?-x:x;
y=c>959?1:y;
if(c<80){
n=c-a;
if(n<44+(x>0)&&n>39-(x<0)) y=-1;
while(y>0) if(getch()==13) y=-1;
if(n>40&&n<43) x=0;
else if(c>40&&c<79) x=(n<41)-(n>42);
}
else{
if(b=*Q[n=c-x]*x) *Q[n]=*Q[n+1-n%2*2]=0;
if(*Q[n=c-40*y]||*Q[n-=x]*x*!b&&++b)
*Q[n]=*Q[n+1-n%2*2]=0,
y=-y;
x=b?-x:x;
}
*Q[c]=0;
*Q[c-=40*y+x]=15;
goto Inicio;
}