#!/usr/bin/perl -w

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

my @m = map { chomp; [ split // ] } <>;
my $xmax = @{ $m[0] };
my $ymax = @m;

my $count;
for my $x (1 .. $xmax-2) {
for my $y (1 .. $ymax-2) {
	my $h = $m[$y][$x];
	say $h;
	my $visible = 1;
	for my $dx (0 .. $x-1) {
		$visible = 0 if $m[$y][$dx] >= $h;
	}
	if ($visible) {
		$count++; next;
	}
	$visible = 1;
	say " $visible";
	for my $dx ($x+1 .. $xmax-1) {
		$visible = 0 if $m[$y][$dx] >= $h;
	}
	if ($visible) {
		$count++; next;
	}
	$visible = 1;
	say " $visible";
	for my $dy (0 .. $y-1) {
		$visible = 0 if $m[$dy][$x] >= $h;
	}
	if ($visible) {
		$count++; next;
	}
	$visible = 1;
	say " $visible";
	for my $dy ($y+1 .. $ymax-1) {
		$visible = 0 if $m[$dy][$x] >= $h;
	}
	if ($visible) {
		$count++; next;
	}
	$count++ if $visible;
} }

say $count + 2* $xmax + 2*$ymax-4;
