#P9939. Cow Meet-Up
Cow Meet-Up
Cow Meet-Up
Bessie, a busy computer science graduate student, wants to make friends. Farmer John has prepared a huge pasture represented as an \( n \times n \) grid. Each cell of the grid is marked with one of the following characters:
- C: a cell containing a cow,
- G: a cell with grass,
- .: an empty cell.
Two cows can become friends if they both are adjacent (up, down, left, or right) to the same grass cell. When they meet, they use that grass cell (which then becomes unavailable for future meetings). Also, the same pair of cows can only meet once, even if they share multiple adjacent grass cells.
In mathematical terms, if a grass cell at position \( (i,j) \) has a set \( S \) of adjacent cows, then any unordered pair \( (a,b) \) with \( a,b \in S,\, a \neq b \) can contribute at most one friendship. Your task is to compute the maximum number of distinct friendships that can be formed.
inputFormat
The first line contains an integer \( n \) representing the size of the grid. Each of the next \( n \) lines contains a string of length \( n \), consisting solely of the characters 'C', 'G', and '.'.
outputFormat
Output a single integer, the maximum number of friendships that can be formed.
sample
3
.C.
GGG
.C.
1