Harryxun/stf_run huggingface dataset:
n,k = map(int,input().split())
A = list(map(int,input().split()))
if k==0:
    print(sum(A))
else:
    l = len(bin(k)[2:])
    digit = [0]*l
    for a in A:
        b = str(format(a, '0{}b'.format(l)))
        for e,c in enumerate(b):
            digit[e] += int(c)
    ret = ''
    for d in digit:
        if d > l//2:
            ret += '0'
        else:
            ret += '1'
    ret = int(ret, 2)
    ans = 0
    for a in A:
        ans += ret^a
    print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
A = list(map(int,input().split()))
cnt = [0]*50
L = format(k, 'b').zfill(50)
S = [[0,0] for _ in range(50)]
for a in A:
    a_ = format(a, 'b').zfill(50)
    for i in range(50):
        if a_[i]=='1':
            S[i][0] += 1
        else:
            S[i][1] += 1
for i in range(len(S)):
    S[i][0] *= pow(2, 50-i-1)
    S[i][1] *= pow(2, 50-i-1)

dp = [[-1,-1] for _ in range(55)]
dp[0][0] = 0

for i in range(50):
    
    if L[i] == '1':
        if dp[i][1] != -1:
            dp[i+1][1] = dp[i][1] + max(S[i][0], S[i][1])
        if dp[i][0] != -1:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0]+S[i][0])
            dp[i+1][0] = dp[i][0] + S[i][1]
        
            
    else:
        if dp[i][1] != -1:
            dp[i+1][1] = dp[i][1] + max(S[i][1], S[i][0])
        if dp[i][0] != -1:
            dp[i+1][0] = dp[i][0] + S[i][0]

print(max(dp[50]))
l = list(map(int, input().split()))
if l[1]+l[2] < l[0]:
    print("delicious")
else:
    if l[2]-l[1] <= l[0]:
        print("safe")
    else:
        print("dangerous")
c


### FIXED CODE ###

l = list(map(int, input().split()))
border = l[1] - l[2]
if border < 0:
    if l[0] >= abs(border):
        print("safe")
    else:
        print("dangerous")
else:
    print("delicious")
# coding: utf-8

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

kaijo_d = {0: 1}
already_max = 0


def f(n):
    global already_max
    if n < already_max:
        return kaijo_d[n]

    output = kaijo_d[already_max]

    for i in range(already_max+1, n+1):
        output *= i
        kaijo_d[i] = output

    already_max = n

    return output


for i in range(1, K+1):
    print((f(K-1) * f(N-K+1)) // (f(i-1) * f(K-i) * f(i) * f(N-K+1-i)) % (10**9 + 7))


### FIXED CODE ###

# coding: utf-8

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

kaijo_d = {0: 1}


def f(n):
    if n in kaijo_d.keys():
        return kaijo_d[n]

    already = max(kaijo_d.keys())

    output = kaijo_d[already]

    for i in range(already+1, n+1):
        output *= i
        kaijo_d[i] = output

    return output


for i in range(1, K+1):
    print((f(K-1) * f(N-K+1)) // (f(i-1) * f(K-i) * f(i) * f(N-K+1-i)) % (10**9 + 7))
p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
flag = 0
if T[N-1]!=A[0]:
    flag = 1
if flag==0:
    H[0] = T[0]
    for i in range(1,N):
        if T[i]<T[i-1]:
            flag = 1
            break
        if T[i]>T[i-1]:
            H[i] = T[i]
if flag==0:
    H[N-1] = A[N-1]
    for i in range(N-2,-1,-1):
        if A[i]<A[i+1]:
            flag = 1
            break
        if A[i]>A[i+1]:
            if H[i]>0 and H[i]!=A[i]:
                flag = 1
                break
            else:
                H[i]=A[i]
if flag==1:
    print(0)
else:
    hmax = max(H)
    cnt = 1
    cur = 0
    for i in range(1,N):
        if H[i]==hmax:
            indH=i
            break
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    cur = N-1
    for i in range(N-2,-1,-1):
        if H[i]==hmax:
            indA = i
            break
        if H[i]==0:
            cnt = (cnt*H[cur])%p
        elif H[i]>0:
            cur = i
    for i in range(indH+1,indA):
        cnt = (cnt*hmax)%p
    print(cnt)

### FIXED CODE ###

p = 10**9+7
N = int(input())
T = list(map(int,input().split()))
A = list(map(int,input().split()))
H = [0 for _ in range(N)]
cnt = 1
H[0] = T[0]
for i in range(1,N):
    if T[i]>T[i-1]:
        H[i] = T[i]
if H[-1]>0 and H[-1]!=A[-1]:
    cnt = 0
else:
    H[-1] = A[-1]
    for i in range(-2,-N-1,-1):
        if H[i]==0 and A[i]>A[i+1]:
            if A[i]<=T[i]:
                H[i] = A[i]
            else:
                cnt = 0
                break
        elif H[i]>0 and A[i]>A[i+1]:
            if H[i]==A[i]:continue
            else:
                cnt = 0
                break
    if cnt==1:
        for i in range(1,N-1):
            if H[i]==0:
                cnt = (cnt*min(T[i],A[i]))%p
print(cnt)
))

print("{:.0f}".format((a+b)/2))


### FIXED CODE ###

import math

a, b = map(float, input().split())

print(math.ceil((a+b)/2))
N,M =map(int,input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

ans = int(1)

A = [0]*(M+1)
A[0] = a[0]-1
A[M] = N - a[M-1]-1
for i in range(M-1):
    A[i+1] = a[i+1] - a[i]- 2
    if A[i+1]==-1:
        ans = 0
        print(ans)
        exit()

SA =[0]*N
SA[0] = int(1)
SA[1] = int(1)
for i in range(N-2):
    SA[i+2] = SA[i+1] + SA[i]
    SA[i+2] = SA[i+2]%1000000007

for i in range(M+1):
    ans *= SA[A[i]]
    ans = ans%1000000007


print(int(ans))


### FIXED CODE ###

def examC():
    N, M = LI()
    A = [I() for _ in range(M)]
    A.append(N+1)
    fib = [1]*(N+2)
    for i in range(1,N):
        fib[i+2] = fib[i+1] + fib[i]
    fib[0] = 0
#    print(fib)
    ans = fib[A[0]]%mod
    for i in range(M):
        ans *= fib[A[i+1]-A[i]-1]
        ans %=mod
    print(ans)
    return

def examD():
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()
N = int(input())
l = list(map(int,input().split()))
for n in range(N):
  if l[N-n-1] - l[N-n] > 1:
    print('No')
    break
  elif 0 < l[N-n-1] - l[N-n] <= 1:
    l[N-n-1] -= 1
  else:
print('Yes')

### FIXED CODE ###

import sys
N = int(input())
l = list(map(int,input().split()))
for n in range(N-2,0,-1):
  if l[n] > l[n+1]:
    l[n] -= 1
  if l[n] > l[n+1]:
    print('No')
    sys.exit()
print('Yes')
def make_divisors(n,m):
    divisors = []
    i=1
    while i*i<m:
      if m % i == 0:
          divisors.append(i)
          if i != m // i and m//i<=m//n:
              divisors.append(m//i)
      i+=1
    return divisors
n,m=map(int,input().split())
print(max(make_divisors(n,m)))


### FIXED CODE ###

def make_divisors(n,m):
    divisors = []
    for i in range(1,min(int(m**(1/2))+1,int(m//n)+1)):
      if m % i == 0:
          divisors.append(i)
          if i != m // i and m//i<=m//n:
              divisors.append(m//i)
    return divisors
n,m=map(int,input().split())
print(max(make_divisors(n,m)))
l = [int(i) for i in input().split()] 
ans = 0

for i in range(len(l) - 1):
	if l[i+1] < l[i]:
	tmp = l[i+1]
	l[i+1] = l[i]
	l[i] = tmp

for i in range(len(l) - 1):
	ans += l[i+1] - l[i]

print(ans)

### FIXED CODE ###

l = [int(i) for i in input().split()] 
ans = 0

for j in range(len(l) - 1):
	for i in range(len(l) - 1):
		if l[i+1] < l[i]:
			tmp = l[i+1]
			l[i+1] = l[i]
			l[i] = tmp
        
for i in range(len(l) - 1):
	ans += l[i+1] - l[i]
    
print(ans)
x = list(map(int,input()))
for i in range(5):
  if x[i]==0:
    print(i)

### FIXED CODE ###

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

for i in range(5):
  if X[i]==0:
    print(i+1)
k = int(input())
s = input()
if len(s) >= k:
  print(s)
else:
  print(s[:k] + '.' * (k - len(s))

### FIXED CODE ###

k = int(input())
s = input()
if len(s) <= k:
  print(s)
else:
  print(s[:k] + '...')
N = int(input())
h = list(map(int, input().split()))


# DP 最小化問題用 change minimum
# 2つの引数をとり，1つめより2つめが小さかったら更新する

def chmin(array, x):
    if (array > x):
        array = x
        return array
    return array


# DP 最大化問題用 change maximum

def chmax(array, x):
    if (array > x):
        array = x
        return True
    return False


#大きな値
INF = 9999

# DPtable
dp = [INF]*10000

#初期条件
dp[0] = 0

#ループ
for i in range(N):
    if i == 0:
        continue
    else:
        dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
        if i > 1:
            dp[i] = chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]))

# print(dp[0:N])
print(dp[N-1])


### FIXED CODE ###

# N = int(input())
# h = list(map(int, input().split()))
# 
# #大きな値
# INF = 9999
# 
# # DPtable
# dp = [INF]*9999
# 
# #初期条件
# dp[0] = 0
# dp[1] = abs(h[1]-h[0])
# 
# #ループ
# for i in range(N):
#     if i == 0 or i == 1:
#         continue
#     else:
#         dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i]-h[i-2]))
# 
# print(dp[N-1])

N = int(input())
h = list(map(int, input().split()))
dp = [10 ** 10 for _ in range(N)]
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[-1])
L,R = list(map(int,input().split()))

from collections import defaultdict

d = defaultdict(int)

for i in range(L,R+1):
  d[i%2019] += 1
  if d[0]>0:
    break

cnt = 0a
ans = list()
for k,v in sorted(d.items()):
  _v = v
  
  while _v > 0:
    cnt +=1
    ans += [k]
    _v -= 1
    if cnt >=2:
      print((ans[0]*ans[1])%2019)
      break
  if cnt >=2:
    break    

### FIXED CODE ###

L,R = list(map(int,input().split()))
from itertools import combinations

numbers = [i for i in range(L,min(R+1,L+2019))]
ans = 2019
for conb in combinations(numbers,2):
  if ans > (conb[0]*conb[1])%2019:
     ans = (conb[0]*conb[1])%2019
    
print(ans)
import sys

inf = sys.maxsize
N, K = map(int, input().split())
heights = list(map(int, input().split()))

dp = [inf]*N
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b] + diff:
        dp[a] = dp[b] + diff
    return


for i in range(N):
    for j in range(1, K+1):
        if i-j >= 0:
            chmin(i, i-j, abs(heights[i]-heights[i-j]))

print(dp[N-1])

### FIXED CODE ###

import sys

inf = sys.maxsize

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

# DPテーブルの初期化(最小問題なのでINFで初期化
dp = [inf] * N

# 初期条件
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b]+diff:
        dp[a] = dp[b]+diff
        return True
    return False

# 普通のDP
for i in range(1, N):
    chmin(i, i-1, abs(heights[i]-heights[i-1]))
    if i > 1:
        chmin(i, i-2, abs(heights[i]-heights[i-2]))
print(dp[N-1])


# # メモ化再帰
# def chmin(a, b):
#     if a > b:
#         a = b
#     return a
#
#
# def rec(i):
#     if dp[i] < inf:
#         return dp[i]
#     if i == 0:
#         return 0
#     res = inf
#     res = chmin(res, rec(i-1)+abs(heights[i]-heights[i-1]))
#     if i > 1:
#         res = chmin(res, rec(i-2)+abs(heights[i]-heights[i-2]))
#     dp[i] = res
#     return dp[i]
#
#
# print(rec(N-1))
A, B = input().split()

print(int(A)*round(float(b)*100)//100)

### FIXED CODE ###

a, b = map(str, open(0).read().split())
print(int(a)*int(b[:-3]+b[-2:]) // 100)
h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
dp = [0] * (h + 1)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])

### FIXED CODE ###

h, n = (int(x) for x in input().split())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])
max_a = max(a for a, _ in ab)
dp = [0] * (h + max_a)
for i in range(1, h + 1):
    dp[i] = min(dp[i - a] + b for a, b in ab)
print(dp[h])
s = input()
if s == "a" or s=="i" or s=="u" or s=="e" or s=="o":
  print(vowel)
else:
  print(consonant)

### FIXED CODE ###

s = input()
if s == "a" or s=="i" or s=="u" or s=="e" or s=="o":
  print("vowel")
else:
  print("consonant")
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j += 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print [x[n][s],0][s>=50]

### FIXED CODE ###

x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j+= 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]
N, A, B= map(int,input().split())

print(min(N*A, B)

### FIXED CODE ###

N, A, B= map(int,input().split())
 
print(min(N*A, B))
s = input().split()

n = len(s[0]) - len(s[1]) + 1
min = len(s[1])
 
for a in range(n):
  count = 0 
	for b in range(len(s[1])):
      if s[0][a+b] != s[1][b]:
        count += 1
  if count < min:
    min = count
print(min)

### FIXED CODE ###

x = [input() for i in range(2)]
S = x[0]
T = x[1]
moji = len(T)

for a in range(len(S) - len(T) + 1):
  count = 0
  for b in range(len(T)):
    
    if S[a+b] != T[b]:
      count += 1
  if count < moji:
    moji = count

print(moji)
n=int(input())
a=list(map(int,input(),split()))
count=0
for i in range(n):
    if a[i]%4==0:
        count+=1

if n//2<=count:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
count4=0#4の倍数
count2=0#2の倍数だが4の倍数じゃない
count1=0
for i in range(n):
    if a[i]%4==0:
        count4+=1
    elif a[i]%2==0:
        count2+=1
    else:
        count1+=1
if count2==0:
    if count1<=count4+1:
        print("Yes")
    else:
        print("No")
else:
    if count1<=count4:
        print("Yes")
    else:
        print("No")

    

    
"""
#print(count2)
if 1<=count2:
    if (n-count2//2)//2<=count or n//2<=count:
        print("Yes")
    elif count2%2==0:
        if   (n-count2)//2<count :
            print("Yes ")
        else:
            print("No")
    elif count2%2==1:
        if  (n-count2)//2<=count :
            print("Yes ")
        else:
            print("No")
else:
    if n//2<=count:
        print("Yes")
    else:
        print("No")

    """
"""    7
    2 2 2 2 3 4 3

    YES になる間違い13晩のテキスト

"""
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque, defaultdict
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def divisor(n):
    ret = list()
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            # ret.append(n // i) if i * i != n else None
    return sorted(ret)


def main():
    S = ii()
    X1, Y1 = 0, 0
    for i in range(floor(sqrt(S)) - 3, floor(sqrt(S)) + 1000):
        if i * i >= S:
            if (i ** 2 - S) // divisor(i ** 2 - S)[-1] > 10**9:
                continue
            else:
                n = i
                break
    print(0, 0, n, divisor(n ** 2 - S)[-1], (n ** 2 - S) // divisor(n ** 2 - S)[-1], n)

if __name__ == '__main__':
    main()


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque, defaultdict
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def divisor(n):
    ret = list()
    for i in range(1, int(sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            # ret.append(n // i) if i * i != n else None
    return sorted(ret)


def main():
    S = ii()
    X1, Y1 = 0, 0
    if (S <= 10 ** 9):
        print(0, 0, S, 0, 0, 1)
        sys.exit()
    for i in range(floor(sqrt(S)) - 3, floor(sqrt(S)) + 1000):
        if i * i >= S:
            if i * i == S:
                print(0, 0, i, 0, 0, i)
                sys.exit()
            if (i ** 2 - S) // divisor(i ** 2 - S)[-1] > 10**9:
                continue
            else:
                n = i
                break
    print(0, 0, n, divisor(n ** 2 - S)[-1], (n ** 2 - S) // divisor(n ** 2 - S)[-1], n)

if __name__ == '__main__':
    main()
s = input()
n = len(s)
if n%2==1 or s[:n//2]==s[n//2:] :
    print("No")
else:
    print("Yes")
return 0

### FIXED CODE ###

n = int(input())
s = input()
if n%2==1 or s[:n//2]!=s[n//2:] :
    print("No")
else:
    print("Yes")
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

memory = {}


def solve(N: int, C: "List[int]"):
    # print(dfs(tuple(C), N, 0))

    dp = [0]*N
    last = [-1]*2*N
    for i, s in enumerate(C):
        if i == 0:
            dp[i] = 1
        else:
            dp[i] = dp[i-1]
            if last[s] != -1 and last[s] < i-1:
                dp[i] = (dp[i] + dp[last[s]]) % MOD
        last[s] = i
    # print(dp, souwa, pre)
    print(dp[-1])
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, C)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

memory = {}


def solve(N: int, C: "List[int]"):
    # print(dfs(tuple(C), N, 0))

    dp = [0]*N
    last = [-1]*(2*(10**5)+1)
    for i, s in enumerate(C):
        if i == 0:
            dp[i] = 1
        else:
            dp[i] = dp[i-1]
            if last[s] != -1 and last[s] < i-1:
                dp[i] = (dp[i] + dp[last[s]]) % MOD
        last[s] = i
    # print(dp, souwa, pre)
    print(dp[-1])
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, C)


if __name__ == '__main__':
    main()
n = int(input())
r = int(input())

if n < 10:
  print(n-(100*(10-n)))
else:
  print(n)

### FIXED CODE ###

n,r = map(int,input().split())
 
if n < 10:
  print(r+(100*(10-n)))
else:
  print(r)
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        q=collections.deque()
        visited=[[False]*w for _ in range(h)]
        q.append((i,j))
        while q:
          y,x=q.popleft()
          if visited[y][x]:
            continue
          visited[y][x]=True
          for dy,dx in dd:
            ny=y+dy
            nx=x+dx
            if 0<=ny<h and 0<=nx<w:
              if field[y][x]==field[ny][nx]:
                continue
              if visited[ny][nx]:
                continue
              if field[ny][nx]=='.':
                # ans+=1
              q.append((ny,nx))
    # print(ans)
  return ans

# main()
print(main())


### FIXED CODE ###

import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[False]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if visited[i][j]:
        continue
      if field[i][j]!='#':
        continue
      q=collections.deque()
      q.append((i,j))
      b=0
      wh=0
      while q:
        y,x=q.popleft()
        if visited[y][x]:
          continue
        if field[y][x]=='#':
          b+=1
        else:
          wh+=1
        visited[y][x]=True
        for dy,dx in dd:
          ny=y+dy
          nx=x+dx
          if not (0<=ny<h and 0<=nx<w):
            continue
          if field[y][x]==field[ny][nx]:
            continue
          if visited[ny][nx]:
            continue
          q.append((ny,nx))
      ans+=b*wh
      # print(i,j,b,wh,ans)
  return ans

# main()
print(main())
import collections

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

# N = 5
# A = [1, 1, 2, 1, 2]

c = collections.Counter(A)
d = {}
for i in c:
    # val = uni_vals[0]
    ans = 0
    for j in c:
        n = c[j]
        if j == A[i]:
            n -= 1
        ans += (n*(n-1))/2
    d[i] = ans

for i in range(N):
    print(int(d[A[i]]))


### FIXED CODE ###

from collections import defaultdict, Counter

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

d = defaultdict(int)
for a in A:
    d[a] += 1

all = 0
for val in d.values():
    all += val * (val - 1) / 2

all = int(all)
val_cnt = Counter(A)
for a in A:
    print(all - (val_cnt[a] - 1))