#!/usr/bin/perl -w

use v5.36;
use strict;
use experimental 'multidimensional';

my @map = map { chomp; [ split // ] } <>;

my $rows = @map;
my $cols = @{ $map[0] };

my %total;
for (1..10) {
	%total = ();
	my @nmap;
	for my $y (0 .. $rows-1) {
		my @row;
		for my $x (0 .. $cols-1) {
			my %count = map { $_ => 0 } ('#', '|', '.');
			for my $neigh ([-1,-1], [0, -1], [1, -1],
				[-1, 0], [1, 0],
				[-1, 1], [0, 1], [1, 1]) {
				my $nx = $x + $neigh->[0];
				my $ny = $y + $neigh->[1];
				next if $nx < 0 || $nx >= $cols
					|| $ny < 0 || $ny >= $cols;
				$count{$map[$ny][$nx]}++;
			}
			my $self = $map[$y][$x];
			if ($self eq '.' && $count{'|'} >= 3) {
				$self = '|';
			} elsif ($self eq '|' && $count{'#'} >= 3) {
				$self = '#';
			} elsif ($self eq '#' &&
				($count{'#'} == 0 || $count{'|'} == 0)) {
				$self = '.';
			}
			push @row, $self;
			$total{$self}++;
		}
		push @nmap, \@row;
	}
	@map = @nmap;
	say map { join('', @$_, "\n") } @map;
}

say $total{"#"} * $total{'|'};
