use strict;             
use warnings;

$_ = do { local $/; <DATA> };
s/./$&$&/g;             
my $w = /\n/ && $-[0];
my $wd = 3 * $w + 1;    
my $wr = 2 * $w + 8;    
my $wl = 2 * $w - 8;    
place($_, '00');
die "No solution\n";

sub place
  {
  (local $_, my $last) = @_;
  (my $new = $last)++;
  /$last.{10}(?=00)/g   and place( s/\G00/$new/r, $new ); 
  /(?=00.{10}$last)/g   and place( s/\G00/$new/r, $new ); 
  /$last.{$wd}(?=00)/gs and place( s/\G00/$new/r, $new ); 
  /(?=00.{$wd}$last)/gs and place( s/\G00/$new/r, $new ); 
  /$last.{$wr}(?=00)/gs and place( s/\G00/$new/r, $new ); 
  /(?=00.{$wr}$last)/gs and place( s/\G00/$new/r, $new ); 
  /$last.{$wl}(?=00)/gs and place( s/\G00/$new/r, $new ); 
  /(?=00.{$wl}$last)/gs and place( s/\G00/$new/r, $new ); 
  /00/ and return;
  print "Solution\n\n", s/  / /gr =~ s/0\B/ /gr;
  exit;
  }

__DATA__
. 0 0 . 0 0 .
0 0 0 0 0 0 0
0 0 0 0 0 0 0
. 0 0 0 0 0 .
. . 0 0 0 . .
. . . 0 . . .