Procedure Gor11(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum: byte;
  Begin
    For j:=1 to n do
      Begin
        For i:=4 to n-1 do
          Begin
            Rigth:=Pole[i+1,j];Left:=pole[i-3,j];
            Sum:=pole[i,j]+pole[i-1,j]+pole[i-2,j];
            Proz:=pole[i,j]*pole[i-1,j]*pole[i-2,j];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i-3;y:=j;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i-3;y:=j;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j]=1)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j]=1)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j]=1)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j]=2)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j]=2)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j]=2)then Begin x:=i-1;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-1,j]=2)and(pole[i-2,j]=2)then Begin x:=i;y:=j;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-1,j]=1)and(pole[i-2,j]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-1,j]=2)and(pole[i,j]=2)then Begin x:=i-2;y:=j;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-1,j]=1)and(pole[i,j]=1)then Begin x:=i-2;y:=j;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i-1,j]=1)and(pole[i,j]=1)then Begin x:=i-2;y:=j;prior:=5;end;
            If prior>4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-2,j]=1)and(cx=1)then Begin x:=i-1;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i-2,j]=2)and(cx=2)then Begin x:=i-1;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j]=2)and(pole[i-2,j]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j]=1)and(pole[i-2,j]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i-3;y:=j;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i-3;y:=j;Prior:=4;End;
                               If(Rigth=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j;prior:=4;End;
                               If(Rigth=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j;Prior:=4;End;
                               If(left=0)and(pole[i-2,j]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i-1;y:=j;Prior:=4;End;
                               If(left=0)and(pole[i-2,j]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i-1;y:=j;Prior:=4;End;
                             End;
          End;
      End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and((pole[x,y])=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;
  End;
Procedure Ver11(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum: byte;
  Begin
    For i:=1 to n do
      Begin
        For j:=4 to n-1 do
          Begin
            Rigth:=pole[i,j+1];Left:=pole[i,j-3];
            Sum:=pole[i,j]+pole[i,j-1]+pole[i,j-2];
            Proz:=pole[i,j]*pole[i,j-1]*pole[i,j-2];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i;y:=j+1;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i;y:=j+1;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i;y:=j-3;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i;y:=j-3;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i,j-2]=1)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i,j-2]=2)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i,j-2]=2)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i,j-2]=2)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i,j-2]=1)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i,j-2]=1)then Begin x:=i;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j-1]=2)and(pole[i,j-2]=2)then Begin x:=i;y:=j;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j-1]=1)and(pole[i,j-2]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j-1]=2)and(pole[i,j]=2)then Begin x:=i;y:=j-2;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j-1]=1)and(pole[i,j]=1)then Begin x:=i;y:=j-2;prior:=5;end;
            If prior<4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i,j-2]=1)and(cx=1)then Begin x:=i;y:=j-1;prior:=4;end;
                               If(left=1)and(rigth=1)and(sum=1)and(proz=0)and
                               (pole[i,j-1]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j-1]=1)and(pole[i,j-2]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j-1]=2)and(pole[i,j-2]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i,j-1]=1)and(cx=1)then Begin x:=i;y:=j-2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i,j-1]=2)and(cx=2)then Begin x:=i;y:=j-2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i,j-2]=2)and(cx=2)then Begin x:=i;y:=j-1;prior:=4;end;
                               If(left=2)and(rigth=2)and(sum=2)and(proz=0)and
                               (pole[i,j]=0)and(pole[i,j-2]=2)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j-3;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j-3;Prior:=4;End;
                                  If(left=0)and(pole[i,j-2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i;y:=j-2;Prior:=4;End;
                                  If(left=0)and(pole[i,j-2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i;y:=j-2;Prior:=4;End;

                             End;
          End;
      End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and((pole[x,y])=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;

  End;
Procedure Diag1(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum,t: byte;
  Begin
    For t:=5 to n do
     Begin
        i:=1;j:=t-2;
      While j>=2 do
          Begin
            Dec(j);Inc(i);
            Rigth:=pole[i+1,j-1];Left:=pole[i-3,j+3];
            Sum:=pole[i,j]+pole[i-1,j+1]+pole[i-2,j+2];
            Proz:=pole[i,j]*pole[i-1,j+1]*pole[i-2,j+2];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j-1;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j-1;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j-1;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i-3;y:=j+3;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j-1;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i-3;y:=j+3;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-1,j+1]=1)then Begin x:=i-2;y:=j+2;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-1,j+1]=2)then Begin x:=i-2;y:=j+2;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-1,j+1]=1)and(pole[i-2,j+2]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-2,j+2]=2)and(pole[i-1,j+1]=2)then Begin x:=i;y:=j;prior:=5;end;
            If prior<4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-2,j+2]=1)and(cx=1)then Begin x:=i-1;y:=j+1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i-2,j+2]=2)and(cx=2)then Begin x:=i-1;y:=j+1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j+1]=1)and(pole[i-2,j+2]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j+1]=2)and(pole[i-2,j+2]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-1,j+1]=1)and(cx=1)then Begin x:=i-2;y:=j+2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j+1]=2)and(pole[i,j]=2)and(cx=2)then Begin x:=i-2;y:=j+2;prior:=4;end;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i-3;y:=j+3;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i-3;y:=j+3;Prior:=4;End;
                               If(Rigth=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j;prior:=4;End;
                               If(Rigth=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j;Prior:=4;End;
                               
                                   If(left=0)and(pole[i-2,j+2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i-1;y:=j+1;Prior:=4;End;
                                   If(left=0)and(pole[i-2,j+2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i-1;y:=j+1;Prior:=4;End;

                             End;
      End;
     End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and((pole[x,y])=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;
  End;
Procedure Diag2(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum,t: byte;
  Begin
    For t:=n downto 5 do
     Begin
        i:=t;j:=n;
      While j>=2 do
          Begin
            Dec(j);Inc(i);
            Rigth:=pole[i+1,j-1];Left:=pole[i-3,j+3];
            Sum:=pole[i,j]+pole[i-1,j+1]+pole[i-2,j+2];
            Proz:=pole[i,j]*pole[i-1,j+1]*pole[i-2,j+2];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j-1;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j-1;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j-1;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i-3;y:=j+3;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i;y:=j;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i-3;y:=j+3;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j+2]=1)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j+2]=2)then Begin x:=i-1;y:=j+1;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-1,j+1]=1)then Begin x:=i-2;y:=j+2;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-1,j+1]=2)then Begin x:=i-2;y:=j+2;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-1,j+1]=1)and(pole[i-2,j+2]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-2,j+2]=2)and(pole[i-1,j+1]=2)then Begin x:=i;y:=j;prior:=5;end;
            If prior<4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-2,j+2]=1)and(cx=1)then Begin x:=i-1;y:=j+1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i-2,j+2]=2)and(cx=2)then Begin x:=i-1;y:=j+1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j+1]=1)and(pole[i-2,j+2]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j+1]=2)and(pole[i-2,j+2]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-1,j+1]=1)and(cx=1)then Begin x:=i-2;y:=j+2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j+1]=2)and(pole[i,j]=2)and(cx=2)then Begin x:=i-2;y:=j+2;prior:=4;end;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i-3;y:=j+3;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i-3;y:=j+3;Prior:=4;End;
                               If(Rigth=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j;prior:=4;End;
                               If(Rigth=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j;Prior:=4;End;

                                   If(left=0)and(pole[i-2,j+2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i-1;y:=j+1;Prior:=4;End;
                                   If(left=0)and(pole[i-2,j+2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i-1;y:=j+1;Prior:=4;End;

                             End;
      End;
     End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and((pole[x,y])=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;
  End;
Procedure Diag3(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum,t: byte;
  Begin
    For t:=n-5 downto 1 do
     Begin
        i:=3;j:=t+3;
      While i<=4 do
          Begin
            Inc(j);Inc(i);
            Rigth:=pole[i+1,j+1];Left:=pole[i-3,j-3];
            Sum:=pole[i,j]+pole[i-1,j-1]+pole[i-2,j-2];
            Proz:=pole[i,j]*pole[i-1,j-1]*pole[i-2,j-2];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j+1;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j+1;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i-3;y:=j-3;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i-3;y:=j-3;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-1,j-1]=1)then Begin x:=i-2;y:=j-2;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-1,j-1]=2)then Begin x:=i-2;y:=j-2;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-2,j-2]=1)and(pole[i-1,j-1]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-2,j-2]=2)and(pole[i-1,j-1]=2)then Begin x:=i;y:=j;prior:=5;end;

            If prior<4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-2,j-2]=1)and(cx=1)then Begin x:=i-1;y:=j-1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i-2,j-2]=2)and(cx=2)then Begin x:=i-1;y:=j-1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j-1]=1)and(pole[i-2,j-2]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j-1]=2)and(pole[i-2,j-2]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j-1]=1)and(pole[i,j]=1)and(cx=1)then Begin x:=i-2;y:=j-2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j-1]=2)and(pole[i,j]=2)and(cx=2)then Begin x:=i-2;y:=j-2;prior:=4;end;
                               If(Rigth=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j;prior:=4;End;
                               If(Rigth=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j;Prior:=4;End;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i-3;y:=j-3;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i-3;y:=j-3;Prior:=4;End;
                                          If(left=0)and(pole[i-2,j-2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i-1;y:=j-1;Prior:=4;End;
                                            If(left=0)and(pole[i-2,j-2]=0)and(pole[i,j]=0)and
                                (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i-1;y:=j-1;Prior:=4;End;
                             End;
      End;
     End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and((pole[x,y])=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;
  End;
Procedure Diag4(Var cx,x,y,prior : byte);Far;
 Var
    i,j,left,Rigth,Proz,Sum,t: byte;
  Begin
    For t:=5 to n do
     Begin
        i:=3;j:=t-2;
      While j<=n-1 do
          Begin
            Inc(j);Inc(i);
            Rigth:=pole[i+1,j+1];Left:=pole[i-3,j-3];
            Sum:=pole[i,j]+pole[i-1,j-1]+pole[i-2,j-2];
            Proz:=pole[i,j]*pole[i-1,j-1]*pole[i-2,j-2];
            If(left=0)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j+1;prior:=5;End;
            IF(left=0)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j+1;prior:=5;End;
            IF(left=2)and(rigth=0)and(sum=6)and(proz=8)then Begin x:=i+1;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=2)and(sum=6)and(proz=8)then Begin x:=i-3;y:=j-3;prior:=5;end;
            IF(left=1)and(rigth=0)and(sum=3)and(proz=1)then Begin x:=i+1;y:=j+1;prior:=5;end;
            IF(left=0)and(rigth=1)and(sum=3)and(proz=1)then Begin x:=i-3;y:=j-3;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=1)and(rigth=0)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-2,j-2]=1)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=0)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=2)and(rigth=0)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-2,j-2]=2)then Begin x:=i-1;y:=j-1;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i,j]=1)and(pole[i-1,j-1]=1)then Begin x:=i-2;y:=j-2;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i,j]=2)and(pole[i-1,j-1]=2)then Begin x:=i-2;y:=j-2;prior:=5;end;
            If(left=1)and(rigth=1)and(sum=2)and(proz=0)and
            (pole[i-2,j-2]=1)and(pole[i-1,j-1]=1)then Begin x:=i;y:=j;prior:=5;end;
            If(left=2)and(rigth=2)and(sum=4)and(proz=0)and
            (pole[i-2,j-2]=2)and(pole[i-1,j-1]=2)then Begin x:=i;y:=j;prior:=5;end;

            If prior<4 then Begin
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i,j]=1)and(pole[i-2,j-2]=1)and(cx=1)then Begin x:=i-1;y:=j-1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i,j]=2)and(pole[i-2,j-2]=2)and(cx=2)then Begin x:=i-1;y:=j-1;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j-1]=1)and(pole[i-2,j-2]=1)and(cx=1)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j-1]=2)and(pole[i-2,j-2]=2)and(cx=2)then Begin x:=i;y:=j;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=2)and(proz=0)and
                               (pole[i-1,j-1]=1)and(pole[i,j]=1)and(cx=1)then Begin x:=i-2;y:=j-2;prior:=4;end;
                               If(left=0)and(rigth=0)and(sum=4)and(proz=0)and
                               (pole[i-1,j-1]=2)and(pole[i,j]=2)and(cx=2)then Begin x:=i-2;y:=j-2;prior:=4;end;
                               If(Rigth=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i;y:=j;prior:=4;End;
                               If(Rigth=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i;y:=j;Prior:=4;End;
                               If(left=1)and(sum=0)and(proz=0)and(cx=1)then Begin x:=i-3;y:=j-3;prior:=4;End;
                               If(left=2)and(sum=0)and(proz=0)and(cx=2)then Begin x:=i-3;y:=j-3;Prior:=4;End;
                                          If(left=0)and(pole[i-2,j-2]=0)and(pole[i,j]=0)and
                               (Rigth=0)And(Sum=1)And(cx=1)And(proz=0) Then Begin x:=i-1;y:=j-1;Prior:=4;End;
                                            If(left=0)and(pole[i-2,j-2]=0)and(pole[i,j]=0)and
                                (Rigth=0)And(Sum=2)And(cx=2)And(proz=0) Then Begin x:=i-1;y:=j-1;Prior:=4;End;

                             End;
      End;
     End;
   If (x>=1)and(x<=n)and(y>=1)and(y<=n)and(pole[x,y]=0) Then
                                                             Else Begin
                                                             prior:=1;
                                                             x:=0;y:=0;
                                                             End;
  End;
Procedure Grisha1(cx : byte;Var x,y : byte);Far;
 Var prior : byte;
  Begin
   Prior:=1;
                                Gor11(cx,x,y,prior);
                                Ver11(cx,x,y,prior);
                                Diag1(cx,x,y,prior);
                                Diag2(cx,x,y,prior);
                                Diag3(cx,x,y,prior);
                                Diag4(cx,x,y,prior);
    If (Prior=1)and(x=0)and(y=0)then Begin
                                       randomize;
                                       repeat
                                       x:=random(n)+1;
                                       y:=random(n)+1;
                                       until (Pole[x,y] = 0)and(x>=1)and(x<=n)
                                       and(y>=1)and(y<=n);
                                     End;


  End;