#!/usr/bin/perl

$S = 5;  

our ($X, $Y);
my @canvas = ("0" x $width) x $height;
my %op = (
    " " => sub { 1 },
    "#" => sub { 0 },

    "1" => sub { $X < $Y },
    "2" => sub { $X > $Y },
    "3" => sub { 50 - $X - $Y > 0 },
    "4" => sub { 50 - $X - $Y < 0 },
    );

my ($x, $y) = (0,0);
while (<>) {
    chomp;
    for my $c (split //, $_) {
	my $p = patch($op->{$c});
	add_patch($p, $x, $y);
    }
    $y++; $x = 0;
    $height = max($y, $height);
}
output();

sub max {
    my ($a, $b) = @_;
    $a > $b ? $a : $b;
}

my %patch;
sub patch {
    my ($op) = @_;
    return $patch{$c} if $patch{$c};
    my @canvas = ("x" x $S) x $S;
    
    for $X (0 .. $S-1) {
	for $Y (0 .. $S-1) {
	    substr($canvas[$y], $x, 1, $op->());
	}
    }
    return $patch{$c} = \@canvas;
}

sub add_patch {
    my ($p, $x, $y) = @_;
    
}

sub output {
    print "P1\n$width $height\n", join ("\n", @canvas, "");
}
