program Cube; {$S-,G+} var a: array[0..101, 0..101] of Integer; n, c: Integer; t: LongInt absolute $40:$6C; t0: LongInt; procedure WriteTime; begin Writeln; Writeln('t = ', (t - t0) * 65536 / 1193180:0:2, ' s'); Writeln; end; procedure Rec(i, j, s: Integer); begin if a[i, j] <> 0 then Exit; Inc(c); a[i, j] := c; if (i = 1) and (j = n) and (c = n * n) then begin for i := 1 to n do begin for j := 1 to n do Write(a[i, j]: 3); Writeln; end; WriteTime; Halt; end; case s of 0: begin Rec(i - 1, j, 1); Rec(i, j - 1, 2); Rec(i + 1, j, 3); Rec(i, j + 1, 4); end; 1: begin Rec(i + 1, j, 0); Rec(i, j + 1, 1); Rec(i, j - 1, 1); end; 2: begin Rec(i, j + 1, 0); Rec(i + 1, j, 2); Rec(i - 1, j, 2); end; 3: begin Rec(i - 1, j, 0); Rec(i, j + 1, 3); Rec(i, j - 1, 3); end; 4: begin Rec(i, j - 1, 0); Rec(i + 1, j, 4); Rec(i - 1, j, 4); end; end; Dec(c); a[i, j] := 0; end; var i: Integer; begin Write('n>'); Readln(n); Writeln; t0 := t; for i := 0 to n + 1 do begin a[i, 0] := -1; a[i, n + 1] := -1; a[0, i] := -1; a[n + 1, i] := -1; end; c := 0; Rec(1, 1, 0); Writeln('No solution for n = ', n); WriteTime; end.