Harryxun/stf_run huggingface dataset:
r, c = map(int, input().split())
mat = []
for i in range(r):
 mat.append(list(map(int, input().split())))
mat.append([])

for x in range(r):
 rsum = 0
 for y in range(c):
  rsum += mat[x][y]
 mat[x].append(rsum)

for x in range(c):
 csum = 0
 for y in range(r):
  csum += mat[y][x]
 mat[c].append(csum)

for x in range(r):
 for y in range(c):
  print("{0} ".format(mat[x][y]), end = '')
 print(mat[x][c])

for i in range(c-1):
 print("{0} ".format(mat[r][i]), end = '')
print(mat[r][c-1]
  

### FIXED CODE ###

r, c = map(int, input().split())
mat =[]

for x in range(r):
 mat.append(list(map(int, input().split())))

tsum = 0

for x in range(r):
 rsum = 0
 for y in range(c):
  rsum += mat[x][y]
  tsum == mat[x][y]
 mat[x].append(rsum)

mat.append([])

for x in range(c):
 csum = 0
 for y in range(r):
  csum += mat[y][x]
  tsum += mat[y][x]
 mat[r].append(csum)



for x in range(r):
 for y in range(c):
  print("{0} ".format(mat[x][y]), end = '')
 print(mat[x][c])

for x in range(c):
 print("{0} ".format(mat[r][x]), end='')
print(tsum)
import sys
input = sys.stdin.readline

a,b,c = map(list(int,input().split()))

if a%b==0:
  print((a//b) * c)
else:
  print((a//b) * (c+1))
  

### FIXED CODE ###

import sys
input = sys.stdin.readline
 
a,b,c = list(map(int,input().split()))
 
if a%b==0:
  print((a//b) * c)
else:
  print(((a//b)+1) * c)
a, b = map(int, input().split())
if a * b % 2 = 0:
  print('Even')
else:
  print('Odd')

### FIXED CODE ###

a,b=map(int,input().split())
if a*b % 2 == 0:
  print('Even')
else:
  print('Odd')
#!/usr/bin/env python3
N = int(input())
a = [int(input()) - 1 for _ in range(N)[1:]]

children = [[] * N for i in range(N)]
for i in range(N)[:-1]:
    children[a[i]].append(i + 1)

def dfs(n):
    if children[n] == []:
        return 0
    dp = [dfs(child) for child in children[n]]
    dp.sort(reverse=True)
    return max(dp[i] + (i + 1) for i in range(len(dp)))

print(dfs(0))


### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

N = int(input())

children = [[] * N for i in range(N)]
for i in range(N)[1:]:
    a = int(input()) - 1
    children[a].append(i)

def dfs(n):
    if children[n] == []:
        return 0
    dp = [dfs(child) for child in children[n]]
    dp.sort(reverse=True)
    return max(dp[i] + (i + 1) for i in range(len(dp)))

print(dfs(0))
n, m = map(int, input().split())
acc = n+m
arr = list(map(int, input().split()))
sums = 0
count = 0
for i in arr:
    sums = sums + i
check = (1 / (4*m))*sums
for i in arr:
    if i < check:
        count += 1
    else:
        if i == sums
            count = 0
            break
        continue
if count >= 1:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

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

check = ((1 / (4 * M)) * sum(A))
x = 0
for item in A:
    if item < check:
        x += 1

ans = N - x

if ans >= M :
    print('Yes')
else:
    print('No')
import sys
def f(j):
  if j==0:return 0
  if j<0: return 100000
  if dp[j]!=-1:return dp[j]
  f_k=[f(j-l-1)+abs(h[j]-h[j-l-1]) for l in range(k)]
  dp[j]=min(f_k)
  return dp[j]
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[-1]*n
sys.setrecursionlimit(n*k+1)
print(f(n-1))


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
from functools import lru_cache
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
def inpl_str():
    '''
    一行に複数の文字
    '''
    return list(input().split())


n,k = inpl()
h = inpl()
dp = [INF] * (n)
dp[0] = 0
for i in range(min(n,k)):
    dp[i] = abs(h[i] - h[0])
for i in range(n - k):
    option=[dp[i+j]+abs(h[i+k]-h[i+j]) for j in range(k)]
    dp[i + k] = min(option)
print(dp[n - 1])
while true:
    n=input()
    if n==0: break
    print sum(input() for i in xrange(n/4))

### FIXED CODE ###

while True:
    n = input()
    if n == 0: break
    print sum(input() for i in range(n/4))
N = input()
for i in range(N):
  a = input()
print(len(set(i)))

### FIXED CODE ###

N = int(input())
list = [input() for i in range(N)]
print(len(set(list)))
import sys
sys.setrecursionlimit(10**7)

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)
        
        self.par = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        tmpx,tmpy=x,y
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
            self.par[tmpy]  =tmpx

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            self.par[tmpx]  = tmpy
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


def cur(i):
    if memo[i]==-1: memo[i]=(cur(tree.par[i])+state[i])%2
    return memo[i]

N=int(input())
tree=UnionFind(N)

state=[-1]*(N+1)
for i in range(N-1):
    u,v,w=map(int,input().split())
    tree.Unite(u,v)
    if tree.par[u]==v: state[u]=w%2
    if tree.par[v]==u: state[v]=w%2

memo=[-1]*(N+1)
memo[tree.Find_Root(1)]=0
for i in range(1,N+1):
    print(cur(i))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

def cur(current,e,dist,color):
    for it in e[current]:
        if color[it]!=-1: continue
        color[it]=(color[current]+dist[(it,current)])%2
        cur(it,e,dist,color)

N=int(input())
e=[[] for i in range(N+1)]
dist={}
for i in range(N-1):
    u,v,w=map(int,input().split())
    e[u].append(v)
    e[v].append(u)
    dist[(u,v)],dist[(v,u)]=w,w
memo=[-1]*N




color=[-1]*(N+1)
color[1]=0
cur(1,e,dist,color)

for i in range(1,N+1):
    print(color[i])
from itertools import combinations
import sys

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

min_diff = 10**9
max_diff = 1
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_diff)
    max_diff = max(x-y, max_diff)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

cand_set = set()
for x,y in XY:
    if x-y in (min_diff, max_diff) or x+y in (min_sum, max_sum):
        cand_set.add((x, y))

if len(cand_set) == N:
    print(max(max_sum-min_sum, mad_diff - min_diff))
    sys.exit()

dist = 0
for p1, p2 in combinations(cand_set, 2):
    dist = max(dist, abs(p1[0]-p2[0]) + abs(p1[1]-p2[1]))
    
print(dist)

### FIXED CODE ###

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

min_diff = 10**9
max_diff = -10**9
min_sum = 2 * 10**9
max_sum = 2

for x,y in XY:
    min_diff = min(x-y, min_diff)
    max_diff = max(x-y, max_diff)
    min_sum = min(x+y, min_sum)
    max_sum = max(x+y, max_sum)

print(max(max_sum-min_sum, max_diff-min_diff))
data = [10 ** 18] * 2
ex = [0]*4
ans = 10 ** 18
s = 0
t = 2
for i in range(1, n - 2):
    bl = [True, True]
    for j in range(s, i):
        res[0] = F[j]
        res[1] = F[i] - F[j]
        if not bl[0]:
            break
        if data[0] > abs(res[1] - res[0]) or j == s:
            s = j
            ex[0] = res[0]
            ex[1] = res[1]
            data[0] = abs(res[1] - res[0])
        else:
            bl[0] = False
    for k in range(t, n):
        res[2] = F[k] - F[i]
        res[3] = F[n - 1] - F[k]
        if not bl[1]:
            break
        if data[1] > abs(res[3] - res[2]) or k == t:
            t = k
            ex[2] = res[2]
            ex[3] = res[3]
            data[1] = abs(res[3] - res[2])
        else:
            bl[1] = False
    ans = min(ans, max(ex) - min(ex))

print(ans)

### FIXED CODE ###

n = int(input())
A = list(map(int, input().split()))
F = [int()] * n
F[0] = A[0]
for b in range(1, n):
    F[b] = F[b - 1] + A[b]


res = [0]*4
data = [10 ** 18] * 2
ex = [0]*4
ans = 10 ** 18
s = 0
t = 2
for i in range(1, n - 2):
    bl = [True, True]
    for j in range(s, i):
        res[0] = F[j]
        res[1] = F[i] - F[j]
        if not bl[0]:
            break
        if data[0] > abs(res[1] - res[0]) or j == s:
            s = j
            ex[0] = res[0]
            ex[1] = res[1]
            data[0] = abs(res[1] - res[0])
        else:
            bl[0] = False
    for k in range(t, n):
        res[2] = F[k] - F[i]
        res[3] = F[n - 1] - F[k]
        if not bl[1]:
            break
        if data[1] > abs(res[3] - res[2]) or k == t:
            t = k
            ex[2] = res[2]
            ex[3] = res[3]
            data[1] = abs(res[3] - res[2])
        else:
            bl[1] = False
    ans = min(ans, max(ex) - min(ex))

print(ans)
import sys

N = int(input())
A = lambda: sys.stdin.readline().rstrip()
lst = [0 for i in range(60)]
q = 0
for i in A:
    a = list(str(format(i, '08b')))
    a.reverse()
    for j in range(len(a)):
        lst[j]+=int(a[j])
for i in range(60):
    k = lst[i]
    l = k*(k-1)
    q+=(2**i)*l
p = sum(A)*(N-1)
print((p-q)%((10**9)+7))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
cnt = [0 for _ in range(60)]
for a in A:
    for i in range(60):
        cnt[i] += a & 1
        a >>= 1
cnt = [x * (N - x) % mod for x in cnt]
power = 1
ans = 0
for i in range(60):
    ans += power * cnt[i]
    power *= 2
    power %= mod
ans %= mod
print(ans)
import string
s = input()
t = input()
l = []
alp = string.ascii_lowercase
G = dict([(alp[i],-1) for i in range(len(alp))])
for i in range(len(s)-1,-1,-1):
  l = [G.copy()] + l
  G[s[i]] = i
stG = G.copy()

cnt = 0
ind = 0
while ind < len(t): 
  if stG[t[ind]] == -1:
    cnt = -1
    break
  else:
    lind = stG[t[ind]]
    ind += 1
    while l[lind][t[ind]] != -1:   
      lind = l[lind][t[ind]]
      ind += 1
      if ind == len(t):
        break   
    if ind == len(t):
      break        
    cnt += 1

###    
if cnt != -1:      
  print(cnt*len(s)+stG[t[-1]]+1)
else:
  print(cnt)  

### FIXED CODE ###

import string
s = input()
t = input()
l = []
alp = string.ascii_lowercase
G = dict([(alp[i],-1) for i in range(len(alp))])
for i in range(len(s)-1,-1,-1):
  l.append(G.copy())
  G[s[i]] = i
l = l[::-1]  
stG = G.copy()

cnt = 0
ind = 0
while ind < len(t): 
  if stG[t[ind]] == -1:
    cnt = -1
    break
  else:
    lind = stG[t[ind]]
    ind += 1
    if ind >= len(t):
      cnt += 1
      break 
    while l[lind][t[ind]] != -1:   
      lind = l[lind][t[ind]]
      ind += 1
      if ind >= len(t):
        break          
    cnt += 1

###    
if cnt != -1:      
  print(cnt*len(s)-(len(s)-(lind+1)))
else:
  print(cnt)
def main ():
N = int(input())
A = list(map(int,input(). split ()))
if 0 in A:
print(0)
return
prod = 1
for a in A:
prod *= a
if prod > 1000000000000000000:
print(-1)
return
print(prod)
main ()


### FIXED CODE ###

def main ():
  N = int(input())
  A = list(map(int,input(). split ()))
  
  if 0 in A:
    print(0)
    return
  prod = 1
  for a in A:
    prod *= a
    if prod > 1000000000000000000:
      print(-1)
      return
  print(prod)
main ()
import sys
finput=lambda:sys.stdin.readline().strip()

def main():
    p=10**9+7
    n=int(finput())
    a=list(map(int,finput().split()))
    k=sum(a)-(n*(n+1))//2
    pk=[i for i in range(n+1) if a[i]==k]
    fact=[1]*(n+2)
    ifact=[1]*(n+2)
    for i in range(1,n+2):
        fact[i]=fact[i-1]*i % p
    a=fact[-1]
    inv=1
    m=p-2
    while m>0:
        if m&1:
            inv=a*inv % p
        m>>=1
        a=a*a % p
    ifact[-1]=inv
    for i in range(n+1,0,-1):
        ifact[i-1]=ifact[i]*i
    ans0=[0]*(n+2)
    ans1=[0]*(n+2)
    ans2=[0]*(n+2)
    sn=pk[0]+n-pk[1]
    for i in range(n):
        ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
        ans1[i+1]=ans0[i]*2
        ans2[i+2]=ans0[i]
		if sn>i:
            ans1[i+1]-=fact[sn]*ifact[sn-i]*ifact[i] % p
        print((ans0[i]+ans1[i]+ans2[i]) % p)

if __name__=='__main__':
    main()


### FIXED CODE ###

import sys
finput=lambda:sys.stdin.readline().strip()

def main():
    p=10**9+7
    n=int(finput())
    a=list(map(int,finput().split()))
    k=sum(a)-(n*(n+1))//2
    pk=[i for i in range(n+1) if a[i]==k]
    fact=[1]*(n+2)
    ifact=[1]*(n+2)
    for i in range(1,n+2):
        fact[i]=fact[i-1]*i % p
    a=fact[-1]
    inv=1
    m=p-2
    while m>0:
        if m&1:
            inv=a*inv % p
        m>>=1
        a=a*a % p
    ifact[-1]=inv
    for i in range(n+1,0,-1):
        ifact[i-1]=ifact[i]*i % p
    ans0=[0]*(n+2)
    ans1=[0]*(n+2)
    ans2=[0]*(n+2)
    for i in range(n):
        ans0[i]=fact[n-1]*ifact[n-i-1]*ifact[i]%p
        ans1[i+1]=ans0[i]*2
        ans2[i+2]=ans0[i]
    sn=pk[0]+n-pk[1]
    for i in range(sn+1):
        ans1[i+1]-=fact[sn]*ifact[sn-i]*ifact[i] % p
    for i in range(1,n+2):
        print((ans0[i]+ans1[i]+ans2[i]) % p)

if __name__=='__main__':
    main()
A, B = map(int,input().split())
B *= 100
print((A*B)//100)

### FIXED CODE ###

A, B = input().split()
A = int(A)

b1,b2 = map(int,B.split("."))
B = 100*b1 + b2
print((A*B)//100)
n = int(input())
l_2 = 2
l_1 = 1

for _ in range(1,n):
  l_now = l_1 + l_2
  l_2 = l_1
  l_1 = l_now
print(l_now)

### FIXED CODE ###

n = int(input())
l_2 = 2
l_1 = 1
l_now = 1

for _ in range(1,n):
  l_now = l_1 + l_2
  l_2 = l_1
  l_1 = l_now
print(l_now)
N, M = map(int, input().split())

A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])

C=[]
for i in range(M):
    c, d = map(int, input().split())
    C.append([c, d])

for i in range(N):
    saitei = float("inf")
    ans = 0
    for j in range(M):
        if abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1]) < saitei:
            saitei = abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1])
            ans = j+1   
    print(ans) 

### FIXED CODE ###

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

A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])

B=[]
for i in range(M):
    c, d = map(int, input().split())
    B.append([c, d])

for i in range(N):
    saitei = float("inf")
    ans = 0
    for j in range(M):
        if abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1]) < saitei:
            saitei = abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1])
            ans = j+1   
    print(ans)
N = int(input())
S = input()
K = int(input())

t = S[K]
newS = [s if s == t else '*' for s in S]
print(''.join(newS))

### FIXED CODE ###

N = int(input())
S = input()
K = int(input())

t = S[K-1]
newS = [s if s == t else '*' for s in S]
print(''.join(newS))
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 5)


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
print(count.most_common(1)[0][1])

### FIXED CODE ###

from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)


N, M = map(int, input().split())
parent = [-1] * N


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res

for _ in range(M):
    a, b = map(int, input().split())
    union(a - 1, b - 1)


count = Counter(find(i) for i in range(N))
print(count.most_common(1)[0][1])
a, b = map(int, raw_input().split())
c = double(a)
d = double(b)

print "%d %d %.5f" %(a/b, a%b, c/d)

### FIXED CODE ###

a, b = map(int, raw_input().split())
c = float(a)
d = float(b)

print "%d %d %.5f" %(a/b, a%b, c/d)
n=int(input())
a=list(map(int,input().split()))
temp=[0,0,0,0,0,0,0,0]
r=0
for i in range(n):
  if a[i]>=3200:
    r=r+1
  elif a[i]>=2800:
    temp[7]=1
  elif a[i]>=2400:
    temp[6]=1
  elif a[i]>=2000:
    temp[5]=1
  elif a[i]>=1600:
    temp[4]=1
  elif a[i]>=1200:
    temp[3]=1
  elif a[i]>=800:
    temp[2]=1
  elif a[i]>=400:
    temp[1]=1
  else:
    temp[0]=1
print(sum(temp),temp(sum)+r)  

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
temp=[0,0,0,0,0,0,0,0]
r=0
for i in range(n):
  if a[i]>=3200:
    r=r+1
  elif a[i]>=2800:
    temp[7]=1
  elif a[i]>=2400:
    temp[6]=1
  elif a[i]>=2000:
    temp[5]=1
  elif a[i]>=1600:
    temp[4]=1
  elif a[i]>=1200:
    temp[3]=1
  elif a[i]>=800:
    temp[2]=1
  elif a[i]>=400:
    temp[1]=1
  else:
    temp[0]=1
if sum(temp)==0:
  print(1,r)
else:
  print(sum(temp),sum(temp)+r)
numbers = set()
for _ in [0] * int(input()):
    A = int(input())
    if A in numbers:
        arr.remove(A)
    else:
        arr.add(A)
print(len(numbers))

### FIXED CODE ###

numbers = {}
for _ in [0] * int(input()):
    A = int(input())
    numbers[A] = numbers.get(A, 0) ^ 1
print(sum(numbers.values()))
#Stone Monument
a,b = map(int, input().split())
M = []
ans = []
for i in range(1,1000,1):
	n = 1/2*i*(i+1)
	M.append(n)
for i in range(0,999,1):
	for j in range(0,1000,1):
		if (a + j == M[i]) and (b + j == M[i+1]):
			ans.append(j)

print(min(ans))


### FIXED CODE ###

#Stone Monument
a,b = map(int, input().split())
M = []
for i in range(1,1000,1):
	n = 1/2*i*(i+1)
	M.append(n)
n = b-a-1
print(int(M[n-1]-a))
a = int(input())
b = int(input())

if a > 8:
    print(":(")

elif b > 8:
    print(":(")

else:
    print("Yay!")

### FIXED CODE ###

num = input()

num = num.split(" ")

for i in range(len(num)-1):
    if int(num[i]) <= 8 and int(num[i+1]) <= 8:
        print("Yay!")

    else:
        print(":(")
from collections import deque

s=deque(list(input()))
q=int(input())


rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
#    s.reverse()
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

s=list(s)
if rev%2==1:
  s.reversed()
print(''.join(s))

### FIXED CODE ###

from collections import deque

s=deque(list(input()))
q=int(input())


rev=0
for i in range(q):
  l=list(input().split())
  if len(l)==1:
#    s.reverse()
    rev+=1
  else:
    t,f,c=l[0],l[1],l[2]

    if rev%2==0:
      if f=='1':
        s.appendleft(c)
      else:
        s.append(c)
    else:
      if f=='1':
        s.append(c)
      else:
        s.appendleft(c)

s=list(s)
if rev%2==1:
  s.reverse()
print(''.join(s))
H, W = map(int, input().split())
g = [input() for _ in range(H)]
white = 0
black = 0
for i in range(H):
    for j in range(W):
        if g[i][j] == '#':
            black += 1
        else:
            white += 1
visit =[[0]*W for _ in range(H)]
dist = 10**9
def dfs(x, y, n):
    if x < 0 or x >= H or y < 0 or y >= W or g[x][y] == '#':
        return 0
    elif x == H-1and y == W-1:
        visit[x][y] = 1
        global dist
        if n < dist:
            dist = n
    elif visit[x][y]:
        return 0
    else:
        visit[x][y] = 1
        dfs(x+1, y, n+1)
        dfs(x-1, y, n+1)
        dfs(x, y+1, n+1)
        dfs(x, y-1, n+1)
dfs(0, 0, 1)
if not visit[H-1][W-1]:
    print(-1)
else:
    print(white - dist)

### FIXED CODE ###

H, W = map(int, input().split())
g = [input() for _ in range(H)]
white = 0
black = 0
for i in range(H):
    for j in range(W):
        if g[i][j] == '#':
            black += 1
        else:
            white += 1
start = (0, 0)
goal = (H-1, W-1)
S = [start]
T = {start: 1}
while S and goal not in T:
    S2 = []
    for x, y in S:
        for pos in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            x2, y2 = pos
            if 0<= x2 <= H-1 and 0<= y2 <= W-1:
                if g[x2][y2] != '#' and pos not in T:
                    T[pos] = T[(x, y)] + 1
                    S2.append(pos)
    S = S2
if goal not in T:
    print(-1)
else:
    print(white - T[goal])
from collections import defaultdict
import sys
# input = sys.stdin.readline

N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()

new_dict = defaultdict(lambda: 0)
for i in range(M):
    b, c = [int(item) for item in input().split()]
    new_dict[c] += b
new_dict = sorted(new_dict.items(), key=lambda x: -x[0])


new_list = []
for k, v in new_dict:
    new_list.extend([k] * v)
    if len(new_list) >= N:
        break
new_list = new_list[:N]

#####
"""

n = min(N, len(new_list))
for i in range(n):
    if A[i] >= new_list[i]:
        break
    A[i] = new_list[i]

print(sum(A))
"""


### FIXED CODE ###

from collections import defaultdict
import sys
input = sys.stdin.readline

N, M = [int(item) for item in input().split()]
A = [int(item) for item in input().split()]
A.sort()

new_dict = defaultdict(lambda: 0)
for i in range(M):
    b, c = [int(item) for item in input().split()]
    new_dict[c] += b
new_dict = sorted(new_dict.items(), key=lambda x: -x[0])

new_list = []
for k, v in new_dict:
    if v > N:
        v = N
    new_list += [k] * v
    if len(new_list) >= N:
        break

new_list = new_list[:N]

#####

n = min(N, len(new_list))
for i in range(n):
    if A[i] >= new_list[i]:
        break
    A[i] = new_list[i]

print(sum(A))
S = input()
A = ['A','T','C','G']
res = []
count = 0
for i in S:
    if i in A:
        count += 1
    else:
        res.append(count)
        count = 0
print(max(res))


### FIXED CODE ###

S = input()+'Z'
X = 'ATCG'
res = [0]
count = 0
for i in S:
    if i in X:
        count += 1
    else:
        res.append(count)
        count = 0
print(max(res))
a = input()
for i in range('aiueo'):
  if a = i:
    print('vowel')
    exit()
print('consonant')

### FIXED CODE ###

a = input()
for i in 'aiueo':
  if a == i:
    print('vowel')
    exit()
print('consonant')
from numpy.linalg import solve

n = int(input())
a = [int(x) for x in input().split()]

#left = [[1] * 3 for i in range(3)]
left = []
for i in range(n-1):
    temp = [0] * n
    temp[i] = 1
    temp[i+1] = 1
    left.append(temp)
else:
    temp = [0] * n
    temp[0] = 1
    temp[-1] = 1
    left.append(temp)

#print(left)

right = [x * 2 for x in a]
#print(right)

sol = [int(x) for x in solve(left, right)]
print(' '.join(map(str, sol)))
    

### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]

c = 0
for i in range(n):
    c += a[i] * (-2 * (i%2) + 1)

sol = [c]

for i in range(1,n):
    c = c * (-1) + 2 * a[i-1]
    sol.append(c)
    
print(' '.join(map(str, sol)))
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(max(ans,c))


### FIXED CODE ###

k,n=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(k-max(ans,c))
x=int(input())

print(x//3600,x/60%60,x/60,sep={" "})


### FIXED CODE ###

x=int(input())


print(x//3600,x//60%60,x%60,sep=':')
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    B[i] = 0
for j in A:
    B[j] += 1
for k in B.values():
    print(k)

### FIXED CODE ###

B = {}#辞書作成
N = int(input())
A = list(map(int, input().split()))


for i in range(N):
    B[i+1] = 0
#print(B)
for j in A:
    B[j] += 1
#print(B)
for k in B.values():
    print(k)