Linguistic Labyrinth
문제
It is the 25th of December, 2025. As a Christmas tradition, you gather a group of friends to solve a puzzle. Among your friends are wordcels and shape rotators, who are respectively better at thinking with words and with mental images. This puzzle challenges even the smartest wordcel and the most brilliant shape rotator:
There is a -dimensional grid with points at all integer coordinates with , and each point has a label associated with it, which is either 'B', 'A', 'P', or 'C'. In this grid, you need to find occurrences of the curly word "BAPC". A curly word "BAPC" is a collection of four points in the grid such that:
- The labels spell out "
BAPC" (in this order). - The angle that the triplet "
BAP" makes is degrees: the vectors fromBAand fromAPform a -degree angle. - The angle that the triplet "
APC" makes is degrees: the vectors fromAPand fromPCform a -degree angle.
Note that the two angles do not need to be axis-aligned. As an example, see the third sample case, visualized in Figure L.1.
How many occurrences of the curly word "BAPC" are in the given grid?
입력
The input consists of:
- One line with an integer (), the size of the grid.
- blocks of lines. Each block of lines consists of:
- One line with a hyphen (
-), to make the input more human-readable. - lines with characters, each character being either '
B', 'A', 'P', or 'C', representing all labels of one horizontal layer of the -dimensional grid.
- One line with a hyphen (
출력
Output the number of curly words "BAPC" in the -dimensional grid.
힌트
Figure L.1: Visualization of the third sample input. In this grid, there are two curly words "BAPC", using the highlighted letters.
예제
예제 1
1 - B
0
예제 2
2 - PA PB - CC PB
2
예제 3
3 - BBB BCB BCB - BBC CBA BBB - BBB BPB BBB
2