#!/usr/bin/perl
use v5.35.0;
# Slurp the whole map as a single string, regularize its
# line terminators, work out how big it is, and set up deltas
# for moving one step in each of the four available directions
local $/ = undef;
local $_ = <>;
s/\v+/\n/g;
my $row = 1 + index $_, "\n";
my $len = length;
my @dp = (1, -$row, -1, $row);
# Find the guard's starting position and direction
/([>^^^