CF1393D.Rarity and New Dress

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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×mn \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 4545^{\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: Examples of improper dress patterns: 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 4545^{\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!

输入格式

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

输出格式

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

输入输出样例

  • 输入#1

    3 3
    aaa
    aaa
    aaa

    输出#1

    10
  • 输入#2

    3 4
    abab
    baba
    abab

    输出#2

    12
  • 输入#3

    5 5
    zbacg
    baaac
    aaaaa
    eaaad
    weadd

    输出#3

    31

说明/提示

In the first example, all the dress patterns of size 11 and one of size 22 are satisfactory.

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

首页