Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

K,S=map(int,input().strip().split(" "))
count=0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if((x+y+z)==S):
                count+=1
                #print(x,y,z)
print(count)
            


### FIXED CODE ###

"""
K,S=map(int,input().strip().split(" "))
count=0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if((x+y+z)==S):
                count+=1
                #print(x,y,z)
print(count)
            
"""

K,S=map(int,input().strip().split(" "))
count=0

for x in range(K+1):
    for y in range(K+1):
        if(0<=S-x-y<=K):
            count+=1
print(count)
### BUGGY CODE ###

i=j=x=int(input())
while(i:=-~i%99)**5-j**5-x:j=j%200-i
print(i,j)

### FIXED CODE ###

x,r=int(input()),range(-99,120);[i**5-x-j**5or exit(print(i,j))for i in r for j in r]
### BUGGY CODE ###

def combi(n, r):
  if r == 0 or n == r:
    return 1
  return combi(n-1, r-1) + combi(n-1, r)

n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list)/len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
  print(1)
elif max_ave_list[0] != max_ave_list[-1]:
  print(combi(l, m))
else:
  print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))

### FIXED CODE ###

import sys

sys.setrecursionlimit(10000)


def memoize(f):
    cache = {}

    def func(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]

    return func


@memoize



def combi(n, r):
  if r == 0 or n == r:
    return 1
  return combi(n-1, r-1) + combi(n-1, r)

n, a, b = map(int, input().split())
items = sorted(map(int, input().split()), reverse=True)
max_ave_list = items[:a]
print(sum(max_ave_list)/len(max_ave_list))

m = max_ave_list.count(max_ave_list[-1])
l = items.count(max_ave_list[-1])
if l == m:
  print(1)
elif max_ave_list[0] != max_ave_list[-1]:
  print(combi(l, m))
else:
  print(sum(combi(l, k) for k in range(m, min(b, l) + 1)))
### BUGGY CODE ###

n=int(input())
a=[0]*n
b=[0]*n
c=[0]
d=[0]
for i in range(n):
	a[i],b[i]=map(int,input().split())
	for j in range(len(c)):
		if a[i]+b[i]>=c[j]:
			c.insert(j,a[i]+b[i])
			d.insert(j,i)
			break
ta=0
ao=0
turn=0
for i in range(n):
	if turn==0:
		ta+=a[d[i]]
		turn=1
	else:
		ao+=b[d[i]]
		turn=0
print(ta-ao)

### FIXED CODE ###

n=int(input())
a=[0]*n
b=[0]*n
c=[]
for i in range(n):
	a[i],b[i]=map(int,input().split())
	c.append((a[i]+b[i],i))
d=sorted(c,reverse=True)
ta=0
ao=0
turn=0
for i in range(n):
	if turn==0:
		ta+=a[d[i][1]]
		turn=1
	else:
		ao+=b[d[i][1]]
		turn=0
print(ta-ao)
### BUGGY CODE ###

from collections import deque

class Grid():
    def __init__(self,i,j,isblack):
        self.i=i
        self.j=j
        self.isblack=isblack
        self.distance=0

H,W=map(int,input().split())

g=[]
for i in range(H):
    Ai=input()
    gi=[]    
    for j in range(W):
        gi.append(Grid(i,j,Ai[j]=='#'))
    g.append(gi)

d=deque()

# 黒マスのreachedをTrueにし，dequeに入れる
for row in g:
    for grid in row:
        if grid.isblack:
            d.append(grid)

while d:
    tg=d.popleft()
    i=tg.i
    j=tg.j
    if i>0 and not g[i-1][j].isblack:
        g[i-1][j].isblack=True
        g[i-1][j].distance=tg.distance+1
        d.append(g[i-1][j])
    if i<H-1 and not g[i+1][j].isblack:
        g[i+1][j].isblack=True
        g[i+1][j].distance=tg.distance+1
        d.append(g[i+1][j])
    if j>0 and not g[i][j-1].isblack:
        g[i][j-1].isblack=True
        g[i][j-1].distance=tg.distance+1
        d.append(g[i][j-1])
    if j<W-1 and not g[i][j+1].isblack:
        g[i][j+1].isblack=True
        g[i][j+1].distance=tg.distance+1
        d.append(g[i][j+1])

'''
for row in g:
    for grid in row:
#        print(grid.distance,end=' ')
#    print()
'''

print(max([max([grid.distance for grid in row]) for row in g]))

### FIXED CODE ###

from collections import deque

class Grid():
    def __init__(self,i,j,isblack):
        self.i=i
        self.j=j
        self.isblack=isblack
        self.distance=0

H,W=map(int,input().split())

g=[]
for i in range(H):
    Ai=input()
    gi=[]    
    for j in range(W):
        gi.append(Grid(i,j,Ai[j]=='#'))
    g.append(gi)

d=deque()

# 黒マスのreachedをTrueにし，dequeに入れる
for row in g:
    for grid in row:
        if grid.isblack:
            d.append(grid)

while d:
    tg=d.popleft()
    i=tg.i
    j=tg.j
    if i>0 and not g[i-1][j].isblack:
        g[i-1][j].isblack=True
        g[i-1][j].distance=tg.distance+1
        d.append(g[i-1][j])
    if i<H-1 and not g[i+1][j].isblack:
        g[i+1][j].isblack=True
        g[i+1][j].distance=tg.distance+1
        d.append(g[i+1][j])
    if j>0 and not g[i][j-1].isblack:
        g[i][j-1].isblack=True
        g[i][j-1].distance=tg.distance+1
        d.append(g[i][j-1])
    if j<W-1 and not g[i][j+1].isblack:
        g[i][j+1].isblack=True
        g[i][j+1].distance=tg.distance+1
        d.append(g[i][j+1])

'''
for row in g:
    for grid in row:
#        print(grid.distance,end=' ')
#    print()
'''

print(max([max([grid.distance for grid in row]) for row in g]))
### BUGGY CODE ###

k, n = map(int, input().split())
def next_lexico(K, N, L):
	if len(L) < N:
		return L + [1]
	else:
		IND = N-1
		while L[IND] == K and IND > 0:
			IND -= 1
		if IND == 0:
			return [L[0]+1]
		else:
			return L[:IND] + [L[IND]+1]

if k == 1:
	print(*[1 for _ in range((n+1)//2)])
elif n == 1:
	print((k+1)//2)
elif k%2 == 0:
	ans = [k//2] + [k] * (n-1)
	print(*ans)
else:
	if n%2 == 1:
		cur, i = 1, n
	else:
		cur, i = 0, n
	while cur <= i:
		i -= 1
		cur += pow(k, n-i)
	ans = [(k+1)//2] * i
	ind = (cur-i) // 2
	l = [1]
	for _ in range(ind-1):
		l = next_lexico(k, n-i, l)
	ans += l
	print(*ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
k, n = map(int, input().split())

def calc_x(K, N):
	return (pow(K, N+1)-K) // (K-1)
def lexico(K, N, X):
	#print(K, N, X)
	global ans
	if X == 0:
		return
	q = (calc_x(K, N-1)+1)
	if N > 1:
		ans.append((X//q) + 1)
	else:
		ans.append((X//q))
	lexico(K, N-1, (X-1)%q)

if k == 1:
	print(*[1 for _ in range((n+1)//2)])
elif n == 1:
	print((k+1)//2)
elif k%2 == 0:
	ans = [k//2] + [k] * (n-1)
	print(*ans)
else:
	if n%2 == 1:
		cur, i = 1, n
	else:
		cur, i = 0, n
	while cur <= i:
		i -= 1
		cur += pow(k, n-i)
	ans = [(k+1)//2] * i
	ind = (cur-i) // 2
	lexico(k, n-i, ind)
	print(*ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 1 << 60
D = [INF] * n
D[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i >= j:
            D[i] = min(D[i], D[i - j] + abs(h[i] - h[i - j]))
print(D[-1])


### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
INF = 1 << 60
D = [INF] * n
D[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i >= j:
            D[i] = min(D[i], D[i - j] + abs(h[i] - h[i - j]))
print(D[-1])
### BUGGY CODE ###

n = int(input())
s = 0
base = 10
while n > 0:
    n,r = divmod(n,base)
    add = r
    s += add
    s %= 9
#print(s)
if s % 9 == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

n = int(input())
if n % 9 == 0:
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

l,r = map(int,input().split())

a = l*r%2019
for i in range(l,r) :
    for j in range(i+1,r+1):
        if (a > i*j%2019) :
            a = i*j%2019


print(a)

### FIXED CODE ###

def yo():
    l,r = map(int,input().split())

    a = l*r%2019
    for i in range(l,r) :
        for j in range(i+1,r+1):
            ij = i*j%2019
            
            if (a > ij) :
                a = ij

            if(a==0) :
                return a

    return a



print(yo())
### BUGGY CODE ###

import math
n,m,k = map(int,input().split())
ss = (math.factorial(m*n)//math.factorial(k))//math.factorial(m*n-k)
s = (ss*k*(k-1))//2
r = 10**9 +7
xav = 0
yav = 0
for i in range(1,m):
  xav += (i*(m-i)*n**2)%r
for j in range(1,n):
  yav += (j*(n-j)*m**2)%r
av = xav + yav
d = (m*n*(m*n-1))//2
print(int(((av*s)//d)%r))




### FIXED CODE ###

n,m,k = map(int,input().split())
x = m*n
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
ss = cmb(x,k)
s = (ss*k*(k-1))//2
r = 10**9 +7
av = (((m**3-m) *n**2)//6 + ((n**3-n)*m**2)//6)%r
d = (x*(x-1))//2
print(int(((av*s)//d)%r))
### BUGGY CODE ###

import math

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def factorize(n):
    primes = set()
    for p in Ps:
        if p * p > n:
            break
        while n % p == 0:
            n //= p
            primes.add(p)
    if n > 1:
        primes.add(n)
    return primes

Ps = primes(10 ** 6)
n = int(input())
As = list(map(int, input().split()))

# setwiseFlag
gcd = As[0]
for a in As:
  gcd = math.gcd(gcd, a)
setwiseFlag = (gcd == 1)

# pairwiseFlag
pairwiseFlag = True
for p in Ps:
  count = 0
  for _p in range(p, 10 ** 6 + 1, p):
    if _p in As:
      count += 1
  if count > 1:
    pairwiseFlag = False

if pairwiseFlag:
  print('pairwise coprime')
elif setwiseFlag:
  print('setwise coprime')
else:
  print('not coprime')


### FIXED CODE ###

import bisect
import math

n = int(input())
As = list(map(int, input().split()))
As.sort()

# cons = 10 ** 6
# is_prime = [True] * (cons + 1)
# is_prime[0] = False
# is_prime[1] = False
# for i in range(2, int(cons**0.5) + 1):
#     if not is_prime[i]:
#         continue
#     for j in range(i * 2, cons + 1, i):
#         is_prime[j] = False
# Ps = [i for i in range(cons + 1) if is_prime[i]]
def eratosthenes(n):
    is_prime = [0, 0] + [1] * (n - 1)
    for i in range(int(n**0.5) + 1):
        if is_prime[i] == 0:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return [i for i, pi in enumerate(is_prime) if pi == 1]
Ps = eratosthenes(10 ** 6)

def factorize(n):
    primes = set()
    for p in Ps:
        if p * p > n:
            break
        while n % p == 0:
            n //= p
            primes.add(p)
    if n > 1:
        primes.add(n)
    return primes

gcd = As[0]
for a in As:
  gcd = math.gcd(gcd, a)
setwiseFlag = (gcd == 1)

pairwiseFlag = True
target = set()
for a in As:
  primes = factorize(a)
  if len(primes & target) > 0:
    pairwiseFlag = False
  target |= primes

if pairwiseFlag:
  print('pairwise coprime')
elif setwiseFlag:
  print('setwise coprime')
else:
  print('not coprime')
### BUGGY CODE ###

import numpy as np
N, K = [int(_) for _ in input().split()]
A = np.array(sorted([int(_) for _ in input().split()]))


def solve(N, K, A):
    lb = -10**18 - 1
    rb = 10**18 + 1

    def check(x):
        #x以下の積がK個以上ある
        cnt = 0
        for i, a in enumerate(A):
            #区間i2∈[0,i) でA[i]*A[i2]<=xとなるようなi2の個数
            l = 0
            r = i
            if a > 0:
                l = -1
                r = np.searchsorted(A, x // a, side='right')
            elif a < 0:
                l = np.searchsorted(A, 0 - x // -a, side='left')
                r = N + 1
            elif x < 0:
                r = 0
            l = min(max(l, 0), i)
            r = max(min(r, i), 0)
            cnt += r - l
        return cnt >= K

    # Min x for check(x) == True
    while rb - lb > 1:
        mid = (rb + lb) // 2
        if check(mid):
            rb = mid
        else:
            lb = mid
    print(rb)


solve(N, K, A)


### FIXED CODE ###

import numpy as np
from numba import njit
N,K=[int(_) for _ in input().split()]
A = np.array([int(_) for _ in input().split()],dtype=int)
A.sort()


@njit
def main(N,K,A):
    lb = -10**18-1
    rb = 10 ** 18 + 1
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                elif a < 0:
                    il = np.searchsorted(A,0- (-target)//a,side='left')
                    d = max(i - il, 0)
                else:
                    ir = np.searchsorted(A,target//a,side='right')
                    d = min(ir, i)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

print(main(N,K,A))
### BUGGY CODE ###

n=int(input())
x=list(map(int,input().split()))
a=sorted(x)

for i in x:
    p=a.index(i)

    if p< n//2:
        print(a[n//2])
    else:
        print(a[n//2-1])
        
        

### FIXED CODE ###

n=int(input())
x=list(map(int,input().split()))
a=sorted(x)
ans={}

for i in range(n):

    if i<n//2:
        ans[a[i]]=a[n//2]
    else:
        ans[a[i]]=a[n//2-1]

for j in x:
    print(ans[j])
### BUGGY CODE ###

def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, k = Input()
    data = sorted(int(input()) for _ in range(n))
    ans = 1e9
    for i in range(n-k+1):
        x = data[i:i+k]
        ans = min(ans, max(x) - min(x))
    print(ans)
main()

### FIXED CODE ###

def main():
    n, k = map(int, input().split(" "))
    data = sorted(int(input()) for _ in range(n))
    print(min([data[i+k-1] - data[i] for i in range(n-k+1)]))
main()
### BUGGY CODE ###

import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7

INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)

N, M = [int(x) for x in input().split()]

# T = [[0] * N for _ in range(N)]
E = [set() for _ in range(N + 1)]

for i in range(M):
    u, v = [int(x) for x in input().split()]
    E[u].add(v)

S, T = [int(x) for x in input().split()]


def f(startSet, n):
    if n == 0:
        return startSet
    ret = set()
    for s in startSet:
        for t in E[s]:
            ret.add(t)
    return f(ret, n - 1)


# print(f({1}, 3))
# print(f({2}, 3))
# print(f({3}, 3))
# print(f({4}, 3))

E2 = [f({i}, 3) for i in range(N + 1)]

openNodes = {S}
closeedNodes = {}
mi = [INF] * (N + 1)
mi[S] = 0

while len(openNodes) != 0:
    curNode = -1
    curW = INF
    for on in openNodes:
        if mi[on] < curW:
            curNode = on
    openNodes.remove(curNode)

    for nn in E2[curNode]:
        if mi[nn] == INF:
            openNodes.add(nn)
            mi[nn] = mi[on] + 1

print(mi[T] if mi[T] != INF else -1)


### FIXED CODE ###

import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, factorial
import math

sys.setrecursionlimit(1000000)

MOD = 10 ** 9 + 7

INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)

N, M = [int(x) for x in input().split()]

# E = {set() for _ in range(N + 1)}
E = defaultdict(lambda: set())

for i in range(M):
    u, v = [int(x) for x in input().split()]
    u -= 1
    v -= 1
    E[3 * u].add(3 * v + 1)
    E[3 * u + 1].add(3 * v + 2)
    E[3 * u + 2].add(3 * v)

S, T = [int(x) for x in input().split()]
S = 3 * (S - 1)
T = 3 * (T - 1)


def bfs(e, start, end):
    open = deque([start])
    w = dict()
    w[start] = 0
    while len(open) != 0:
        target = open.popleft()
        for next in E[target]:
            if not next in w:
                open.append(next)
                w[next] = w[target] + 1

    return w[end] // 3 if end in w else -1


print(bfs(E, S, T))
### BUGGY CODE ###

N = int(input())
S = []
cnt = 0
for i in range(N):
    s = sorted(input())
    for s_tmp in S:
        if s_tmp == s:
            cnt += 1
    S.append(s)

print(cnt)

### FIXED CODE ###

N = int(input())
S = []
cnt = 0
for i in range(N):
    s = sorted(input())
    new_str = ''.join(s)
    S.append(new_str)

# print(S)

import collections

c = collections.Counter(S)

# print(c)

ary = c.values()

import math

def combinations_count(n, r = 2):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


for i in ary:
    if i != 1:
        cnt += combinations_count(i)


print(cnt)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#mitsui d
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

s=input()
#tmp = input().split()
#s = list(map(lambda a: int(a), tmp))

ans=0

for i in range(0,10):
	for j in range(0,10):
		for k in range(0,10):
			flg=0
			for index in range(0,n):
				if(flg==0)and(s[index]==str(i)):
					flg+=1
				elif(flg==1)and(s[index]==str(j)):
					flg+=1
				elif(flg==2)and(s[index]==str(k)):
					flg+=1
					break
			if(flg==3):
				tst=str(i)+str(j)+str(k)
#				print(tst)
				ans+=1
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
#mitsui d
import sys
import math
import collections
#sys.setrecursionlimit(100000)

n=int(input())

s=input()
#tmp = input().split()
#s = list(map(lambda a: int(a), tmp))

sfirst=[]
slast=[]
for i in range(0,10):
	sfirst.append(n)
	slast.append(0)
for i in range(0,n):
	if(sfirst[int(s[i])]>i):
		sfirst[int(s[i])]=i
	if(slast[int(s[i])]<i):
		slast[int(s[i])]=i
#print(s)
#print(sfirst)
#print(slast)

ans=0

for i in range(0,10):
	for j in range(0,10):
		for k in range(0,10):
			flg=0
			for index in range(sfirst[i]+1,slast[k]):
				if(flg==0)and(s[index]==str(j)):
					flg+=1
					ans+=1
					break
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
a,b = '',''
ans = 0
for i in range(N):
  a = S[i]
  for j in range(i,N):
    if S[j] != a:
      b = S[j]
      for k in range(j,N):
        if S[k]!=a and S[k]!=b and j-i!=k-j:
          ans += 1
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
a,b = '',''
r = S.count('R')
g = S.count('G')
b = len(S)-r-g
rgb = r*g*b
expt = 0
for i in range(N):
  a = S[i]
  for j in range(i,(N+i-1)//2+1):
    if S[j] != a:
      b = S[j]
      k = 2*j-i
      if S[k]!=b and S[k]!=a:
        expt += 1
print(rgb-expt)
### BUGGY CODE ###

import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,r+1)])))
ans = 10**9

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    left +=1
print(ans)

### FIXED CODE ###

import numpy as np
l,r = map(int,input().split())
mod = 2019
arr = np.array(list(set([i%mod for i in range(l,min(r+1,l+2019))])))
ans = 2019

for left in range(len(arr)-1):
    ans = min(min(arr[left]*arr[left+1:]%mod),ans)
    if ans == 0:
        print(ans)
        exit()
print(ans)
### BUGGY CODE ###

#ABC154D
import sys

n, k = map(int, sys.stdin.readline().split())
p = list(map(int, sys.stdin.readline().split()))

ans = 0
total = 0
for i in range(n+1-k):
    total = 0
    for j in range(k):
        total += (1+p[i+j])/2
    if ans < total:
        ans = total
print(ans)

### FIXED CODE ###

#ABC154D
import sys
N, K = map(int, sys.stdin.readline().split())
P = list(map(int, sys.stdin.readline().split()))

#print(P)

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2
#print(L)

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

#print(S)
total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)
### BUGGY CODE ###

h, w = map(int, input().split())
grid = [[1 if i == "#" else 0 for i in input()] for _ in range(h)]
seen = [[0] * w for _ in range(h)]
DX = (0, 1, 0, -1)
DY = (1, 0, -1, 0)
ans = 0


def white(X, Y, cnt):
    todo = [(X, Y)]
    seen[X][Y] = cnt
    res = 0
    while todo:
        x, y = todo.pop()
        now = grid[x][y]
        for dx, dy in zip(DX, DY):
            nx = x + dx
            ny = y + dy
            if nx < 0 or ny < 0 or nx >= h or ny >= w:  # インデックスが範囲外ならだめ
                continue
            if seen[nx][ny] == cnt or now == grid[nx][ny]:  # 既に見ていたり、白-白、黒-黒ならばだめ
                continue
            if 1-now:  # 現在位置が白色の場合
                res += 1
            seen[nx][ny] = cnt
            todo.append((nx, ny))
    return res


cnt = 1
for i in range(h):
    for j in range(w):
        if grid[i][j] == 1:
            continue
        ans += white(i, j, cnt)
        cnt += 1

print(ans)


### FIXED CODE ###

h, w = map(int, input().split())
grid = [[1 if i == "#" else 0 for i in input()] for _ in range(h)]
seen = [[0] * w for _ in range(h)]
DX = (0, 1, 0, -1)
DY = (1, 0, -1, 0)
ans = 0


def dfs(X, Y, cnt):
    todo = [(X, Y)]
    seen[X][Y] = cnt
    black = 0
    white = 1
    while todo:
        x, y = todo.pop()
        now = grid[x][y]
        for dx, dy in zip(DX, DY):
            nx = x + dx
            ny = y + dy
            if nx < 0 or ny < 0 or nx >= h or ny >= w:  # インデックスが範囲外ならだめ
                continue
            if seen[nx][ny] == cnt or now == grid[nx][ny]:  # 既に見ていたり、白-白、黒-黒ならばだめ
                continue
            if 1-now:  # 現在位置が白色の場合
                black += 1
            else:
                white += 1
            seen[nx][ny] = cnt
            todo.append((nx, ny))
    return black*white


cnt = 1
for i in range(h):
    for j in range(w):
        if grid[i][j] or seen[i][j]:
            continue
        ans += dfs(i, j, cnt)
        cnt += 1

print(ans)
### BUGGY CODE ###

import sys


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = [i for i, v in enumerate(Mh) if v == nh]
    lw = [i for i, v in enumerate(Mw) if v == nw]

    for h in lh:
        for w in lw:
            if (h, w) not in B:
                print(nh + nw)
                return

    print(nh + nw - 1)


main()


### FIXED CODE ###

import sys
from collections import Counter


def main():
    H, W, M = map(int, sys.stdin.readline().rstrip().split())
    Mh = [0] * H
    Mw = [0] * W
    B = []
    for i in range(M):
        h, w = map(int, sys.stdin.readline().rstrip().split())
        Mh[h - 1] += 1
        Mw[w - 1] += 1
        B.append((h - 1, w - 1))

    nh = max(Mh)
    nw = max(Mw)

    # 交差する場所に置かれた処理物があるか？
    lh = Counter(Mh)[nh]
    lw = Counter(Mw)[nw]

    out = 0
    for (h, w) in B:
        if Mh[h] == nh and Mw[w] == nw:
            out += 1

    if out == lh * lw:
        print(nh + nw - 1)
    else:
        print(nh + nw)


main()