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.


-----Examples-----
Input
3 3
aaa
aaa
aaa

Output
10

Input
3 4
abab
baba
abab

Output
12

Input
5 5
zbacg
baaac
aaaaa
eaaad
weadd

Output
31



-----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.

Difficulty: MEDIUM

Solutions:
import sys
input = sys.stdin.buffer.readline
(n, m) = map(int, input().split())
dress = [input().rstrip() for i in range(n)]
dist = [[min(i, m - 1 - i, j, n - 1 - j) for i in range(m)] for j in range(n)]
move = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		for (nx, ny) in move:
			if dress[i + nx][j + ny] != dress[i][j]:
				dist[i][j] = 0
for j in range(m):
	for i in range(1, n):
		dist[i][j] = min(dist[i - 1][j] + 1, dist[i][j])
for j in range(m):
	for i in range(n - 2, -1, -1):
		dist[i][j] = min(dist[i + 1][j] + 1, dist[i][j])
for i in range(n):
	for j in range(1, m):
		dist[i][j] = min(dist[i][j - 1] + 1, dist[i][j])
ans = n * m
for i in range(n):
	for j in range(m - 2, -1, -1):
		dist[i][j] = min(dist[i][j + 1] + 1, dist[i][j])
		ans += dist[i][j]
print(ans)


(n, m) = map(int, input().split())
mat = []
for r in range(n):
	mat.append(input())
dp = [[1 for i in range(m)] for i in range(n)]
out = 2 * m
if n < 2:
	out = m
for r in range(2, n):
	out += 2
	for c in range(1, m - 1):
		if mat[r][c] == mat[r - 1][c] == mat[r - 1][c - 1] == mat[r - 1][c + 1] == mat[r - 2][c]:
			dp[r][c] += min(dp[r - 1][c + 1], dp[r - 1][c - 1], dp[r - 1][c], dp[r - 2][c])
		out += dp[r][c]
print(out)


def rainy(S, M, MASTER):
	MAP = [[1 for i in range(M)] for j in range(S)]
	for i in range(2, S):
		for j in range(1, M - 1):
			if MASTER[i][j] == MASTER[i - 1][j - 1] and MASTER[i - 1][j - 1] == MASTER[i - 2][j] and (MASTER[i - 2][j] == MASTER[i - 1][j + 1]) and (MASTER[i - 1][j + 1] == MASTER[i - 1][j]):
				MAP[i][j] = min(MAP[i - 1][j - 1], MAP[i - 2][j], MAP[i - 1][j + 1]) + 1
	ans = 0
	for i in MAP:
		for j in i:
			ans += j
	return ans
(S, M) = map(int, input().split())
MASTER = []
for i in range(S):
	MASTER.append(input())
print(rainy(S, M, MASTER))


from collections import *
import sys

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
(n, m) = rl()
aa = []
for i in range(n):
	aa.append(input())
dp = [[1] * m for _ in range(n)]
if n == 1:
	print(1)
else:
	ans = 2 * m + 2 * (n - 2)
	for i in range(2, n):
		for j in range(1, m - 1):
			if aa[i][j] == aa[i - 1][j] == aa[i - 1][j - 1] == aa[i - 1][j + 1] == aa[i - 2][j]:
				dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 2][j]) + 1
				ans += dp[i][j]
			else:
				ans += 1
	print(ans)


(n, m) = map(int, input().split())
g = [[1] * m for _ in range(n)]
cc = [input() for _ in range(n)]
ans = 0
for (r, row) in enumerate(cc):
	for (c, x) in enumerate(row):
		if r >= 2 and c >= 1 and (c + 1 < m):
			if x == cc[r - 1][c] == cc[r - 2][c] == cc[r - 1][c - 1] == cc[r - 1][c + 1]:
				g[r][c] = min(g[r - 2][c], g[r - 1][c - 1], g[r - 1][c + 1]) + 1
		ans += g[r][c]
print(ans)


import sys
input = sys.stdin.readline
(n, m) = list(map(int, input().split()))
grid = []
for i in range(n):
	grid.append(input().rstrip())
(n, m) = (m, n)
(A, B, C, D) = ([[1] * n for j in range(m)], [[1] * n for j in range(m)], [[1] * n for j in range(m)], [[1] * n for j in range(m)])
for i in range(1, m):
	for j in range(1, n):
		if grid[i][j] == grid[i - 1][j] and grid[i][j] == grid[i][j - 1]:
			A[i][j] = 1 + min(A[i - 1][j], A[i][j - 1])
for i in range(1, m):
	for j in range(n - 2, 0, -1):
		if grid[i][j] == grid[i - 1][j] and grid[i][j] == grid[i][j + 1]:
			B[i][j] = 1 + min(B[i - 1][j], B[i][j + 1])
for i in range(m - 2, 0, -1):
	for j in range(1, n):
		if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i][j - 1]:
			C[i][j] = 1 + min(C[i + 1][j], C[i][j - 1])
for i in range(m - 2, 0, -1):
	for j in range(n - 2, 0, -1):
		if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i][j + 1]:
			D[i][j] = 1 + min(D[i + 1][j], D[i][j + 1])
ans = 0
for i in range(m):
	for j in range(n):
		ans += min(A[i][j], B[i][j], C[i][j], D[i][j])
print(ans)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def solve():
	dd = [[1] * w for _ in range(h)]
	for j in range(w):
		for i in range(1, h):
			if aa[i][j] == aa[i - 1][j]:
				dd[i][j] += dd[i - 1][j]
	uu = [[1] * w for _ in range(h)]
	for j in range(w):
		for i in range(h - 2, -1, -1):
			if aa[i][j] == aa[i + 1][j]:
				uu[i][j] += uu[i + 1][j]
	ll = [[1] * w for _ in range(h)]
	for i in range(h):
		for j in range(1, w):
			if aa[i][j] == aa[i][j - 1]:
				ll[i][j] = min(dd[i][j], uu[i][j], ll[i][j - 1] + 1)
	rr = [[1] * w for _ in range(h)]
	for i in range(h):
		for j in range(w - 2, -1, -1):
			if aa[i][j] == aa[i][j + 1]:
				rr[i][j] = min(dd[i][j], uu[i][j], rr[i][j + 1] + 1)
	ans = 0
	for i in range(h):
		for j in range(w):
			ans += min(ll[i][j], rr[i][j])
	print(ans)
(h, w) = MI()
aa = [SI() for _ in range(h)]
solve()


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
(n, m) = MI()
l = []
for i in range(n):
	l.append(list(SI()))
dp = []
for i in range(n):
	dp.append([1] * m)
ans = 0
for i in range(n):
	for j in range(m):
		if i > 1 and j > 0 and (j < m - 1):
			if l[i - 1][j - 1] == l[i - 2][j] == l[i - 1][j] == l[i - 1][j + 1] == l[i][j]:
				dp[i][j] = min(dp[i - 1][j - 1], dp[i - 2][j], dp[i - 1][j], dp[i - 1][j + 1]) + 1
		ans += dp[i][j]
print(ans)


(n, m) = map(int, input().split())
mat = []
for i in range(n):
	mat.append(list(input()))
curr = [[1 for i in range(m)] for j in range(n)]
for i in range(2, n):
	for j in range(1, m - 1):
		if mat[i][j] == mat[i - 1][j - 1] == mat[i - 2][j] == mat[i - 1][j + 1] == mat[i - 1][j]:
			curr[i][j] = min(curr[i - 1][j - 1], curr[i - 2][j], curr[i - 1][j + 1]) + 1
ans = 0
for i in curr:
	for j in i:
		ans += j
print(ans)


from sys import stdin, stdout

def rarity_and_new_dress(n, m, s_a):
	dp = [[1 for j in range(m)] for i in range(n)]
	res = 0
	for i in range(n):
		for j in range(m):
			if i > 1 and 0 < j < m - 1 and (s_a[i][j] == s_a[i - 1][j - 1] == s_a[i - 1][j] == s_a[i - 1][j + 1] == s_a[i - 2][j]):
				dp[i][j] += min(dp[i - 1][j - 1], dp[i - 1][j], dp[i - 1][j + 1], dp[i - 2][j])
			res += dp[i][j]
	return res
(n, m) = map(int, stdin.readline().split())
s_a = []
for _ in range(n):
	s_a.append(stdin.readline().strip())
ans = rarity_and_new_dress(n, m, s_a)
stdout.write(str(ans) + '\n')


import sys
input = sys.stdin.readline
(N, M) = map(int, input().split())
a = [0] * (N * M)
dp = [1] * (N * M)
dx = [0, 0, -1, 1]
dy = [-1, -2, -1, -1]
res = 0
for i in range(N):
	t = list(input())[:-1]
	for j in range(M):
		a[i * M + j] = ord(t[j])
		for k in range(4):
			y = i + dy[k]
			x = j + dx[k]
			if y in range(N) and x in range(M):
				if a[i * M + j] != a[y * M + x]:
					break
			else:
				break
		else:
			dp[i * M + j] = min(dp[(i - 2) * M + j], dp[(i - 1) * M + j - 1], dp[(i - 1) * M + j + 1], dp[(i - 1) * M + j]) + 1
		res += dp[i * M + j]
print(res)


mod = 10 ** 9 + 7
s = []
f = []
ans = 0
(n, m) = map(int, input().split())

def calc(x, y):
	if f[x][y] != -1:
		return f[x][y]
	elif x <= 1 or y == 0 or y == m - 1:
		f[x][y] = 1
	else:
		f[x][y] = 1
		if s[x][y] != s[x - 2][y] or s[x][y] != s[x - 1][y] or s[x][y] != s[x - 1][y - 1] or (s[x][y] != s[x - 1][y + 1]):
			f[x][y] = 1
		else:
			f[x][y] = min(calc(x - 1, y), calc(i - 2, y), calc(x - 1, y - 1), calc(x - 1, y + 1)) + 1
	return f[x][y]
for i in range(n):
	t = input()
	s.append(t)
	tmp = []
	for j in range(m):
		tmp.append(-1)
	f.append(tmp)
for i in range(n):
	for j in range(m):
		ans += calc(i, j)
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
b = []
for i in range(n):
	s = input()
	c = []
	for j in s:
		c.append(j)
	b.append(c)
ans = 0
dp = [[0] * m for i in range(n)]
for i in range(n):
	for j in range(m):
		if i == 0:
			ans += 1
			dp[i][j] = 1
		elif j == 0:
			dp[i][j] = 1
			ans += 1
		elif j == m - 1:
			dp[i][j] = 1
			ans += 1
for i in range(1, n):
	for j in range(1, m - 1):
		if b[i - 1][j - 1] == b[i][j] and b[i][j] == b[i - 1][j] and (b[i - 1][j + 1] == b[i][j]):
			res = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i - 1][j + 1])
			dp[i][j] = res
			if i - res - 1 >= 0 and b[i - res - 1][j] == b[i][j]:
				dp[i][j] = res + 2
		else:
			dp[i][j] = 1
		ans += (dp[i][j] + 1) // 2
print(ans)


def getlist():
	return list(map(int, input().split()))

def main():
	(N, M) = getlist()
	L = []
	table1 = [0] * (M * N)
	table2 = [0] * (M * N)
	table3 = [0] * (M * N)
	table4 = [0] * (M * N)
	for i in range(N):
		l = [ord(j) for j in list(input())]
		L.append(l)
	for i in range(N - 2, -1, -1):
		for j in range(M - 2, -1, -1):
			if L[i][j] == L[i + 1][j] == L[i][j + 1]:
				table1[M * i + j] = 1 + min(table1[M * i + j + 1], table1[M * (i + 1) + j])
	for i in range(1, N):
		for j in range(M - 2, -1, -1):
			if L[i][j] == L[i - 1][j] == L[i][j + 1]:
				table2[M * i + j] = 1 + min(table2[M * i + j + 1], table2[M * (i - 1) + j])
	for i in range(1, N):
		for j in range(1, M):
			if L[i][j] == L[i - 1][j] == L[i][j - 1]:
				table3[M * i + j] = 1 + min(table3[M * i + j - 1], table3[M * (i - 1) + j])
	for i in range(N - 2, -1, -1):
		for j in range(1, M):
			if L[i][j] == L[i + 1][j] == L[i][j - 1]:
				table4[M * i + j] = 1 + min(table4[M * i + j - 1], table4[M * (i + 1) + j])
	ans = N * M
	for i in range(N):
		for j in range(M):
			ans += min(table1[M * i + j], table2[M * i + j], table3[M * i + j], table4[M * i + j])
	print(ans)
main()


import sys
input = sys.stdin.readline
(n, m) = [int(x) for x in input().split()]
arr = []
for _ in range(n):
	arr.append(input())
dp = [[1 for _ in range(m)] for __ in range(n)]
cnts = 0
for i in range(n):
	for j in range(m):
		if i >= 2 and 1 <= j <= m - 2 and (arr[i][j] == arr[i - 1][j - 1] == arr[i - 1][j + 1] == arr[i - 2][j] == arr[i - 1][j]):
			dp[i][j] = 1 + min(dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 2][j])
		cnts += dp[i][j]
print(cnts)


from sys import stdin
(n, m) = [int(x.strip()) for x in stdin.readline().split()]
a = [line.strip() for line in stdin.readlines()]
dp = [[0] * m for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(m):
		if i < 2 or j == 0 or j == m - 1:
			dp[i][j] = 1
		elif a[i][j] != a[i - 1][j] or a[i][j] != a[i - 2][j] or a[i][j] != a[i - 1][j - 1] or (a[i][j] != a[i - 1][j + 1]):
			dp[i][j] = 1
		else:
			dp[i][j] = min(dp[i - 1][j], dp[i - 2][j], dp[i - 1][j - 1], dp[i - 1][j + 1]) + 1
		ans += dp[i][j]
print(ans)


from sys import stdin, gettrace
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():
	(n, m) = map(int, inputi().split())
	fff = []
	for _ in range(n):
		fff.append(list(input()))
	mw = []
	for i in range(n):
		mw.append([1])
		for j in range(1, m):
			if fff[i][j] != fff[i][j - 1]:
				mw[-1].append(1)
			else:
				mw[-1].append(mw[-1][-1] + 1)
	mc = [[1] * m for _ in range(n)]
	for i in range(1, n - 1):
		mc[i][0] = 1
		for j in range(1, m):
			if fff[i - 1][j - 1] != fff[i][j]:
				mc[i][j] = 1
			else:
				mc[i][j] = min((mw[i][j] + 1) // 2, mc[i - 1][j - 1] + 1)
	for i in range(n - 2, 0, -1):
		for j in range(1, m):
			if fff[i + 1][j - 1] != fff[i][j]:
				mc[i][j] = 1
			else:
				mc[i][j] = min(mc[i][j], mc[i + 1][j - 1] + 1)
	print(sum(map(sum, mc)))
main()


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(n, m, s):
	d = (min(n, m) + 1) // 2
	dp = [[1] * m for i in range(n)]
	for i in range(n - 3, -1, -1):
		for j in range(1, m - 1):
			if s[i][j] != s[i + 1][j - 1] or s[i][j] != s[i + 1][j + 1] or s[i][j] != s[i + 1][j] or (s[i][j] != s[i + 2][j]):
				continue
			dp[i][j] = max(dp[i][j], 1 + min(dp[i + 1][j - 1], dp[i + 1][j + 1], dp[i + 2][j]))
	ans = 0
	for i in range(n):
		for j in range(m):
			ans += dp[i][j]
	return ans

def main():
	(n, m) = ria()
	s = []
	for i in range(n):
		s.append(rs())
	wi(solve(n, m, s))
main()


import io
import os
from array import array
ordA = ord('a')

def solve(R, C, grid):
	seen = [False for i in range(26)]
	for i in range(R * C):
		seen[grid[i] - ordA] = True
	ans = 0
	CC = C + 1
	dp2 = array('h', (0 for i in range(CC)))
	dp1 = array('h', (0 for i in range(CC)))
	dp0 = array('h', (0 for i in range(CC)))
	for i in range(26):
		ch = ordA + i
		if seen[i]:
			for c in range(C):
				dp2[c] = 0
				dp1[c] = 0
			j = 0
			for r in range(R):
				for c in range(C):
					dp0[c] = 0 if grid[j] != ch else 1 + min(dp2[c], dp1[c - 1], dp1[c], dp1[c + 1])
					ans += dp0[c]
					j += 1
				(dp2, dp1, dp0) = (dp1, dp0, dp2)
	return ans
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
(N, M) = [int(x) for x in input().split()]
grid = b''.join((input().rstrip() for i in range(N)))
ans = solve(N, M, grid)
print(ans)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
(n, m) = mdata()
dp = [[0] * m for i in range(n)]
mat = []
for i in range(n):
	mat.append(data())
ans = n * m
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if mat[i - 1][j] == mat[i][j - 1] == mat[i][j]:
			dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1
for i in range(n - 2, 0, -1):
	for j in range(m - 2, 0, -1):
		if mat[i + 1][j] == mat[i][j + 1] == mat[i][j]:
			dp[i][j] = min(dp[i][j], min(dp[i + 1][j], dp[i][j + 1]) + 1)
		else:
			dp[i][j] = 0
		ans += dp[i][j]
out(ans)


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
MAP = [input().strip() for i in range(n)]
COUNT0 = [[1] * m for i in range(n)]
COUNT1 = [[1] * m for i in range(n)]
COUNT2 = [[1] * m for i in range(n)]
COUNT3 = [[1] * m for i in range(n)]
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if MAP[i][j] == MAP[i][j - 1] == MAP[i - 1][j]:
			COUNT0[i][j] = min(COUNT0[i][j - 1], COUNT0[i - 1][j]) + 1
for i in range(1, n - 1):
	for j in range(m - 2, 0, -1):
		if MAP[i][j] == MAP[i][j + 1] == MAP[i - 1][j]:
			COUNT1[i][j] = min(COUNT1[i][j + 1], COUNT1[i - 1][j]) + 1
for i in range(n - 2, 0, -1):
	for j in range(1, m - 1):
		if MAP[i][j] == MAP[i][j - 1] == MAP[i + 1][j]:
			COUNT2[i][j] = min(COUNT2[i][j - 1], COUNT2[i + 1][j]) + 1
for i in range(n - 2, 0, -1):
	for j in range(m - 2, 0, -1):
		if MAP[i][j] == MAP[i][j + 1] == MAP[i + 1][j]:
			COUNT3[i][j] = min(COUNT3[i][j + 1], COUNT3[i + 1][j]) + 1
ans = 0
for i in range(n):
	for j in range(m):
		ans += min(COUNT0[i][j], COUNT1[i][j], COUNT2[i][j], COUNT3[i][j])
print(ans)


import os, sys
from io import BytesIO, IOBase

def main():
	(n, m) = map(int, input().split())
	a = [input().strip() for _ in range(n)]
	left = [[1] * m for _ in range(n)]
	right = [[1] * m for _ in range(n)]
	up = [[1] * m for _ in range(n)]
	down = [[1] * m for _ in range(n)]
	for i in range(n):
		for j in range(1, m):
			if a[i][j] == a[i][j - 1]:
				left[i][j] = left[i][j - 1] + 1
	for i in range(n):
		for j in range(m - 2, -1, -1):
			if a[i][j] == a[i][j + 1]:
				right[i][j] = right[i][j + 1] + 1
	for i in range(1, n):
		for j in range(m):
			if a[i][j] == a[i - 1][j]:
				up[i][j] = min(left[i][j], right[i][j], up[i - 1][j] + 1)
	for i in range(n - 2, -1, -1):
		for j in range(m):
			if a[i][j] == a[i + 1][j]:
				down[i][j] = min(left[i][j], right[i][j], down[i + 1][j] + 1)
	su = min(2, n) * m
	for i in range(1, n - 1):
		for j in range(m):
			su += min((up[i - 1][j] if a[i - 1][j] == a[i][j] else 0) + 1, (down[i + 1][j] if a[i + 1][j] == a[i][j] else 0) + 1, left[i][j], right[i][j])
	print(su)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from itertools import product
(n, m) = map(int, input().split())
bd = [input() for _ in range(n)]
bc = [[0] * m for _ in range(n)]
sm = 0
for (i, j) in product(range(n), range(m)):
	if i - 2 >= 0 and j - 1 >= 0 and (j + 1 < m) and (bd[i][j] == bd[i - 1][j - 1] == bd[i - 1][j] == bd[i - 1][j + 1] == bd[i - 2][j]):
		bc[i][j] = min(bc[i - 1][j - 1], bc[i - 1][j + 1], bc[i - 2][j]) + 1
	else:
		bc[i][j] = 1
	sm += bc[i][j]
print(sm)


(n, m) = map(int, input().split())
a = []
for j in range(n):
	a.append(input().strip())
dp = [[1 for i in range(m)] for j in range(n)]
for j in range(2, n):
	for k in range(1, m - 1):
		if a[j][k] == a[j - 2][k] == a[j - 1][k] == a[j - 1][k - 1] == a[j - 1][k + 1]:
			dp[j][k] = min(dp[j - 2][k], dp[j - 1][k - 1], dp[j - 1][k + 1]) + 1
s = 0
for j in range(n):
	for k in range(m):
		s = s + dp[j][k]
print(s)


(n, m) = map(int, input().split())
u = []
d = []
for i in range(n):
	u.append(list(input()))
	d.append([0] * m)
for j in range(m):
	d[0][j] = 1
for i in range(1, n):
	for j in range(m):
		if j == 0 or j == m - 1 or (not u[i - 1][j - 1] == u[i - 1][j] == u[i - 1][j + 1] == u[i][j]):
			cur = 0
		else:
			cur = min(d[i - 1][j - 1], d[i - 1][j], d[i - 1][j + 1])
		dl = cur * 2
		if dl <= i and u[i - dl][j] == u[i][j]:
			d[i][j] = cur + 1
		else:
			d[i][j] = cur
ans = 0
for i in range(n):
	ans += sum(d[i])
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
(n, m) = RL()
dp = [[1] * m for _ in range(n)]
grid = []
for _ in range(n):
	grid.append(input())
if m == 1 or n == 1:
	print(m * n)
else:
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i - 1][j] and (grid[i][j] == grid[i][j + 1]) and (grid[i][j] == grid[i][j - 1]):
				dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1
	for i in range(1, n - 1):
		for j in range(m - 2, 0, -1):
			if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i - 1][j] and (grid[i][j] == grid[i][j + 1]) and (grid[i][j] == grid[i][j - 1]):
				dp[i][j] = min(min(dp[i - 1][j], dp[i][j + 1]) + 1, dp[i][j])
	for i in range(n - 2, 0, -1):
		for j in range(m - 2, 0, -1):
			if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i - 1][j] and (grid[i][j] == grid[i][j + 1]) and (grid[i][j] == grid[i][j - 1]):
				dp[i][j] = min(min(dp[i + 1][j], dp[i][j + 1]) + 1, dp[i][j])
	for i in range(n - 2, 0, -1):
		for j in range(1, m - 1):
			if grid[i][j] == grid[i + 1][j] and grid[i][j] == grid[i - 1][j] and (grid[i][j] == grid[i][j + 1]) and (grid[i][j] == grid[i][j - 1]):
				dp[i][j] = min(min(dp[i + 1][j], dp[i][j - 1]) + 1, dp[i][j])
	print(sum((a for b in dp for a in b)))


(n, m) = list(map(int, input().split()))
mat = []
for i in range(n):
	row = []
	ls = list(input())
	for item in ls:
		row.append(ord(item) - 97)
	mat.append(row)
state = [[[1, 1], [None, None]] for j in range(m)]
c = 0
l = 1
res = m
for i in range(1, n):
	for j in range(m):
		char = mat[i][j]
		state[j][l][0] = 1
		state[j][l][1] = 1
		if not (j == 0 or j == m - 1):
			if char == mat[i - 1][j] and char == mat[i - 1][j - 1] and (char == mat[i - 1][j + 1]):
				max_rh = min(min(state[j - 1][c][0], state[j + 1][c][0]) + 2, state[j][c][1] + 1)
				if max_rh % 2 == 0:
					max_rh -= 1
				state[j][l][0] = max_rh
				state[j][l][1] += state[j][c][1]
			elif char == mat[i - 1][j]:
				state[j][l][1] += state[j][c][1]
		res += state[j][l][0] // 2 + 1
	temp = c
	c = l
	l = temp
print(res)


temp = input().split()
row = int(temp[0])
column = int(temp[1])
mn = min(row, column)
cloth = [[0] * column for i in range(row)]
for i in range(row):
	temp = input()
	cloth[i] = temp
count = 0
dp = [[0] * column for i in range(row)]
for i in range(row):
	for j in range(column):
		if i < 2 or j < 1 or j == column - 1:
			dp[i][j] = 1
		elif cloth[i - 1][j - 1] == cloth[i][j] and cloth[i - 1][j] == cloth[i][j] and (cloth[i - 1][j + 1] == cloth[i][j]) and (cloth[i - 2][j] == cloth[i][j]):
			dp[i][j] = min(dp[i - 1][j - 1], dp[i - 2][j], dp[i - 1][j + 1]) + 1
		else:
			dp[i][j] = 1
print(sum(map(sum, dp)))


import sys
input = sys.stdin.readline
(n, m) = map(int, input().split())
S = [input()[:-1] for _ in range(n)]
dp = [[0] * m for _ in range(n)]
ans = 0
for i in range(n):
	for j in range(m):
		if i >= 2 and j - 1 >= 0 and (j + 1 < m) and (S[i][j] == S[i - 1][j] == S[i - 1][j - 1] == S[i - 1][j + 1] == S[i - 2][j]):
			dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 2][j]) + 1
		else:
			dp[i][j] = 1
		ans += dp[i][j]
print(ans)


(r, c) = map(int, input().split())
rama = []
for i in range(r):
	rama.append(list(input()))
visit = [[1 for i in range(c)] for j in range(r)]
for i in range(2, r):
	for j in range(1, c - 1):
		if rama[i][j] == rama[i - 1][j - 1] == rama[i - 1][j + 1] == rama[i - 2][j] == rama[i - 1][j]:
			visit[i][j] = min(visit[i - 1][j - 1], visit[i - 1][j + 1], visit[i - 2][j]) + 1
add = 0
for i in visit:
	for j in i:
		add += j
print(add)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	(n, m) = RL()
	gp = [input() for _ in range(n)]
	nex = [[-1, -1], [-1, 1], [-1, 0], [-2, 0]]
	dp = [[1] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			mi = INF
			for (nx, ny) in nex:
				(xx, yy) = (nx + i, ny + j)
				if -1 < xx < n and -1 < yy < m:
					if gp[xx][yy] != gp[i][j]:
						break
					mi = min(dp[xx][yy], mi)
				else:
					break
			else:
				if mi != INF and mi + 1 > dp[i][j]:
					dp[i][j] = mi + 1
					tag = True
	res = 0
	for i in dp:
		for j in i:
			res += j
	print(res)
main()


def tc():
	(n, m) = list(map(int, input().split()))
	mat = [input() for _ in range(n)]
	alpha = 'abcdefghijklmnopqrstuvwxyz'
	dp = [[0] * m for _ in range(n)]
	ans = 0
	for i in range(n):
		for j in range(m):
			if j == 0 or j == m - 1 or i < 2:
				dp[i][j] = 1
			elif mat[i][j] == mat[i - 1][j] and mat[i][j] == mat[i - 1][j - 1] and (mat[i][j] == mat[i - 1][j + 1]) and (mat[i][j] == mat[i - 2][j]):
				dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1], dp[i - 1][j + 1], dp[i - 2][j]) + 1
			else:
				dp[i][j] = 1
			ans += dp[i][j]
	print(ans)
tc()


(n, m) = map(int, input().split())
L = []
for i in ' ' * n:
	L.append(input())
dp = [[0] * m for i in range(n)]
for i in range(n + m - 1):
	rightmin = max(0, i - (n - 1))
	leftmin = max(0, i - (m - 1))
	left = i - rightmin
	jstart = max(0, i - (n - 1))
	for j in range(abs(left - leftmin) + 1):
		jj = jstart + j
		ii = i - jj
		if jj < 2 or ii < 1 or ii == n - 1:
			dp[ii][jj] = 1
			continue
		if L[ii + 1][jj - 1] == L[ii][jj - 1] == L[ii][jj - 2] == L[ii - 1][jj - 1] == L[ii][jj]:
			dp[ii][jj] = min(dp[ii + 1][jj - 1], dp[ii][jj - 1], dp[ii][jj - 2], dp[ii - 1][jj - 1]) + 1
		else:
			dp[ii][jj] = 1
ct = 0
for i in dp:
	for j in i:
		ct += j
print(ct)


import sys
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : sys.stdin.readline().strip().split()
ri = lambda : int(sys.stdin.readline().strip())
rs = lambda : sys.stdin.readline().strip()
from collections import defaultdict as df
from math import *
(n, m) = RI()
l = [[] for i in range(n)]
for i in range(n):
	l[i] = list(rs())
down = [[0] * m for i in range(n)]
for i in range(m):
	down[n - 1][i] = 1
for i in range(n - 2, -1, -1):
	for j in range(m):
		if l[i + 1][j] == l[i][j]:
			down[i][j] = down[i + 1][j] + 1
		else:
			down[i][j] = 1
maxr = [[1] * m for i in range(n)]
for i in range(n - 2, -1, -1):
	for j in range(m):
		if j == 0 or j == m - 1:
			continue
		if l[i][j] != l[i + 1][j - 1] or l[i][j] != l[i + 1][j] or l[i][j] != l[i + 1][j + 1]:
			continue
		left = maxr[i + 1][j - 1]
		right = maxr[i + 1][j + 1]
		center = down[i + 1][j]
		center = center // 2
		maxr[i][j] = min(left, right, center) + 1
ans = 0
for i in range(n):
	for j in range(m):
		ans += maxr[i][j]
print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
(n, m) = Ri()
lis = []
for i in range(n):
	lis.append(ri())
maxxbar = list2d(n, m, 1)
for i in range(n):
	cnt = 0
	for j in range(m):
		if j == 0:
			continue
		if lis[i][j] == lis[i][j - 1]:
			maxxbar[i][j] = maxxbar[i][j - 1] + 1
	for j in range(m - 1, -1, -1):
		if j == m - 1:
			maxxbar[i][j] = 1
			cnt = 1
			continue
		if lis[i][j] == lis[i][j + 1]:
			cnt += 1
			maxxbar[i][j] = 2 * min(maxxbar[i][j], cnt) - 1
		else:
			maxxbar[i][j] = 1
			cnt = 1
up = list2d(n, m, 1)
for i in range(1, n - 1):
	for j in range(1, m - 1):
		if lis[i][j] == lis[i - 1][j]:
			if maxxbar[i][j] - 2 <= up[i - 1][j]:
				up[i][j] = maxxbar[i][j]
			else:
				up[i][j] = up[i - 1][j] + 2
down = list2d(n, m, 1)
for i in range(n - 2, 0, -1):
	for j in range(m - 1, 0, -1):
		if lis[i][j] == lis[i + 1][j]:
			if maxxbar[i][j] - 2 <= down[i + 1][j]:
				down[i][j] = maxxbar[i][j]
			else:
				down[i][j] = down[i + 1][j] + 2
ans = 0
for i in range(n):
	for j in range(m):
		ans += min(up[i][j], down[i][j]) // 2 + 1
print(ans)


from sys import stdin

def main():
	(n, m) = map(int, stdin.readline().split())
	arr = [stdin.readline() for i in range(n)]
	up = [[0] * m for _ in range(n)]
	down = [[0] * m for _ in range(n)]
	left = [[0] * m for _ in range(n)]
	right = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(1, m):
			if arr[i][j] == arr[i][j - 1]:
				left[i][j] = left[i][j - 1] + 1
		for j in range(m - 2, -1, -1):
			if arr[i][j] == arr[i][j + 1]:
				right[i][j] = right[i][j + 1] + 1
	for i in range(1, n):
		for j in range(m):
			if arr[i - 1][j] == arr[i][j]:
				up[i][j] = min(up[i - 1][j] + 1, min(left[i][j], right[i][j]))
	for i in range(n - 2, -1, -1):
		for j in range(m):
			if arr[i + 1][j] == arr[i][j]:
				down[i][j] = min(down[i + 1][j] + 1, min(left[i][j], right[i][j]))
	ans = 0
	for i in range(n):
		for j in range(m):
			ans += min(left[i][j], right[i][j], up[i][j], down[i][j]) + 1
	print(ans)
main()


import sys
input = sys.stdin.readline
(m, n) = map(int, input().split())
A = [input()[:-1] for _ in range(m)]
(left, right) = ([[1] * n for _ in range(m)], [[1] * n for _ in range(m)])
for i in range(m):
	for j in range(n):
		if A[i][j] == A[i][j - 1]:
			left[i][j] += left[i][j - 1] if j else 0
for i in range(m):
	for j in range(n - 2, -1, -1):
		if A[i][j] == A[i][j + 1]:
			right[i][j] += right[i][j + 1] if j < n - 1 else 0
dp = [[0] * n for _ in range(m)]
for i in range(m):
	for j in range(n):
		dp[i][j] = min(left[i][j], right[i][j], (dp[i - 1][j] if i and A[i][j] == A[i - 1][j] else 0) + 1)
dp2 = [[0] * n for _ in range(m)]
for i in range(m - 1, -1, -1):
	for j in range(n):
		dp2[i][j] = min(left[i][j], right[i][j], (dp2[i + 1][j] if i + 1 < m and A[i][j] == A[i + 1][j] else 0) + 1)
ans = 0
for i in range(m):
	for j in range(n):
		ans += min(dp[i][j], dp2[i][j])
print(ans)


(n, m) = map(int, input().split(' '))
f = [[] for i in range(n)]
d = [[0 for j in range(m)] for i in range(n)]
count = 0
for i in range(n):
	s = input()
	for j in range(m):
		c = s[j]
		f[i].append(c)
		if j - 1 >= 0 and i - 1 >= 1 and (j + 1 < m):
			if f[i - 1][j - 1] == c and f[i - 1][j] == c and (f[i - 1][j + 1] == c) and (f[i - 2][j] == c):
				d[i][j] = 1 + min(d[i - 1][j + 1], d[i - 1][j], d[i - 1][j - 1], d[i - 2][j])
			else:
				d[i][j] = 1
		else:
			d[i][j] = 1
		count += d[i][j]
print(count)