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

def main():
    from sys import stdin
    #input = stdin.readline
    import numpy as np
    h, w, n = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    ab_d = {(a, b) for a, b in ab}

    ans = [set() for _ in range(9)]
    for a, b in ab:
        temp = np.full((5, 5), -1, dtype=np.int64)
        for i in range(max(0, 3-a), min(5, h-a+3)):
            for j in range(max(0, 3-b), min(5, w-b+3)):
                if (a+i-2, b+j-2) in ab_d:
                    temp[i, j] = 1
                else:
                    temp[i, j] = 0
        # print(temp)
        flag_yoko = [0, 5]
        flag_tate = [0, 5]
        if np.all(temp[:, 0] == np.full((1, 5), -1, dtype=np.int64)):
            if np.all(temp[:, 1] == np.full((1, 5), -1, dtype=np.int64)):
                flag_yoko[0] = 2
            else:
                flag_yoko[0] = 1
        if np.all(temp[:, 4] == np.full((1, 5), -1, dtype=np.int64)):
            if np.all(temp[:, 3] == np.full((1, 5), -1, dtype=np.int64)):
                flag_yoko[1] = 3
            else:
                flag_yoko[1] = 4
        if np.all(temp[0, :] == np.full(5, -1, dtype=np.int64)):
            if np.all(temp[1, :] == np.full(5, -1, dtype=np.int64)):
                flag_tate[0] = 2
            else:
                flag_tate[0] = 1
        if np.all(temp[4, :] == np.full(5, -1, dtype=np.int64)):
            if np.all(temp[3, :] == np.full(5, -1, dtype=np.int64)):
                flag_tate[1] = 3
            else:
                flag_tate[1] = 4
        new_temp = temp[flag_tate[0]:flag_tate[1], flag_yoko[0]:flag_yoko[1]]
        # print(new_temp)
        for i in range(flag_tate[1]-flag_tate[0]-2):
            for j in range(flag_yoko[1]-flag_yoko[0]-2):
                cnt = [new_temp[i+k, j+l] for k in range(3) for l in range(3)]
                if None not in cnt:
                    ans[sum(cnt)-1].add((a+i-2+flag_tate[0], b+j-2+flag_yoko[0]))

    for i in range(9):
        ans[i] = len(ans[i])

    print((h-2)*(w-2)-sum(ans))
    for i in ans:
        print(i)


main()

### FIXED CODE ###

h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**9)+b-1 for a,b in ab}

ans=[set() for _ in range(9)]
for a,b in ab:
    temp=[None for _ in [0]*25]
    for i in range(5):
        for j in range(5):
            if 0<a+i-2<=h and 0<b+j-2<=w:
                if (a+i-2)*(10**9)+b+j-3 in ab_d:
                    temp[i*5+j]=1
                else:
                    temp[i*5+j]=0
    for i in range(3):
        for j in range(3):
            cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
            if None not in cnt:
                ans[sum(cnt)-1].add((a+i-2)*(10**9)+b+j-3)
                
for i in range(9):
    ans[i]=len(ans[i])

print((h-2)*(w-2)-sum(ans))
for i in ans:
    print(i)
### BUGGY CODE ###

# abc177_c.py
# https://atcoder.jp/contests/abc177_c


# [開発時用] ログ関数
def lg(value):
    flag = False
    # flag = True
    if flag:
        print(str(value))


# [開発時用] exit処理
def xt(log):
    lg('★exit() - ' + str(log))
    exit()


# 本体
def get_results():

    # 引数処理部
    lines = list()
    # 仕様でn行と決まっている場合(の例)
    lines_count = 2
    # 先頭行のNで行数が決まる場合(の例)
    # line = input()
    # lines.append(line)
    # N = int(line)
    # lines_count = N
    for _ in range(lines_count):
        lines.append(input())

    # 演算部
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lg(f'values=[{values}]')

    su = 0
    for i in range(N-1):
        target = 0
        for j in range(i+1, N):
            target += values[j]
        su = (su + values[i] * target) % (10**9+7)

    return [su]


# 主処理
def main():
    results = get_results()

    for result in results:
        print(result)


# 起動処理
if __name__ == '__main__':
    main()


### FIXED CODE ###

# abc177_c.py
# https://atcoder.jp/contests/abc177_c


# [開発時用] ログ関数
def lg(value):
    flag = False
    # flag = True
    if flag:
        print(str(value))


# [開発時用] exit処理
def xt(log):
    lg('★exit() - ' + str(log))
    exit()


# 本体
def get_results():

    # 引数処理部
    lines = list()
    # 仕様でn行と決まっている場合(の例)
    lines_count = 2
    # 先頭行のNで行数が決まる場合(の例)
    # line = input()
    # lines.append(line)
    # N = int(line)
    # lines_count = N
    for _ in range(lines_count):
        lines.append(input())

    # 演算部
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    lg(f'values=[{values}]')

    targets = list()
    # [1, 2, 3] => targets = [3, 5]
    su = 0
    for j in range(1, N):
        # targets.append(3)
        # targets.append(5)
        su += values[N - j]
        targets.append(su)

    su = 0
    for i in range(N-1):
        # for j in range(i+1, N):
        #     target += values[j]
        su = (su + values[i] * targets[N-2-i]) % (10**9+7)

    return [su]


# 主処理
def main():
    results = get_results()

    for result in results:
        print(result)


# 起動処理
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N, K ,Q = (int(nkq) for nkq in input().split())
A = []
score_list = [-1] + [K for _ in range(N)]
for _ in range(Q):
    A.append(int(input()))

for a in A:
    score_list = [-1] + [score_list[i]-1 if i != a else score_list[i] for i in range(1, N+1)]

for score in score_list[1:]:
    if score > 0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

N, K ,Q = (int(nkq) for nkq in input().split())
A = []
score_list = [-1] + [K-Q for _ in range(N)]
for _ in range(Q):
    A.append(int(input()))

for a in A:
    score_list[a] += 1

for score in score_list[1:]:
    if score > 0:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

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

real_ans=0
ans1=len(set(A))
ans2=collections.Counter(A)
ANS=list(ans2.values())

for j in range(ans1):
    real_ans+=(ANS[j]*(ANS[j]-1))//2
    
for i in range(N):
    num=A.count(A[i])
    re_ans=real_ans-(num-1)
    print(re_ans)

### FIXED CODE ###

import collections

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

ans=0
dic=collections.Counter(A)
keys=list(dic.keys())
values=list(dic.values())


for i in values:
    
    ans+=(i*(i-1))//2

for j in A:
    ANS=ans
    num=dic[j]
    ANS=ANS-(num-1)
    print(ANS)
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]




for i in range(n):
	temp = a[i]
	a[i] = 0
	print(max(a))
	a[i] = temp

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
b = sorted(a, reverse = True)

a1 = b[0]
a2 = b[1]



for i in range(n):
	if a[i] == a1:
		print(a2)
	else:
		print(a1)
### BUGGY CODE ###

# 正解ではない

from queue import Queue

q = Queue()
cell_list = list()


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [list(input()) for i in range(H)]
    q.put((0, Ch - 1, Cw - 1))
    S[Ch - 1][Cw - 1] = '1'

    answer = resolve(S, (Dh - 1, Dw - 1), H, W)
    print(answer)


def resolve(S, D, H, W):
    if q.empty():
        return -1

    while not q.empty():
        worp_count, x, y = q.get()
        S[x][y] = '2'
        cell_list.append((x, y))

        if (x, y) == D:
            return worp_count

        for i, j in [(x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1)]:
            if 0 <= i < H and 0 <= j < W and S[i][j] == '.':
                q.put((worp_count, i, j))

    for x, y in cell_list:
        for i, j in [(x + a, y + b) for a in range(-2, 3) for b in range(-2, 3)]:
            if 0 <= i < H and 0 <= j < W and S[i][j] == '.':
                q.put((worp_count + 1, i, j))
                S[i][j] = '1'

    return resolve(S, D, H, W)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    Ch, Cw = map(int, input().split())
    Dh, Dw = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    d = [[-1 for _ in range(W)] for _ in range(H)]

    q = deque([])
    q.appendleft((0, Ch - 1, Cw - 1))

    while len(q):
        worp_count, x, y = q.popleft()

        if d[x][y] != -1:
            continue
        d[x][y] = worp_count

        for i, j in ((a, b) for a in range(-2, 3) for b in range(-2, 3)):
            nx = x + i
            ny = y + j
            if 0 <= nx < H and 0 <= ny < W and S[nx][ny] == '.':
                if i == 0 and j == 0:
                    continue
                elif abs(i) + abs(j) == 1:
                    q.appendleft((worp_count, nx, ny))
                else:
                    q.append((worp_count + 1, nx, ny))

    print(d[Dh - 1][Dw - 1])


if __name__ == "__main__":
    main()
### BUGGY CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(m)]
H = [i for i, _ in HW]
W = [i for _, i in HW]

hd = defaultdict(int)
wd = defaultdict(int)

for i, j in HW:
  hd[i] += 1
  wd[j] += 1

hd = list(hd.items())
wd = list(wd.items())

hd.sort(key=lambda x: -x[1])
wd.sort(key=lambda x: -x[1])

kouhoh = []
kouhow = []

for i, j in hd:
  if j < hd[0][1]:
    break
  else:
    kouhoh.append(i)

for i, j in wd:
  if j < wd[0][1]:
    break
  else:
    kouhow.append(i)

for i in kouhoh:
  for j in kouhow:
    if [i, j] not in HW:
      ans = hd[0][1] + wd[0][1]
      print(ans)
      exit()

ans = hd[0][1] + wd[0][1] - 1  
print(ans)

### FIXED CODE ###

from collections import defaultdict

h, w, m = map(int, input().split())
HW = [list(map(int, input().split())) for _ in range(m)]
dicHW = defaultdict(set)

for h, w in HW:
  dicHW[h].add(w)

hd = defaultdict(int)
wd = defaultdict(int)

for i, j in HW:
  hd[i] += 1
  wd[j] += 1

hd = list(hd.items())
wd = list(wd.items())

hd.sort(key=lambda x: -x[1])
wd.sort(key=lambda x: -x[1])

kouhoh = []
kouhow = []

for i, j in hd:
  if j < hd[0][1]:
    break
  else:
    kouhoh.append(i)

for i, j in wd:
  if j < wd[0][1]:
    break
  else:
    kouhow.append(i)

for i in kouhoh:
  for j in kouhow:
    if j not in dicHW[i]:
      ans = hd[0][1] + wd[0][1]
      print(ans)
      exit()

ans = hd[0][1] + wd[0][1] - 1  
print(ans)
### BUGGY CODE ###

s = list(input())
ans = 0
for i in range(4, len(s) + 1):
    l = 0
    r = l + i
    while r <= len(s):
        if int(''.join(s[l:r])) % 2019 == 0:
            ans += 1
            l = r - 1
            r = l + i
        else:
            l += 1
            r += 1
print(ans)

### FIXED CODE ###

s = input()[::-1]
sum_of_digits = 0
cnts = [0] * 2019
cnts[0] = 1

d = 1
for c in s:
    sum_of_digits += int(c) * d
    d *= 10
    d %= 2019
    sum_of_digits %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

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

import math

n = int(input())
s = input()

R, G, B = [], [], []

i = 0
while i < n:
    if s[i] == "R": R.append(i + 1)
    if s[i] == "G": G.append(i + 1)
    if s[i] == "B": B.append(i + 1)
    i += 1

cnt = 0
for r in R:
    for g in G:
        for b in B:
            i, j, k = sorted([r, g, b])
            if j - i != k - j:
                cnt += 1

print(cnt)


### FIXED CODE ###

import math

n = int(input())
s = input()

R, G, B = s.count("R"), s.count("G"), s.count("B")
ans = R * G * B

for i in range(n):
    for j in range(n):
        c1 = i
        c2 = i + j
        c3 = i + j * 2
        if c3 >= n: continue
        if c1 == c2 == c3: continue
        if s[c1] != s[c2] and s[c2] != s[c3] and s[c1] != s[c3]:
            ans -= 1

print(ans)
# 012 024 036 048
# 123 135 147 159
### BUGGY CODE ###

num = int(input())
flag_list = [int(i) for i in input().split()]


ans = 0
check_divide = False
cont_game = True

while cont_game:
    for i in range(num):
        if check_divide == False:
            if flag_list[i] % 2 == 0:
                flag_list[i] //= 2
                check_divide = True
            else:
                flag_list[i] *= 3
        else:
            flag_list[i] *= 3

    if check_divide == True:
        check_divide = False
    else:
        break
    ans += 1

print(ans)

### FIXED CODE ###

num = int(input())
flag_list = [int(i) for i in input().split()]


ans = 0
cont_game = True

for val in flag_list:
    while val % 2 == 0:
        val //= 2
        ans += 1

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

N=input()
A = list(map(int, input().split()))
T=True
sucl =[]
for i in range(0,int(N)):
  T=True
  for j in range(0,int(N)):
    
    if A[i] % A[j]==0:
      if i==j:
        pass
      else:
        T=False
        
  if T==True:
    sucl.append(i)
print(len(sucl))
    

### FIXED CODE ###

N = input()
A = list(map(int, input().split()))
N = int(N)
MA = max(A)
s=0
LS = [0 for i in range(0,MA)]
for i in range(0,N):
  k=1
  while A[i]*k<=MA:
    LS[A[i]*k-1] +=1
    k +=1
for j in range(0,N):
  if LS[A[j]-1]==1:
    s+=1
print(s)
### BUGGY CODE ###

N = int(input())
N_list = [int(i) for i in input().split()]

counter = 0
for i in range(len(N_list)):
    if N_list[i] <= min(N_list[:i+1]):
        counter += 1
print(counter)
print()

### FIXED CODE ###

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

counter = 0
min = N_list[0]
for i in range(N):
    if N_list[i] <= min:
        min = N_list[i]
        counter += 1
print(counter)
print()
### BUGGY CODE ###

n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = map(int, input().split())
    if x <= t and y <= a:
        x = t
        y = a
    elif x <= t and y > a:
        i = 1
        while y > a:
            a //= i
            i += 1
            a *= i
        x = i*t
        y = a

    elif x > t and y <= a:
        i = 1
        while x > t:
            t //= i
            i +=1
            t *= i
        y = i*a
        x = t

    elif x > t and y > a:
        i = 1
        while x > t or y > a:
            t //= i
            a //= i
            i += 1
            t *= i
            a *= i
        x = t
        y = a

print(x+y)

### FIXED CODE ###

n = int(input())
x, y = 1, 1
for _ in range(n):
    t, a = map(int, input().split())
    if x <= t and y <= a:
        x = t
        y = a
    elif x <= t and y > a:
        if y % a == 0:
            i = y // a
        else:
            i = y // a + 1
        y = i*a
        x = i*t
    elif x > t and y <= a:
        if x % t == 0:
            i = x // t
        else:
            i = x // t + 1
        x = i*t
        y = i*a
    elif x > t and y > a:
        if x % t == 0:
            i_x = x // t
        else:
            i_x = x // t + 1

        if y % a == 0:
            i_y = y // a
        else:
            i_y = y // a + 1
        bigger = max(i_x, i_y)
        x = bigger*t
        y = bigger*a
print(x+y)
### BUGGY CODE ###

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

MAP=[["." for i in range (W)]for i in range(H)]
LIST=[(0,0,0)]*10**8

l=0
r=0
for i in range(H):
    A=list(input())
    for j in range(W):
        if(A[j]=="#"):
            MAP[i][j]="#"
            LIST[r]=(i,j,0)
            r+=1

while(True):
    T=LIST[l]
    i=T[0]
    j=T[1]
    if(i>0):
        if(MAP[i-1][j]=="."):
            MAP[i-1][j]="#"
            LIST[r]=(i-1,j,T[2]+1)
            r+=1  
    if(i+1<H):
        if(MAP[i+1][j]=="."):
            MAP[i+1][j]="#"
            LIST[r]=(i+1,j,T[2]+1)
            r+=1  
    if(j>0):
        if(MAP[i][j-1]=="."):
            MAP[i][j-1]="#"
            LIST[r]=(i,j-1,T[2]+1)
            r+=1  
    if(j+1<W):
        if(MAP[i][j+1]=="."):
            MAP[i][j+1]="#"
            LIST[r]=(i,j+1,T[2]+1)
            r+=1
    l+=1
    if(r<=l):
        print(LIST[r-1][2])
        exit()  



### FIXED CODE ###

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

MAP=[["." for i in range (W)]for i in range(H)]
LIST=[0]*(10**6+100)

l=0
r=0
for i in range(H):
    A=list(input())
    for j in range(W):
        if(A[j]=="#"):
            MAP[i][j]="#"
            LIST[r]=(i,j,0)
            r+=1

while(True):
    T=LIST[l]
    i=T[0]
    j=T[1]
    if(i>0):
        if(MAP[i-1][j]=="."):
            MAP[i-1][j]="#"
            LIST[r]=(i-1,j,T[2]+1)
            r+=1  
    if(i+1<H):
        if(MAP[i+1][j]=="."):
            MAP[i+1][j]="#"
            LIST[r]=(i+1,j,T[2]+1)
            r+=1  
    if(j>0):
        if(MAP[i][j-1]=="."):
            MAP[i][j-1]="#"
            LIST[r]=(i,j-1,T[2]+1)
            r+=1  
    if(j+1<W):
        if(MAP[i][j+1]=="."):
            MAP[i][j+1]="#"
            LIST[r]=(i,j+1,T[2]+1)
            r+=1
    l+=1
    if(r<=l):
        print(LIST[r-1][2])
        exit()
### BUGGY CODE ###

from collections import deque


def solve():
    N, M = map(int, input().split())
    V = {i:[] for i in range(1, N+1)}
    for _ in range(M):
        u, v = map(int, input().split())
        V[u].append(v)

    S, T = map(int, input().split())
    q = deque([(S, 0)])
    used = [[False]*3 for _ in range(N+1)]
    while q:
        a, dist = q.popleft()
        used[a][dist%3] = True
        if a==T and dist%3==0:
            break
        for b in V[a]:
            if used[b][(dist+1)%3]:continue
            q.append((b, dist+1))

    if a==T and dist%3==0:
        print(dist//3)
    else:
        print(-1)

if __name__ == "__main__":
    solve()

### FIXED CODE ###

from collections import defaultdict, deque
from heapq import heappush, heappop


def bfs(V, s, t):
    q = deque([(0, s)])
    used = set()
    
    while q:
        dist, a = q.popleft()
        used.add(a)
        if a == t:
            break
        for b in V[a]:
            if b in used: continue
            q.append((dist+1, b))
    
    if a != t:
        dist = -1
    else:
        dist = -1 if dist%3 else dist//3
    return dist

def dijkstra1(V, n, source):
    # O(ElogV)

    inf = float("inf")
    dist = [inf] * (n+1)
    dist[source] = 0
    q = [(0, source)]

    while q:
        cost, u = heappop(q)
        if dist[u] < cost:
            continue
        for c, v in V[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                heappush(q, (dist[v], v))

    return dist


if __name__ == "__main__":
    V = defaultdict(list)
    N, M = map(int, input().split())
    for _ in range(M):
        u, v = map(int, input().split())
        V[u].append((1, v+(N)))
        V[u+(N)].append((1, v+(2*N)))
        V[u+(2*N)].append((1, v))

    S, T = map(int, input().split())
    dist = dijkstra1(V, 3*N, S)[T]
    print(-1 if dist==float("inf") else dist//3)
### BUGGY CODE ###


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

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in b:
    total += choose2(a.count(i))

for i in a:
    s = a.count(i)
    print(total - choose2(s) + choose2(s-1))

### FIXED CODE ###


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

from collections import Counter
count = Counter(a)

def choose2(x):
    return int(x*(x-1)/2)
    
total = 0
for i in list(count.values()):
    total += choose2(i)

for i in a:
    s = count[i]
    print(total - choose2(s) + choose2(s-1))
### BUGGY CODE ###

s = str(input())
count = 0
while ("ABC" in s) == True:
    s = s.replace("ABC", "BCA", 1)
    count += 1
print(count)

### FIXED CODE ###

s = str(input())
d = s.replace("BC", "D")

count = 0
count_a = 0
for i,c in enumerate(d):
    if c == "A":
        count_a += 1
    elif c == "D":
        count += count_a
    else:
        count_a = 0
print(count)
### BUGGY CODE ###

from collections import deque

h , w = map(int,input().split())
ma = [["#"]*(w+2)]
cou = 0
for i in range(h):
    kar = ["#"]
    kar.extend(list(input()))
    cou += kar.count(".")
    kar.append("#")
    ma.append(kar)
ma.append(["#"]*(w+2))

ans = [[-1 for i in range(w+2)] for j in range(h+2)]
ans[1][1] = 1
q = deque([(1,1)])

while q:
    x , y = q.popleft()
    ma[x][y] = "#"
    if ma[x-1][y] == ".":
        q.append((x-1,y))
        ans[x-1][y] = ans[x][y] + 1
    if ma[x+1][y] == ".":
        q.append((x+1,y))
        ans[x+1][y] = ans[x][y] + 1        
    if ma[x][y-1] == ".":
        q.append((x,y-1))
        ans[x][y-1] = ans[x][y] + 1        
    if ma[x][y+1] == ".":
        q.append((x,y+1))
        ans[x][y+1] = ans[x][y] + 1

if ans[h][w] == -1:
    print(-1)
else:
    print(cou - ans[h][w])

### FIXED CODE ###

from collections import deque
 
h , w = map(int,input().split())
cou = 0
ma = []
for i in range(h):
    kar = list(input())
    cou += kar.count("#")
    ma.append(kar)
 
 
ans = [[-1 for i in range(w)] for j in range(h)]
ans[0][0] = 1
q = deque([(0,0)])
xy = [(1,0),(-1,0),(0,1),(0,-1)]
 
while q:
    x , y = q.popleft()
    for i in range(4):
        nx = x + xy[i][0]
        ny = y + xy[i][1]
        if 0 <= nx <= h-1 and 0 <= ny <= w-1 and ans[nx][ny] == -1:
            if ma[nx][ny] == ".":
                q.append((nx,ny))
                ans[nx][ny] = ans[x][y] + 1
        if nx == h-1 and ny == w-1:
            break
 
if ans[h-1][w-1] == -1:
    print(-1)
else:
    print(h*w - cou - ans[h-1][w-1])