Олимпиадный тренинг

Задача 38376. Complexity


Задача

Темы:
Fedot — designer, he is entrusted with the responsible work of artistic laying of black and white tiles. His last assignment — lay black and white tiles in a square n × n.

Fedot loves his job and always carefully prepares for each project. Fedot believes that two squares are similar if one of them can be obtained from the other several times by replacing the colors in some row or column with opposite ones.
These squares are all similar and no other is similar
Fedot noticed that clients never look at the whole work, usually their field of vision is limited to the square k × k. To evaluate the sketches, he introduced a special value — complexity. It is equal to the number of pairs of dissimilar squares k × k that occur in the picture.

By trial and error, Fedot found that clients like paintings of a certain complexity. Too much complexity is like chaos, and too little is boring, Fedot believes.

Before laying the tiles, Fedot prepared several sketches. Help Fedot calculate their complexity.

Input
The first line of the input file contains two integers n and k (1 ≤ k ≤ n ≤ 500). The next n lines contain a description of the sketch. Each of them has length n and consists of the characters b and w, which correspond to the white and black colors of the tiles.

Imprint
In the first line of the output file print a single integer q — the complexity of the picture.
Examples
# Input Output
1 2 1
bw
wb
0
2 3 2
bwb
wbb
bbw
3