#!/usr/bin/perl -w

use v5.38;
use experimental 'multidimensional';
$; = ';';

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

my @dirs = ([1, 0], [0, 1], [-1, 0], [0, -1]);

my %seen;
my @q = [-1, 0, 0];

my @slash = (3, 2, 1, 0);
my @bs    = (1, 0, 3, 2);

while (@q) {
	my ($x, $y, $dir) = @{ shift @q };
	my ($dx, $dy) = @{ $dirs[$dir] };

	$x += $dx; $y += $dy;
	next if $x < 0 || $y < 0 || $x > $xmax || $y > $ymax;

	next if $seen{$x,$y} && ($seen{$x,$y} & (1 << $dir));
	$seen{$x,$y} |= (1 << $dir);

	my $pt = $map[$y][$x];
	if ($pt eq '-' && ($dir == 1 || $dir == 3)) {
		push @q, [$x, $y, 0], [$x, $y, 2];
	} elsif ($pt eq '|' && ($dir == 0 || $dir == 2)) {
		push @q, [$x, $y, 1], [$x, $y, 3];
	} elsif ($pt eq '/') {
		push @q, [$x, $y, $slash[$dir]];
	} elsif ($pt eq '\\') {
		push @q, [$x, $y, $bs[$dir]];
	} else {
		push @q, [$x, $y, $dir];
	}
}

say scalar keys %seen;
