Apple is a very careless girl. One day, the teacher leaves her a problem which has stuck her for a long while. Apple turns to you with this problem: counting the number of the isosceles right triangles composed with various letters in a capital letters matrix. And there are only two forms of the isosceles right triangle in the matrix:
Form 1:
Two right sides are both parallel with the sides of the matrix. e.g.
Form 2:
The hypotenuse is parallel with one side of the matrix. e.g.
Notice that all the isosceles right triangles should contain more than or equal to three letters.