#P1557. Far Relative’s Birthday Cake

Far Relative’s Birthday Cake

题目描述

Door's family is going to celebrate Famil Door's birthday party. They love Famil Door so much that they are planning to make his birthday cake weird!

The cake is an n×nn \times n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Door's family is wondering what the amount of happiness is going to be.

Please note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column.

中文题目大意

Polycarp的远房亲戚过生日,他准备了一个n×nn×n的方形蛋糕。蛋糕被切成n2n^2个小方块,每个方块要么有樱桃(用C’C’表示),要么没有(用.’.’表示)。如果两个樱桃在同一行或同一列,它们就会产生”幸福”。求总共有多少对樱桃会产生幸福?

数据范围:1≤n≤100

输入

In the first line of the input, you are given a single integer nn (1n1001 \leq n \leq 100) — the length of the side of the cake.

Then follow nn lines, each containing nn characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'.

输出

Print the value of Famil Door's happiness, i.e., the number of pairs of chocolate pieces that share the same row or the same column.

样例

3
.CC
C..
C.C
4
4
CC..
C..C
.CC.
.CC.
9

提示

Explanation

If we number rows from top to bottom and columns from left to right, then the pieces that share the same row are:

  1. (1, 2) and (1, 3)
  2. (3, 1) and (3, 3)

The pieces that share the same column are:

  1. (2, 1) and (3, 1)
  2. (1, 3) and (3, 3)