Harryxun/stf_run huggingface dataset:
n = int(input())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
res = 0
for i in range(n):
    res += min(a[i], b[i])
    b[i] = max(0, b[i] - a[i])
    res += min(b[i], a[i + 1])
    a[i + 1] = max(0, a[i + 1] - b[i])
print(res)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
for i in range(n):
    res += min(a[i], b[i])
    b[i] = max(0, b[i] - a[i])
    res += min(b[i], a[i + 1])
    a[i + 1] = max(0, a[i + 1] - b[i])
print(res)
N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i] = i*N - i*(i-1) + 1

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)


### FIXED CODE ###

N,K = map(int,input().split())
cnt = [0]*(N-K+2)

cnt_all = 0
mod = 1000000007

for i in range(K,N+2):
    cnt[i-K] = i*N - i*(i-1) + 1

for i in range(N-K+2):
    cnt_all += cnt[i]

print(cnt_all % mod)
from sys import stdin

n, m = (int(x) for x in stdin.readline().rstrip().split())
s = int()
e = int()
for i in range(m):
    line = stdin.readline().rstrip().split()
    if i == 0:
        s = int(line[0])
        e = int(line[1])
    else:
        if s <= int(line[0]) <= e:
            s = int(line[0])
        if s <= int(line[1]) <= e:
            e = line[1]

print(len([i for i in range(s, e+1) if 1 <= i <= n]))


### FIXED CODE ###

from sys import stdin

n, m = (int(x) for x in stdin.readline().rstrip().split())
lr = [stdin.readline().rstrip().split() for _ in range(m)]
l = max([int(i[0]) for i in lr])
r = min([int(i[1]) for i in lr])

if l <= r:
    print(r-l+1)
else:
    print(0)
N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(X):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(X + (N - sum_min) // use_min)

### FIXED CODE ###

N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(N):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(N + (X - sum_min) // use_min)
from fractions import gcd
n,x=map(int,input().split())
h=[abs(x-int(a)) for a in input().split()]
print(reduce(gcd,h))

### FIXED CODE ###

from fractions import gcd
from functools import reduce
n,x=map(int,input().split())
h=[abs(x-int(a)) for a in input().split()]
print(reduce(gcd,h))
a = float(input())
b =float(input())
print(a+b)
print(a*b)


### FIXED CODE ###

a,b = map(int,input().split())
print(a*b,2*(a+b))
S = str(input())
li = [i for i in S]
li_2 = list(set(li))
li_2.sort()
ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
ascii_lowercase_list = list(ascii_lowercase)
for i in range(0,len(S),1):
  if li_2[i] != ascii_lowercase_list[i]:
    print(ascii_lowercase_list[i])
    break
  elif i+1 == len(S):
    print("None")
    break


### FIXED CODE ###

S = list(set(input()))
S.sort()
tmp = "abcdefghijklmnopqrstuvwxyz"
for i in range(0,len(tmp),1):
    if tmp[i] not in S:
        print(tmp[i])
        exit()
print("None")
while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n???+ 1):
        for m in range(s + 1, n):
            for e in range(m + 1, n + 1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)

### FIXED CODE ###

while True:
    n, x = [int(i) for i in input().split()]

    if n == x == 0:
        break

    count = 0
    for s in range(1, n+1):
        for m in range(s+1, n):
            for e in range(m+1, n+1):
                if x == sum([s, m, e]):
                    count += 1

    print(count)
n = int(input())
s, t = ISS()
S =""
for i in range(n):
	S+=s[i]+t[i]
print(S)


### FIXED CODE ###

import sys

def ISS(): return sys.stdin.readline().rstrip().split()

n = int(input())
s, t = ISS()
S =""
for i in range(n):
	S+=s[i]+t[i]
print(S)
import copy

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

Y=sorted(X.copy())

a=Y[N//2-1]
b=Y[N//2]

for i in range(N):
    if X[i]<=a:
        print(b)
    else:
        print(a)

### FIXED CODE ###

import copy

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

Y=sorted(X.copy())

a=Y[N//2-1]
b=Y[N//2]

for i in range(N):
    if X[i]<=a:
        print(b)
    else:
        print(a)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def s(x):
    a = []
    aa = x[i]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

h,w = m()

a = []
aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    a.append(k)
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa.pop(0)
        if not c == 0:
            if aa[c-1][v] != min(aa[c][v]+1,aa[c-1][v]) and a[c-1][v] != "#":
                a[c-1][v] = "#"
                aa[c-1][v] = min(aa[c][v]+1,aa[c-1][v])
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] != min(aa[c][v]+1,aa[c+1][v])and a[c+1][v] != "#":
                a[c+1][v] = "#"
                aa[c+1][v] = min(aa[c][v]+1,aa[c+1][v])
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] != min(aa[c][v]+1,aa[c][v-1])and a[c][v-1] != "#":
                a[c][v-1] = "#"
                aa[c][v-1] = min(aa[c][v]+1,aa[c][v-1])
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] != min(aa[c][v]+1,aa[c][v+1])and a[c][v+1] != "#":
                a[c][v+1] = "#"
                aa[c][v+1] = min(aa[c][v]+1,aa[c][v+1])
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)
        




### FIXED CODE ###

import sys
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa[i]
        if not c == 0:
            if aa[c-1][v] > aa[c][v]+1:
                aa[c-1][v] = aa[c][v]+1
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] > aa[c][v]+1:
                aa[c+1][v] = aa[c][v]+1
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] > aa[c][v]+1:
                aa[c][v-1] = aa[c][v]+1
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] > aa[c][v]+1:
                aa[c][v+1] = aa[c][v]+1
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)
a,b = map(int,input().split());print(sum(range(b-a))-a)


### FIXED CODE ###

N = int(input())

if N<=999:print('ABC')
else:print('ABD')
l=[1,2,3]
for i in range(2):
    l.remove(int(input))
print(l[0])

### FIXED CODE ###

l=[1,2,3]
for i in range(2):
	l.remove(int(input()))
print(l[0])
if S == ABC:
  print(ARC)
 
else:print(ABC)

### FIXED CODE ###

S = input()
if S == 'ARC':
  print("ABC")
else:print('ARC')
n = int(input())
nums = list(map(int, input().split()))
sum = 1
i = 0
flag = 0
upper = pow(10, 18)
for i in nums:
  sum *= nums[i]
  if sum > upper:
    print(-1)
    flag = 1
    break
if flag == 0:
    print(sum)

### FIXED CODE ###

n = int(input())
nums = list(map(int, input().split()))
sum = 1
flag = 1
upper = pow(10, 18)
for num in nums:
  if num == 0:
    sum = 0
    flag = 1
    break
  if flag == 1:
    sum = sum * num
    if sum > upper:
      flag = 2

if flag == 1:
  print(sum)
elif flag == 2:
  print(-1)
X, Y = map(int,input().split())

for i in range(X) :
    if Y -(4*((i+1) == (X-(i+1))*2 :
        print("Yes")
        exit()
    else :
        if Y==2 or Y==4 :
            print("Yes")
            exit()
print("No")

### FIXED CODE ###

X, Y = map(int,input().split())
XX = X +1
for i in range(XX) :
    if Y -(4*i) == (X-i)*2 :
        print("Yes")
        exit()

print("No")
N, M = map(int, input().split())
a_n = [int(x/2) for x in input().split()]

def lcm(lis):
    from fractions import gcd
    x = lis[0]
    for i in range(1, len(lis)):
        x = (x * lis[i]) // gcd(x, lis[i])
    return x
res = lcm(a_n)
count = 0
for i in range(int(M/res)-1):
    count += 1
print(count)

### FIXED CODE ###

N,M = map(int, input().split())
a_n = list(map(int, input().split()))
g = a_n.copy()
 
while not any(x%2 for x in g): g = [x//2 for x in g]
if not all(x%2 for x in g): print(0); exit(0)
def gcd(a,b):
  while b: a,b = b,a%b
  return a
lcm = lambda a,b: a*b//gcd(a,b)
tot = 1
for x in a_n: tot = lcm(tot,x//2)
print((M//tot+1)//2)
D = 3 * r**2

### FIXED CODE ###

r = int(input())
D = 3 * (r**2)
print(D)
a=list(map(int,input().split()))

if (max(a)-a[0])%2==0 and (max(a)-a[1])%2==0 and (max(a)-a[2])%2==0
    print(int((max(a)*3-sum(a))/2))
else:
    print(int((max(a)*3-sum(a))/2)+2)

### FIXED CODE ###

a=list(map(int,input().split()))
a.sort()

if (max(a)-a[0])%2==0 and (max(a)-a[1])%2==0:
    print(int((max(a)*3-sum(a))/2))
elif (a[2]-a[0])%2==1 and (a[2]-a[1])%2==1:
    print(int((max(a)*3-sum(a))/2))
else:
    print(int((max(a)*3-sum(a))/2)+2)
#!/usr/bin/env python
import math
N = int(input())
A = list(map(int, input().split()))
A.sort()

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

if N == 2:
    print(max(A))
else:
    min1 = min(A)
    div1 = make_divisors(min1)
    c = 0
    for i in div1:
        for a in A:
            if a % i == 0:
                c += 1
        if c == N-1 or c == N:
            g = i
            break
        c = 0

    m = 0
    for i in range(1, N-1):
        gcd = math.gcd(A[i], A[i+1])
        if gcd > m:
            m = gcd
    print(max(g, m))


### FIXED CODE ###

#!/usr/bin/env python
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

L = []
R = []
k = 0
for i in range(N):
    k = gcd(k, A[i])
    L.append(k)
k = 0
for j in range(N)[::-1]:
    k = gcd(k, A[j])
    R.append(k)
R[:] = R[::-1]

ans = 0
for i in range(N):
    if i == 0:
        ans = R[1]
    elif i == N-1:
        ans = max(ans, L[N-2])
    else:
        ans = max(ans, gcd(L[i-1], R[i+1]))
print(ans)
n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    start = s[l-1:r].find('A')
    end = s[l-1:r].rfind("C")
     if start == -1 or end== -1:
        print(0)
        pass
    cand = s[l-1:r][start:end+1]
    print(cand.count("AC"))

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

t = [0] * (N)
for i in range(N-1):
    t[i+1] = t[i] + (1 if S[i:i+2]=="AC" else 0)

for j in range(Q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])
N = int(input())
total = 0
for _ in range(N):
  x, u = input().split()
  i = int(x)
  if u == "JPY":
    tptal += i
  else:
    total += i*380000.0
print(total)    

### FIXED CODE ###

N = int(input())
total = 0
for _ in range(N):
  x, u = input().split()
  i = float(x)
  if u == "JPY":
    total += i
  else:
    total += i*380000
print(total)
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif ans[s] is not c:
        print(-1)
        exit(-1)
if ans[0] == 0:
    print(-1)
    exit(-2)

a = 0
for i in range(N):
    if ans[i] is -1:
        ans[i] = 0
    a += ans[i]*10**(N-i-1)

print(a)


### FIXED CODE ###

N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]

ans = [-1] * N

for i in range(M):
    s = sc[i][0] - 1
    c = sc[i][1]
    if ans[s] is -1:
        ans[s] = c
    elif not ans[s] == c:
        print(-1)
        exit()

if N!=1 and ans[0] == 0:
    print(-1)
    exit()

a = 0
for i in range(N):
    if ans[i] is -1:
        if i == 0 and N!= 1:
            ans[i] = 1
        else:
            ans[i] = 0
    a += ans[i]*10**(N-i-1)

print(a)
A = list(map(int,input().split))
B = (A[0]+A[1])/2
if B >= int(B):
  print(int(B)+1)
else:
  print(B)

### FIXED CODE ###

A = list(map(int,input().split()))
B = (A[0]+A[1])/2
if B > int(B):
  print(int(B)+1)
else:
  print(int(B))
l=map(int,raw_input().split())
l.sort()
if l[2]-l[1]==l[1]-l[0]:
	print('YES')
else:
	print('NO')

### FIXED CODE ###

a,b,c=input().split()
d=[]
d.append(int(a))
d.append(int(b))
d.append(int(c))
if d[2]-d[1]==d[1]-d[0]:
	print('YES')
else:
	print('NO')
s = input()
if s=="AAA" | s=="BBB":
    print("No")
else: 
    print("Yes")

### FIXED CODE ###

s = input()
if (s in "AAA") | (s in "BBB"):
    print("No")
else: 
    print("Yes")
N = int(input())
A = input().split(' ')
a = 0
sum = 0
for i in range(1, N):
    sum += int(A[i])
for i in range(N):
    a += int(A[i]) *  sum
    if i < N - 1:
        sum -= int(A[i + 1])
    
print(int(a % (1e9 + 7)))

### FIXED CODE ###

line = input().split(' ')
D = float(line[0])
T = float(line[1])
S = float(line[2])

if D / S <= T:
    print("Yes")
else:
    print("No")
n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(n+10):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
	amari=k%n
    ans=li[amari-1]
	print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n+10)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
    print(next+1)
n,m = map(int,input().split())
a = list(map(int,input().split()))
for i in a:
    n -= i
    if n<0:
        print(-1)
        exit()
print(n)

### FIXED CODE ###

R = int(input())

a = 2*3.1426*R

print(a)
from math import sqrt, ceil
A, B = map(int, input().split())


def era_prime(N):
    temp = [True]*(N+1)
    temp[0] = temp[1] = False
    for i in range(2, ceil(sqrt(N+1))):
        if temp[i]:
            temp[i+i::i] = [False]*(len(temp[i+i::i]))
    primes = [n for n in range(N+1) if temp[n]]
    return primes


prime_list = era_prime(min(A, B))
ans = 1


for i in range(2, min(A, B)+1):
    if A % i == 0 and B % i == 0:
        if i in prime_list:
            ans += 1

print(ans)


### FIXED CODE ###

from math import sqrt, ceil
import fractions
A, B = map(int, input().split())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


ans = 1

tmp = make_divisors(fractions.gcd(A, B))

for x in tmp:
    if is_prime(x):
        ans += 1

print(ans)
n=int(input())
flag=0
if i in range(26):
    if j in  range(15):
        total=4*i+j*7
        if total==n:
            flag+=1
            break
if flag==0:
    print('No')
else:
    print('Yes')
        









### FIXED CODE ###

n=int(input())
flag=0
for i in range(26):
    for j in  range(15):
        total=4*i+j*7
        if total==n:
            flag+=1
            break
if flag==0:
    print('No')
else:
    print('Yes')
n = int(input())
if n % 2 == 1:
  print(0)
elif n == 0:
  print(1)
else:
  m = n // 2
  l = 1
  ans = 0
  while 5**l <= m:
    ans += m//(5**l)
    l += 1
print(ans)

### FIXED CODE ###

n = int(input())
if n % 2 == 1:
  print(0)
elif n == 0:
  print(0)
else:
  m = n // 2
  l = 1
  ans = 0
  while 5**l <= m:
    ans += m//(5**l)
    l += 1
  print(ans)
X,N = map(int,input().split())
p = list(map(int,input().split()))
min = 0
i = 0
count = 0
while True:
    if abs(X - i) == min:
        if i not in p:
            break
        elif i in p and min != 0:
            count += 1
            if count == 2:
                min += 1
                count = 0
                i = 0
        else:
            min += 1
            i = 0
    i += 1

print(i)

### FIXED CODE ###

x = list(map(int,input().split()))

for i in range(5):
    if x[i] == 0:
        print(i+1)
        exit()
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
min = 1
max = N
X = 0
for i in range(M):
    L[i], R[i] = map(int, input().split())
    if L[i] > min:
        min = L[i]
    if R[i] < max:
        max = R[i]
    if R[i] < min or L[i] > max:
        X +=1


if X = 0:
    print(max-min+1)
else:
    print(0)


### FIXED CODE ###

N, M = map(int, input().split())
L = [0] * M
R = [0] * M
min = 1
max = N
X = 0
for i in range(M):
    L[i], R[i] = map(int, input().split())
    if L[i] > min:
        min = L[i]
    if R[i] < max:
        max = R[i]
    if R[i] < min or L[i] > max:
        X +=1


if X == 0:
    print(max-min+1)
else:
    print(0)
n, k = map(int, input().split())
p = list(map(int, input().split()))
max = 0
ans = 0

for i in range(0,n-n%k):
    sum = 0
    for j in range(i,i+k):
        sum += p[j]
    if sum > max:
        e = []
        for j in range(i, i+k):
            e.append(p[j])

for i in range(k):
    x = 0
    for j in range(e[i]+1):
        x += j
    x /= e[i]
    ans += x    

print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))
e = []

for i in range(n):
    e.append(p[i] + 1)

sum_e = [0]

for i in range(1,n+1):
    sum_e.append(sum_e[i-1]+e[i-1])

ans = []

for i in range(n-k+1):
    ans.append(sum_e[i+k]-sum_e[i])

print(max(ans)/2)
n, m = map(int, input().split())
ll = [0] + [ 0 * n]
for i in range(m):
    a, b = map(int, input().split())
    ll[a] += 1
    ll[b] += 1
for l in ll[1:]:
    print()


### FIXED CODE ###

n, m = map(int, input().split())
ll = [[0]] + [ [] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    ll[a].append(b)
    ll[b].append(a)
for l in ll[1:]:
    print(len(l))
from sys import stdin
a,b,c=[x for x in stdin.readline().rstrip().split()]
print(max(int(a)+int(b+c),int(a+b)+int(c))

### FIXED CODE ###

from sys import stdin
a,b,c=[x for x in stdin.readline().rstrip().split()]
print(max(int(a)+int(b+c),int(a+b)+int(c),int(c+b)+int(a)))
S = list(input())
T = list(input())

i = 0
ans =[]

while i + len(T) < len(S):
    n = 0
    for s, t in zip(S[i:i+len(T)], T):
        if s != t:
            n += 1
    ans.append(n)
    i += 1

print(min(ans))

### FIXED CODE ###

S = list(input())
T = list(input())

i = 0
ans =[]

while i + len(T) <= len(S):
    n = 0
    for s, t in zip(S[i:i+len(T)], T):
        if s != t:
            n += 1
    ans.append(n)
    i += 1

print(min(ans))
def BS(A, N):
    A = list(map(int, A.split()))
    flag = 1
    count = 0 
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                unk = A[j]
                A[j] = A[j-1]
                A[j-1] = unk
                flag = 1
                count = count +1
    print(" ".join(map(str,A)))
    print(count)
 
N = int(input())
A = input()
BS(A, N)


### FIXED CODE ###

def BS(A, N):
    A = list(map(int, A.split()))
    flag = 1
    count = 0 
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                unk = A[j]
                A[j] = A[j-1]
                A[j-1] = unk
                flag = 1
                count = count +1
    print(" ".join(map(str,A)))
    print(count)
 
N = int(input())
A = input()
BS(A, N)
N,M = map(int,input().split())
array2 = [0 for i in range(M+1)]
for i in range(N):
  array = list(map(int,input().split()))
  array.pop[0]
  for j in array:
    array2[j] += 1
c = 0
for k in array2:
  if k == N:
    c += 1
print(c)
  

### FIXED CODE ###

N,M = map(int,input().split())
array2 = [0 for i in range(M+1)]
for i in range(N):
  array = list(map(int,input().split()))
  array.pop(0)
  for j in array:
    array2[j] += 1
c = 0
for k in array2:
  if k == N:
    c += 1
print(c)
H,W=map(int,input().split())
series = [[] for h in range(H)]
for h in range(H):
	series[h] = list(input())
check = [[0 for w in range(W)] for h in range(H)]
def Go(h,w,c):
	check[h][w]=c
	count = 0
	front = ""
	tmp=0
	if series[h][w] == "#":
		front = "."
	else:
		front = "#"
	if h >= 1:
		if series[h-1][w] == front and check[h-1][w] == 0:
			if series[h-1][w] == ".":
				count += Go(h-1,w,c)+1
			else:
				count += Go(h-1,w,c)
	if h < H-1:
		if series[h+1][w] == front and check[h+1][w] == 0:
			if series[h+1][w] == ".":
				count += Go(h+1,w,c)+1
			else:
				count += Go(h+1,w,c)
	if w >= 1:
		if series[h][w-1] == front and check[h][w-1] == 0:
			if series[h][w-1] == ".":
				count += Go(h,w-1,c)+1
			else:
				count += Go(h,w-1,c)
	if w < W-1:
		if series[h][w+1] == front and check[h][w+1] == 0:
			if series[h][w+1] == ".":
				count += Go(h,w+1,c)+1
			else:
				count += Go(h,w+1,c)
	return count

ans=0
c=1
for h in range(H):
	for w in range(W):
		if series[h][w] == "#":
			ans += Go(h,w,c)
			check = [[0 for w in range(W)] for h in range(H)]
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
H,W=map(int,input().split())
series = [[] for h in range(H)]
for h in range(H):
	series[h] = list(input())

def Go(h,w):
	#print(h,w)
	global c
	check[h][w]=1
	count = 0
	front = ""
	if series[h][w] == "#":
		front = "."
	else:
		front = "#"
	if h >= 1:
		if series[h-1][w] == front and check[h-1][w] == 0:
			if series[h-1][w] == ".":
				count += Go(h-1,w)+1
			else:
				count += Go(h-1,w)
				c += 1
				used[h-1][w] = 1
	if h < H-1:
		if series[h+1][w] == front and check[h+1][w] == 0:
			if series[h+1][w] == ".":
				count += Go(h+1,w)+1
			else:
				count += Go(h+1,w)
				c += 1
				used[h+1][w] = 1
	if w >= 1:
		if series[h][w-1] == front and check[h][w-1] == 0:
			if series[h][w-1] == ".":
				count += Go(h,w-1)+1
			else:
				count += Go(h,w-1)
				c += 1
				used[h][w-1] = 1
	if w < W-1:
		if series[h][w+1] == front and check[h][w+1] == 0:
			if series[h][w+1] == ".":
				count += Go(h,w+1)+1
			else:
				count += Go(h,w+1)
				c += 1
				used[h][w+1] = 1
	return count

ans=0
used =  [[0 for w in range(W)] for h in range(H)]
check = [[0 for w in range(W)] for h in range(H)]
for h in range(H):
	for w in range(W):
		if series[h][w] == "#" and used[h][w] == 0:
			c=1
			ans += Go(h,w) * c
print(ans)