use strict; use warnings; use utf8; sub check { my $list = shift; my $index = shift; for my $n (1..2){ if($list->[$index] ne $list->[$index + $n]){ return undef; } } return 1; } sub solver { my $list = shift; return 'NA' if (scalar @$list) <= 1; my $max = (scalar @$list) - 2; for my $c (0..$max){ my $ans = ($list->[$c] eq 'O') ? 'East' : 'West'; if(check($list,$c)){ return $ans; } } return 'NA'; } chomp(my $input = ); my @data = split //, $input; print solver(\@data),"\n";