#!/afs/athena/contrib/perl/p

$first = (<>);
$dims = (<>);
$third = (<>);
$|=1;
($rows, $cols) = split(' ', $dims);

@colorlist=(' ','.', ':', ';', '/', '<', '=', 'X', '*', '&', '#');
while(<>){
    $img .= $_;
}

while(length($img)){
    $pix = substr($img, 0, 3);
    $img = substr($img, 3);
    print &color($pix);
    $atcol++;
    if($atcol >= $rows) {
	$atcol=0;print("\n");
    }
}


sub color {
    local($p) = @_;

    return $colored{$p} if $colored{$p};
    $colored{$p} = $colorlist[( (ord(substr($p,0,1))+(ord($p,1,1))+(ord($p,2,1)))/76.5)];
}
