fn main [ var lines := list_break_to_lines(read_lazy(h[0])); lines := list_flatten(lines); const x := len(lines[0]); const y := len(lines); var a := list_to_array([x, y], list_join(lines, "")); a := array_flatten(a); var found := 0; for j := 1 to y - 1 do [ for i := 1 to x - 1 do [ if a[i, j] <> 'A' then continue; var c := [ a[i - 1, j - 1], a[i - 1, j + 1], a[i + 1, j - 1], a[i + 1, j + 1] ]; if c[0] = c[3] or c[1] = c[2] then continue; for q := 0 to 4 do if c[q] <> 'M', c[q] <> 'S' then goto cont; found += 1; cont: ] ] write(h[1], ntos(found) + nl); ]