409255: GYM103469 G Glory Graph

Memory Limit:0 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

G. Glory Graphtime limit per test3 secondsmemory limit per test512 mebibytesinputstandard inputoutputstandard output

You are given a complete undirected graph on $$$n$$$ vertices, each edge is colored blue or yellow. Anton likes a subgraph on $$$4$$$ vertices if, among its $$$6$$$ edges, $$$5$$$ edges have one color, and the $$$6$$$-th edge has another color. Yahor likes a subgraph on $$$4$$$ vertices if $$$3$$$ of its edges are yellow, $$$3$$$ are blue, and no $$$3$$$ vertices form a triangle with edges of the same color.

On the image below, on the left, you can see examples of graphs Anton likes. On the right, there are examples of graphs Yahor likes.

Let $$$A$$$ be the number of subgraphs Anton likes, and $$$Y$$$ be the number of subgraphs Yahor likes. They want to know who likes more subgraphs. To help them, find the value $$$Y - A$$$.

Input

The first line of the input contains a single integer $$$n$$$ ($$$4 \le n \le 2000$$$), the number of vertices in the graph.

The $$$i$$$-th of the next $$$i$$$ lines contains a string $$$s_i$$$ of length $$$n$$$.

It is guaranteed that:

  • For every $$$i$$$ from $$$1$$$ to $$$n$$$, the $$$i$$$-th character of $$$s_i$$$ is '-'
  • For every $$$i \neq j$$$, the $$$j$$$-th character of $$$s_i$$$ is either 'Y' or 'B', where' Y' shows that the edge between vertices $$$i$$$ and $$$j$$$ is yellow, and 'B' shows that it is blue
  • For every $$$i \neq j$$$, the $$$j$$$-th character of $$$s_i$$$ is equal to the $$$i$$$-th character of $$$s_j$$$
Output

Output a single integer: the value $$$Y - A$$$.

ExamplesInput
5
-YBYB
Y-BBB
BB-BY
YBB-Y
BBYY-
Output
2
Input
6
-YYYYY
Y-YYBB
YY-YYY
YYY-YB
YBYY-Y
YBYBY-
Output
-6
Note

In the first example, Yahor likes subgraphs on vertices $$$1, 2, 4, 5$$$ and on vertices $$$1, 3, 4, 5$$$. Anton doesn't like any subgraphs there.

加入题单

算法标签: