Fruit Boats

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.5s
Memory limit: 10M

Author:
Problem type

In the land of TSSOJ, there are certain fruits that are banned for being too fruity. jsumabat is a fruit smuggler who smuggles illegal fruits into TSSOJ by plane. One day, one of his fruit shipments containing apples, bananas and coconuts is intercepted and his plane is destroyed while flying over a square shaped lake. All the fruit falls out, but because of the way the fruit is stored, they land neatly next to each other in a grid formation. jsumabat sends two boats to recover as much of the fruit as he can. Unfortunately, most of the island is already under surveillance by the TSSOJ government. jsumabat decides that the best way to recover as much fruit as possible is the send the boats in an X formation across the river, collecting any fruit they encounter.
The path of the boats is visualized in the following image:
If this image doesn't show you're outta luck.
Your task is to determine how much of each fruit will be collected.

Input Specification

The first line of input, w (3 \le w \le 2999) represents the number of fruit from one end of the lake to directly across on the other. In other words, the lake can be split into a grid of size wxw with a fruit in each square. It is guaranteed that w will be odd.
The next w lines will contain w space separated letters representing the type of fruit that is in each square. A for apple, B for banana and C for coconut.

Output Specification

Output 3 integers, each on a new line representing the number of each type of fruit collected, in the order of apples, bananas, coconuts.

Subtask 1

For 5/7 of the points, w \le 299.

Sample Input

5
A A B A C
B A C C A
C C B A B
C A C B C
A B A A A

Sample Output

5
2
2

Explanation for Sample Input

The path of the fruit boats is visualized in the following image:
RIP
In total, the boats will encounter 5 apples, 2 bananas, and 2 coconuts.


Comments

There are no comments at the moment.