#!/usr/bin/perl -w

use v5.38;

my @gxys;
my $y = 0;
while (<>) {
	while (/#/g) {
		my $x = pos()-1;
		push @gxys, [ $x, $y ];
	}
	$y++;
}

my %x_gxy = map { $_->[0] => 1 } @gxys;
my %y_gxy = map { $_->[1] => 1 } @gxys;

my $steps;
for my $i (0 .. $#gxys-1) {
	for my $j ($i .. $#gxys) {
		my ($x1, $y1) = $gxys[$i]->@*;
		my ($x2, $y2) = $gxys[$j]->@*;

		($x1, $x2) = ($x2, $x1) if $x1 > $x2;
		for ($x1+1 .. $x2) {
			$steps += $x_gxy{$_} ? 1 : 2;
		}

		($y1, $y2) = ($y2, $y1) if $y1 > $y2;
		for ($y1+1 .. $y2) {
			$steps += $y_gxy{$_} ? 1 : 2;
		}
	}
}

say $steps;
