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

N = int(input())
A = list(map(int, input().split()))

if N % 2 == 0:
    for i in range(1, N, 2):
        if A.count(i) != 2:
            print(0)
            exit()
    print(int((2 ** (N/2)) % (10*9 + 7)))
else:
    for j in range(0, N, 2):
        if j == 0:
            if int(A.count(j)) != 1:
                print(0)
                exit()
        else:
            if A.count(j) != 2:
                print(0)
                exit() 
    print(int(2 ** ((N-1)/2) % (10*9 + 7)))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

#if N % 2 == 0:
#    for i in range(1, N, 2):
#        if A.count(i) != 2:
#            print(0)
#            exit()
#    print(int((2 ** (N/2)) % (10*9 + 7)))
#else:
#    for j in range(0, N, 2):
#        if j == 0:
#            if int(A.count(j)) != 1:
#                print(0)
#                exit()
#        else:
#            if A.count(j) != 2:
#                print(0)
#                exit() 
#    print(int(2 ** ((N-1)/2) % (10*9 + 7)))

# 全探索でやると間に合わなかったので正しい場合の和の値を求めてそれを配列の和と比較する

K = N if N % 2 == 0 else N + 1
S = N // 2
if sum(A) == K * S:
    ans = 2 ** S % (10 ** 9 + 7)
else:
    ans = 0

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

n=int(input())
a = list(map(int,input().split()))
ans=1
for i in range(n):
  ans *= a[i]

if(ans > 10**18):
    ans = -1
    
print(ans)

### FIXED CODE ###

n=int(input())
a = list(map(int,input().split()))
ans=1


if(0 in a):
    ans=0
else:
  for i in a:
    ans *= i
    if(ans > 10**18):
      ans = -1
      break

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

K,S= map(int,input().split())

ans=0

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

### FIXED CODE ###

K,S= map(int,input().split())

ans=0

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

class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # グループのサイズ
        return -self.parents[self.find(x)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xysort = sorted(xy)

uf = Unionfind(n)
for i, (p, q) in enumerate(xysort):
    for j, (x, y) in enumerate(xysort[:i]):
        if q > y:
            uf.union(i, j)

for x, y in xy:
    print(uf.size(x - 1))


### FIXED CODE ###

class Unionfind():  # Unionfind
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):  # グループの根
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # グループの併合
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  # グループのサイズ
        return -self.parents[self.find(x)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
xysort = [None] * n
for x, y in xy:
    xysort[x - 1] = y - 1

# 解説AC
uf = Unionfind(n)
tmp, yfrag = 0, [0] * n
for x, y in enumerate(xysort[:n - 1], 1):
    yfrag[y] = 1
    tmp += yfrag[n - x] + (y > n - x)
    if tmp < x:
        uf.union(x, x - 1)

for x, y in xy:
    print(uf.size(x - 1))
### BUGGY CODE ###

n,k = map(int,input().split())
list1 = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j]+abs(list1[i]-list1[i-j]))

print(dp[-1])

### FIXED CODE ###

n,k = map(int,input().split())
list1 = list(map(int,input().split()))
dp = [10**9]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,k+1):
        if i - j < 0:
            break
        dp[i] = min(dp[i],dp[i-j]+abs(list1[i]-list1[i-j]))

print(dp[-1])
### BUGGY CODE ###

from collections import Counter
n = int(input())
p = [list(str(input())) for _ in range(n)]
ln = []
a = []
for i in p:
    a.append(Counter(i))
    if Counter(i)not in ln:
        ln.append(Counter(i))

ln2 = [0] * len(ln)

for j in a:
    ln2[ln.index(j)] += 1
    
ln2 = ([i for i in ln2 if i != 1])

import math
def cmb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

x = 0

for k in ln2:
    x += cmb(k, 2)
    
print(x)        

### FIXED CODE ###

N = int(input())
S = [''.join(sorted(list(input()))) for _ in range(N)]
 
from collections import Counter
a=Counter(S)
 
ans = 0
 
for i in a.values():
    if i>1:
        ans += i*(i-1)/2
 
print(int(ans))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,X=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]

A.sort(key=lambda x:x[2]*(X-x[0])+x[0]*x[1],reverse=True)
ALL=[a[2]*(X-a[0])+a[0]*a[1] for a in A]

from itertools import accumulate

SUM=[0]+list(accumulate(ALL))

MAX=0
MINUS=0

for a,r,l in A:
    MAX+=a
    MINUS+=a*r

OUT=-1

def binsearch(score):

    alluse=score//X
    rest=score-alluse*X

    for ri in range(N):
        plus=0
        b,l,u=A[ri]
        
        if rest<b:
            plus+=rest*l
        else:
            plus+=rest*u+b*l-b*u

        if alluse<=ri:
            plus+=SUM[alluse]

        else:
            plus+=SUM[alluse+1]-ALL[ri]

        #print(score,ri,plus)

        if plus>=MINUS:
            return 1

    return 0


while MAX-OUT>1:
    mid=(MAX+OUT)//2

    if binsearch(mid)==1:
        MAX=mid
    else:
        OUT=mid

print(MAX)

### FIXED CODE ###

import sys
input = sys.stdin.readline

from itertools import accumulate

def main():
    N,X=map(int,input().split())
    A=[list(map(int,input().split())) for i in range(N)]

    A.sort(key=lambda x:x[2]*(X-x[0])+x[0]*x[1],reverse=True)
    ALL=[a[2]*(X-a[0])+a[0]*a[1] for a in A]



    SUM=[0]+list(accumulate(ALL))

    MAX=0
    MINUS=0

    for a,r,l in A:
        MAX+=a
        MINUS+=a*r

    OUT=-1

    def binsearch(score):

        alluse=score//X
        rest=score-alluse*X

        for ri in range(N):
            plus=0
            b,l,u=A[ri]
            
            if rest<b:
                plus+=rest*l
            else:
                plus+=rest*u+b*l-b*u

            if alluse<=ri:
                plus+=SUM[alluse]

            else:
                plus+=SUM[alluse+1]-ALL[ri]

            #print(score,ri,plus)

            if plus>=MINUS:
                return 1

        return 0


    while MAX-OUT>1:
        mid=(MAX+OUT)//2

        if binsearch(mid)==1:
            MAX=mid
        else:
            OUT=mid

    print(MAX)

main()
### BUGGY CODE ###

import math
a,b,n=map(int,input().split())
m=[]
for x in range(n+1):
    f=math.floor(a*x/b)-a*math.floor(x/b)
    m.append(f)
print(max(m))

### FIXED CODE ###

a,b,n=map(int,input().split())
import math
if n<b:
    m=math.floor(a*n/b)
else:
    e=b-1
    m=math.floor(a*e/b)
print(m)
### BUGGY CODE ###

N=int(input())
S=[]
#A,B,C,D=map(int,input().split())
count=0
for i in range(N):
	s=input()
	if s not in S:
		S.append(s)
		count+=1
print(count)

### FIXED CODE ###

N=int(input())
S={0}
#A,B,C,D=map(int,input().split())

for i in range(N):
	S.add(input())
print(len(S)-1)
### BUGGY CODE ###

NN = 2020202
MOD = 10**9+7
INF = float("inf")


n, p = map(int, input().split())
S = input()
pl = len(str(p))
ans = 0
d = [0]*p

for i in range(len(S)):
    d[0] += 1
    nd = [0]*p
    a = int(S[i])
    for k, v in enumerate(d):
        ne = (k*10+a)%p
        nd[ne] += v
    ans += nd[0]
    d = nd
    # print(d)

print(ans)


### FIXED CODE ###

NN = 2020202
MOD = 10**9+7
INF = float("inf")

n, p = map(int, input().split())
S = input()
pl = len(str(p))

if p == 2 or p == 5:
    count = 0
    for i in range(len(S)):
        if int(S[i])%p == 0:
            count += i+1
            # print(int(S[i]), count)

    print(count)

else:
    d = [0] * p
    d[0] = 1
    val = 0
    dec = 1

    for i in range(len(S)-1, -1, -1):
        val = (int(S[i])*dec+val)%p
        dec = (dec*10)%p
        d[val] += 1

    # print(d)
    ans = 0
    for e in d:
        ans += (e*(e-1))//2
    print(ans)
### BUGGY CODE ###

s = list(input())
num_list = [s[:i].count("B") if s[i] == "W" else 0 for i in range(1, len(s))]
print(str(sum(num_list)))


### FIXED CODE ###

s = list("BWBWBW" * 10000)

s = list(input())
ret, counter = 0, 0
for a in s:
    if a == "B":
        counter += 1
    else:
        ret += counter
print(str(ret))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2 * 10**5)


n, q = map(int, input().split())
GRAPH = [[] for _ in range(n + 1)]
COUNTS = [0] * (n + 1)

for _ in range(n - 1):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    COUNTS[p] += x

def dfs(now, prev):
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        else:
            next = vertex
        COUNTS[next] += COUNTS[now]
        dfs(next, now)
dfs(1, 0)

answer = " ".join(map(str, COUNTS[1:]))
print(answer)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline()


n, q = map(int, input().split())
GRAPH = [[] for _ in range(n + 1)]
COUNTS = [0] * (n + 1)

for _ in range(n - 1):
    a, b = map(int, input().split())
    GRAPH[a].append(b)
    GRAPH[b].append(a)

for _ in range(q):
    p, x = map(int, input().split())
    COUNTS[p] += x

def dfs(now, prev):
    for vertex in GRAPH[now]:
        if vertex == prev:
            continue
        else:
            next = vertex
        COUNTS[next] += COUNTS[now]
        dfs(next, now)
dfs(1, 0)

answer = " ".join(map(str, COUNTS[1:]))
print(answer)
### BUGGY CODE ###

import heapq
N, M, s, t = map(int, input().split())
s, t = s - 1, t - 1
G_yen = [[] for i in range(N)]
G_snuuk = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u - 1, v - 1
    G_yen[u].append([v, a])
    G_yen[v].append([u, a])
    G_snuuk[u].append([v, b])
    G_snuuk[v].append([u, b])


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


d_yen = dijkstra(s, G_yen)
d_snuuk = dijkstra(t, G_snuuk)

ans = 10 ** 15
ans_list = []
for i in reversed(range(N)):
    ans = min(ans, d_yen[i] + d_snuuk[i])
    ans_list.append(10 ** 15 - ans)

print(*ans_list[::-1], sep='\n')


### FIXED CODE ###

import heapq
N, M, S, T = map(int, input().split())
S, T = S-1, T-1
G1 = [[] for i in range(N)]
G2 = [[] for i in range(N)]
for i in range(M):
    u, v, a, b = map(int, input().split())
    u, v = u-1, v-1
    G1[u].append((v, a))
    G1[v].append((u, a))
    G2[u].append((v, b))
    G2[v].append((u, b))


def dijkstra(x, G):
    d = [float('inf')] * N
    d[x] = 0
    visited = {x}

    # d, u
    hq = [(0, x)]

    while hq:
        u = heapq.heappop(hq)[1]
        visited.add(u)

        for node, cost in G[u]:
            if (node not in visited) and d[node] > d[u] + cost:
                d[node] = d[u] + cost
                heapq.heappush(hq, (d[u]+cost, node))
    return d


toChange = dijkstra(S, G1)
toGoal = dijkstra(T, G2)

ans = [float('inf')]
for i in range(N-1, -1, -1):
    ans.append(min(ans[-1], toChange[i] + toGoal[i]))

del ans[0]
money = 10 ** 15
for cost in ans[::-1]:
    print(money - cost)
### BUGGY CODE ###

H, W, D = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(H)]
Q, = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(Q)]

pos = {}
for i, row in enumerate(A):
    for j, x in enumerate(row):
        pos[x] = (i, j)

for l, r in LR:
    result = 0
    x = l
    while x < r:
        y = x + D
        p1 = pos[x]
        p2 = pos[y]
        result += abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
        x += D
    print(result)


### FIXED CODE ###

H, W, D = [int(_) for _ in input().split()]
A = [[int(_) for _ in input().split()] for i in range(H)]
Q, = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for i in range(Q)]

"""
H, W, D = 300, 300, 1
Q = 1
A = [[j + i * 300 + 1 for j in range(300)] for i in range(300)]
LR = [[0, 300*300-1], [0, 300*300-1], [0, 300*300-1]]
"""

pos = {}
for i, row in enumerate(A):
    for j, x in enumerate(row):
        pos[x] = (i, j)

dt = [0] * (H * W + 1)
for x in range(1, D + 1):
    r = 0
    while 1:
        dt[x] = r
        y = x + D
        if y > H * W:
            break
        p1 = pos[x]
        p2 = pos[y]
        r += abs(p1[0] - p2[0]) + abs(p1[1] - p2[1])
        x = y

for l, r in LR:
    print(dt[r] - dt[l])
### BUGGY CODE ###

import copy

N = int(input())
As = list(map(int, input().split()))
As = [0] + As + [0]


def dist(a, b):
    return abs(a - b)


dAs = [dist(As[i], As[i+1]) for i in range(N+1)]


def rem(i):
    ret = copy.deepcopy(dAs)
    print('copy', ret)
    ret[i] = dist(As[max(0, i-1)], As[i+1])
    print('rett', ret, i)
    ret = ret[:max(0, i-1)] + ret[i:]
    print('As', As)
    print('ret', ret)
    return ret

def calc(i):
    return sum(dAs) - dist(As[i], As[i-1]) - dist(As[i+1], As[i]) + dist(As[i+1], As[i-1])


for i in range(1, N+1):
    print(calc(i))


### FIXED CODE ###

import copy
import time


N = int(input())
As = list(map(int, input().split()))
As = [0] + As + [0]

t0 = time.time()

def dist(a, b):
    return abs(a - b)


dAs = [dist(As[i], As[i+1]) for i in range(N+1)]
sumdAs = sum(dAs)
# print(time.time()-t0, 'a')

def rem(i):
    ret = copy.deepcopy(dAs)
    print('copy', ret)
    ret[i] = dist(As[max(0, i-1)], As[i+1])
    print('rett', ret, i)
    ret = ret[:max(0, i-1)] + ret[i:]
    print('As', As)
    print('ret', ret)
    return ret

def calc(i):
    return sumdAs - dist(As[i], As[i-1]) - dist(As[i+1], As[i]) + dist(As[i+1], As[i-1])


for i in range(1, N+1):
    print(calc(i))
### BUGGY CODE ###

import math
import copy

def first(a):
 a=A

N=int(input())
A=list(map(int,[input() for i in range(N)]))


for i in range(N):
  temp=copy.copy(A)
  temp.pop(i)
  print(max(temp))

### FIXED CODE ###

n = int(input())
list = [int(input()) for i in range(n)]
list2 = sorted(list)
m1 = list2[-1]
m2 = list2[-2]
 
for i in list:
    if i == m1:
        print(m2)
    else:
        print(m1)
### BUGGY CODE ###

n,m=map(int,input().split())
A=list(map(int,input().split()))
B=[];C=[];Q=[]
A.sort()
for i in range(m):
    b,c=map(int,input().split())
    Q.append([b,c])

import bisect as bi

#Qの統合
s=set([l[1] for l in Q])
dicts={}
for i in s:
    dicts[i]=0
for l in Q:
    dicts[l[1]]+=l[0]
Q=[[j,i] for i,j in dicts.items()]
Q=sorted(Q, key=lambda x:x[1], reverse=1)
######
#print(Q)

for l in Q:
    b,c=l
    a=bi.bisect_left(A,c)
    if A[0]>=c:
        break
    if a< b:
        A=[c]*a + A[a:]
        break
    
    A= A[b:a]+ [c]*b + A[a:]
    #print(A)
print(sum(A))

### FIXED CODE ###

n,m=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
Q=[]
for i in range(m):
    b,c=map(int,input().split())
    Q.append([b,c])

Q=sorted(Q, key=lambda x:x[1], reverse=1)
kae=0

d=[-1]*(n)
now=0
for l in Q:
    b,c=l
    if n-now<b:
        d[now:]=[c]*(n-now)
        break
    d[now:now+b]=[c]*b
    now+=b

#print(d)
ans=sum(A)
now=ans
for kae in range(1,n+1):
    now+=d[kae-1]
    now-=A[kae-1]
    ans=max(ans,now)
print(ans)
### BUGGY CODE ###

class Osa_k:
    def __init__(self, n_max):
        self.n_max = n_max
        self.min_factor = min_factor = list(range(n_max + 1))
        min_factor[2::2] = [2] * (n_max // 2)
        min_factor[3::6] = [3] * ((n_max + 3) // 6)
        for i in range(5, int(n_max ** .5) + 1, 2):
            if min_factor[i] == i:
                for j in range(i*i, n_max + 1, i):
                    if min_factor[j] == j:
                        min_factor[j] = i

    def __call__(self, n):
        min_factor = self.min_factor
        t = []
        while n > 1:
            if t and t[-1][0] == min_factor[n]:
                t[-1][1] += 1
            else:
                t.append([min_factor[n], 1])
            n //= min_factor[n]
        return t

def f(K):
    res = 1
    for _, i in K:
        res *= i + 1
    return res

P = Osa_k(10**7)
print(sum(i * f(P(i)) for i in range(1, int(input()) + 1)))


### FIXED CODE ###

n = int(input())
print(sum(n//i * (i + n//i*i)//2 for i in range(1, n + 1)))
### BUGGY CODE ###

from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
n,k = map(int, stdin.readline().rstrip().split())
p = list(map(int, stdin.readline().rstrip().split()))

m = 0
l =[]

for i in range(n-k+1):
    q = p[i:i+k]
    s = sum(q)
    if m < s:
        m = s
        l = q

ans = 0

for i in l:
    ans += (i+1) / 2

print(ans)


### FIXED CODE ###

from sys import stdin
#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
N,K = map(int, stdin.readline().rstrip().split())
P = list(map(int, stdin.readline().rstrip().split()))

Q = [(p+1)/2 for p in P]
c = [0]
for q in Q:
    c.append(c[-1] + q)

ans = 0
for i in range(K,N+1):
    ans = max(ans, c[i] - c[i-K])
print(ans)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jun 16 20:56:46 2019

@author: Yamazaki Kenichi
"""

N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9 + 7

A = [[1 for j in range(M+1)]]
A += [[0 for j in range(M+1)] for i in range(N)]
A += [[1 for j in range(M+1)]]
for i in range(N):
#    print(i,j)
    for j in range(M):
#        print(i,j)
        if T[j] == S[i]:
            A[i+1][j] = A[-1][j-1] % mod
        else:
            A[i+1][j] = A[i+1][j-1] % mod
        A[-1][j] += A[i+1][j]
        A[-1][j] %= mod
#        print(A)
ans = A[-1][-2]
print(ans)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jun 16 22:15:18 2019

@author: Yamazaki Kenichi
"""

N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9 + 7

A = [[1 for j in range(M+1)]]
A += [[0 for j in range(M+1)]]
#A += [[0 for j in range(M+1)] for i in range(N)]
A += [[1 for j in range(M+1)]]
for i in range(N):
#    print(i,j)
    tmp2 = 0
    for j in range(M):
#        print(i,j)
        if T[j] == S[i]:
            tmp = A[-1][j-1] % mod
#            A[i+1][j] = A[-1][j-1] % mod
        else:
            tmp = tmp2 % mod
#            A[i+1][j] = A[i+1][j-1] % mod
        tmp2 = tmp
        A[-1][j] += tmp
#        A[-1][j] += A[i+1][j]
        A[-1][j] %= mod
#        print(A)
ans = A[-1][-2] % mod
print(ans)
### BUGGY CODE ###

X = int(input())
result = []
i = X
while i >= X:
    i += 1
    if i > 1:
        for j in range (2, i):
            if (i % j) == 0:
                break
        else:
            result.append(i)
print (min(result))

### FIXED CODE ###

X = int(input())
result = []
for i in range(X,X*2):
    for j in range (2,i):
        if (i % j) == 0:
            break
    else:
            result.append(i)
            a = i
            break
print (a)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if (x,y) not in finished:
            finished.add((x,y))
            for i in range(-1,2,1):
                for j in range(-1,2,1):
                    if abs(i) + abs(j) < 2 and check(y+j,x+i):
                        que.append([x+i,y+j,grid[y+j][x+i]])
                        if color != grid[y+j][x+i]:
                            adjacent_list[x+w*y].append((x + i)+w*(y + j))
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
black = 0
white = 0
#x,y渡すと、（ｈ、ｗ）に入ってるかどうか判定
def check(s,t):
    if (0 <=  s <= h - 1) and (0 <= t <= w - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, color = que.popleft()
        if x+y*w not in finished:
            finished.add(x+y*w)
            for i in range(-1,2,1):
                for j in range(-1,2,1):
                    if abs(i) + abs(j) < 2 and check(y+j,x+i):
                        if (x+i)+(y+j)*w not in finished:
                            que.append([x+i,y+j,grid[y+j][x+i]])
                        if color != grid[y+j][x+i]:
                            adjacent_list[x+w*y].append((x + i)+w*(y + j))
def dfs(node):
    global white
    global black
    finished.add(node)
    y,x = divmod(node,w)
    if grid[y][x] == '#':
        black += 1
    else:
        white += 1
    for i in adjacent_list[node]:
        if i not in finished:
            dfs(i)
from collections import deque
h,w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
ans = 0
adjacent_list = [[] for i in range(h*w)]
"""
que = deque()
que.append([0,0,grid[0][0]])
bfs(que)
"""
for y in range(h):
    for x in range(w):
        for i in range(-1,2,1):
            for j in range(-1,2,1):
                if abs(i) + abs(j) < 2 and check(y+j,x+i):
                    if grid[y][x] != grid[y+j][x+i]:
                        adjacent_list[x+w*y].append((x + i)+w*(y + j))
#再び初期化
finished = set()
for i in range(h*w):
    #頂点iからdfsをする。黒と白をカウントしておいて最後にかける
    black = 0
    white = 0
    if i not in finished:
        dfs(i)
        ans += black * white
print(ans)