Codeforces Round 662 (Div. 2)
D
Rarity and New Dress
Codeforces
2100
原题
← CE1 →
翻译中…

Carousel Boutique is busy again! Rarity has decided to visit the pony ball and she surely needs a new dress, because going out in the same dress several times is a sign of bad manners. First of all, she needs a dress pattern, which she is going to cut out from the rectangular piece of the multicolored fabric.

翻译中…

The piece of the multicolored fabric consists of $n \times m$ separate square scraps. Since Rarity likes dresses in style, a dress pattern must only include scraps sharing the same color. A dress pattern must be the square, and since Rarity is fond of rhombuses, the sides of a pattern must form a $45^{\circ}$ angle with sides of a piece of fabric (that way it will be resembling the traditional picture of a rhombus).

翻译中…

Examples of proper dress patterns: image Examples of improper dress patterns: image The first one consists of multi-colored scraps, the second one goes beyond the bounds of the piece of fabric, the third one is not a square with sides forming a $45^{\circ}$ angle with sides of the piece of fabric.

翻译中…

Rarity wonders how many ways to cut out a dress pattern that satisfies all the conditions that do exist. Please help her and satisfy her curiosity so she can continue working on her new masterpiece!

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2000$). Each of the next $n$ lines contains $m$ characters: lowercase English letters, the $j$-th of which corresponds to scrap in the current line and in the $j$-th column. Scraps having the same letter share the same color, scraps having different letters have different colors.

翻译中…

Output

翻译中…

Print a single integer: the number of ways to cut out a dress pattern to satisfy all of Rarity's conditions.

翻译中…

Note

翻译中…

In the first example, all the dress patterns of size $1$ and one of size $2$ are satisfactory.

翻译中…

In the second example, only the dress patterns of size $1$ are satisfactory.

翻译中…

样例

Input #1
3 3
aaa
aaa
aaa
Output #1
10
InputCopy OutputCopy
Input #2
3 4
abab
baba
abab
Output #2
12
InputCopy OutputCopy
Input #3
5 5
zbacg
baaac
aaaaa
eaaad
weadd
Output #3
31
InputCopy OutputCopy
题目信息
题号
1393D
时间限制
1 s
内存限制
256 MB
标签
DFS 及类似
动态规划
模拟
最短路

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。