#P11788. Brave Bitaro's Spell Power
Brave Bitaro's Spell Power
Brave Bitaro's Spell Power
Brave Bitaro is facing a demon. To attack the demon, Bitaro places one of three magical items — denoted by J
, O
, and I
— on each cell of an $H\times W$ grid. The cell in the $i$-th row and $j$-th column (with $1 \le i \le H$ and $1 \le j \le W$) is denoted by $(i,j)$.
Next, Bitaro casts a spell whose power is determined by the arrangement of items on the grid. Specifically, the power of the spell is equal to the number of ordered quadruples $(i, j, k, l)$ satisfying $$1 \le i < k \le H, \quad 1 \le j < l \le W,$$ with the following conditions:
- Cell $(i,j)$ contains
J
. - Cell $(i,l)$ contains
O
. - Cell $(k,j)$ contains
I
.
Your task is to compute and output the power of Bitaro's spell.
inputFormat
The first line of input contains two integers $H$ and $W$, denoting the number of rows and columns of the grid respectively.
This is followed by $H$ lines, each containing a string of length $W$. Each character in the string is either J
, O
, or I
, representing the magical item placed in that cell.
outputFormat
Output a single integer representing the power of the spell, i.e. the number of quadruples $(i,j,k,l)$ satisfying the given conditions.
sample
2 2
JO
IJ
1
</p>