Problem:
 Score : 300 points    Problem Statement There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region.
The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:   For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.   It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed.
Find the number of cards that face down after all the operations.      Constraints  1 \leq N,M \leq 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  N  M       Output Print the number of cards that face down after all the operations.        Sample Input 1 2 2      Sample Output 1 0  We will flip every card in any of the four operations. Thus, after all the operations, all cards face up.       Sample Input 2 1 7      Sample Output 2 5  After all the operations, all cards except at both ends face down.       Sample Input 3 314 1592      Sample Output 3 496080

Solution (Python):
N,M=map(int,input().split())

if N>=3 and M>=3:
    print((N-2)*(M-2))
elif N==1 or M==1:
    print((max(N,M)-2)*(max(N,M)>=3)or N*M%2)
else:
    print(0)

Solution (Python):
N, M = map(int, input().split())

if N == 1 and M == 1:
  print(1)
elif min(N,M) == 1:
  print(max(N,M)-2)
else:
  print((N-2)*(M-2))

Solution (Python):
n,m = list(map(int, input().split()))




if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(max(n,m)-2)
else:
    print((n-2)*(m-2))

Solution (Python):
def main():
    N, M = map(int, input().split())
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1:
        print(M - 2)
        return
    if M == 1:
        print(N - 2)
        return
    ans = (N - 2) * (M - 2)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

a,b = map(int,input().split())
n,m = max(a,b),min(a,b)

if n <= 1:
    result = 1
elif m <= 1:
    result = n - 2
else:
    result = (m-2)*(n-2)
    
print(result)

Solution (Python):
import sys
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    if N > M:
        N, M = M, N
    if N == 1 and M == 1:
        return 1
    elif N == 1:
        return M - 2
    else:
        return (N-2) * (M-2)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Solution (Python):
















H,W = map(int,input().split())
h = H-2
w = W-2
if H==1:
    h=1
if W==1:
    w=1
print(h*w)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n,m=mii()

if n==1 and m==1:
    print(1)
elif n==1 and m!=1:
    print(m-2)
elif n!=1 and m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

Solution (Python):
n, m = map(int, input().split())
if n == m == 1:
  print(1)
elif n == 1 or m == 1:
  print(max(n, m) - 2)
else:
  print((n - 2) * (m - 2))

Solution (Python):
N, M=map(int, input().split())
if N==1 or M==1:
  if N*M==1:
    print(1)
  else:
    print(max(N, M)-2)
else:
  print((N-2)*(M-2))

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    N, M = min(N, M), max(N, M)
    if N == M == 1:
        ans = 1
    elif N == 1:
        ans = M - 2
    else:
        ans = (N - 2) * (M - 2)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())

    N, M = min(N, M), max(N, M)
    if N == M == 1:
        ans = 1
    elif N == 1:
        ans = M - 2
    elif N == 2:
        ans = 0
    else:
        ans = N * M - 2 * (N - 2) - 2 * (M - 2) - 4

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


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

'''
if N > 3 and M > 3:
    ans = N * M - 2*N - 2*M + 4
    print(ans)
'''

ans = N * M - 2*N - 2*M + 4
print(abs(ans))

Solution (Python):
n, m = map(int, input().split())
if n == 1 and m == 1:
    ans = 1
elif n == 1:
    ans = m - 2
elif m == 1:
    ans = n - 2
else:
    ans = (n - 2) * (m - 2)
print(ans)

Solution (Python):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1:
    print(m-2)
elif m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

Solution (Python):
n,m = map(int,input().split())
if n == 1 and m == 1:
  print('1')
elif n == 1 and 2 <= m:
  print(m-2)
elif m == 1 and 2 <= n:
  print(n-2)
elif n == 2 or m == 2:
  print('0')
else:
  print((n-2)*(m-2))

Solution (Python):
N, M = map(int, input().split())
if N == 1 and M > 3:
    print(M - 2)
elif M == 1 and N > 3:
    print(N - 2)
else:
    print((N - 2) * (M - 2))

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]









n,m=l()
if(n>m):
    n,m=m,n
if(n==1 and m==1):
    print(1)
    exit()
if(n==1 and m!=1):
    print(m-2)
    exit()
print((n-2)*(m-2))

Solution (Python):
n, m = map(int, input().split())
n, m = min(n, m), max(n, m)
if n == m == 1:
	print(1)
elif n == 1:
	print(m - 2)
else:
	print((n-2)*(m-2))

Solution (Python):
N, M = map(int, input().split())
if N > M:
    N, M = M, N
if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M - 2)
else:
    print(N * M - 2 * N - 2 * M + 4)

Solution (Python):
n,m =  map(int,input().split())
if n==1 or m == 1:
    if n==1 and m==1:
        ans = 1
    else:
        ans = n*m - 2
else:
    ans = (n-2)*(m-2)
print(ans)

Solution (Python):
def solve():
    n, m = map(int, input().split())
    if n == m == 1:
        print(1)
    elif n == 1:
        print(m-2)
    elif m == 1:
        print(n-2)
    elif n == 2 or m == 2:
        print(0)
    else:
        print((n-2)*(m-2))
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n, m = map(int, input().split())

ret = 0

if (n >= 3) and (m >= 3):
    ret += (n-2) * (m-2)

if (n == 1) and (m >= 3):
    ret += m - 2

if (m == 1) and (n >= 3):
    ret += n - 2

if (m == 1) and (n == 1):
    ret += 1

print(ret)

Solution (Python):


def main():
    (N, M) = map(int, input().split())
    if N >= M:
        (N, M) = (M, N)
    if N == 1:
        if M == 1:
            print(1)
        else:
            print(M-2)
    else:
        print((N-2) * (M-2))
    

main()

Solution (Python):
n, m = map(int, input().split())
print(abs((n-2)*(m-2)))

Solution (Python):
def main():
    N, M = map(int, input().split())
    if N >= 3 and M >= 3:
        ans = (N-2)*(M-2)
    elif N == 2 or M == 2:
        ans = 0
    elif N == 1 and M == 1:
        ans = 1
    else:
        S = max(N, M)
        ans = max(0, S-2)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N,M = list(map(int,input().split()))
print(abs((N-2)*(M-2)))

Solution (Python):
N, K = map(int, input().split())
if N >= 3 and K >= 3:
    print((N-2)*(K-2))
elif N == 1 or K == 1:
    ans = max(N, K) - 2
    if ans >= 0:
        print(ans)
    else:
        print(1)
else:
    print(0)

Solution (Python):
N, M = map(int, input().split())
if N == M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N - 2, M - 2))
else:
    print((N - 2) * (M - 2))

Solution (Python):
n, m = map(int, input().split())

if min(n, m) == 1:
    if max(n, m) == 1:
        print(1)
    else:
        print(max(n, m)-2)
elif min(n, m) == 2:
    print(0)
else:
    print((n-2)*(m-2))

Solution (Python):
import math
import collections

def main():
    x, y = input_list()
    if x < 2 or y < 2:
        print(abs(x-2) * abs(y-2))
    else:
        print((x-2) * (y-2))


def yogen(a, b, angle):
    coss = math.cos((angle/180)*math.pi)
    return math.sqrt(a**2 + b**2 - 2*a*b*coss)


def get_angle(hour, minute):
    h = (hour * 360) / 12 + (minute * 360) / (12 * 60)
    m = (minute * 360) / 60
    angle = abs(h-m)
    return min(angle, 360-angle)

def has(v, l):
    for vl in l:
        if v == vl:
            return True
    return False

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    IN = [int(_) for _ in input().split()]
    N = IN[0]
    M = IN[1]

    if N == 1 and M != 1:
        print(M-2)
    elif M == 1 and N != 1:
        print(N-2)
    elif N == 1 and M == 1:
        print(1)
    else:
        print((N-2)*(M-2))

if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N,M  = map(int, input().split()) 
    if N >=3 and M >=3:
        print((N-2)*(M-2))
    elif N ==1 and M==1:
        print(1)
    elif N ==1 or M==1:
        print((N*M)-2)
    else:
        print(0)



if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    if n==1 and m==1:
        ans=1
    
    elif m==1 or n==1:
        ans=max(n,m)-2
    else:
        ans=(n-2)*(m-2)
    print(ans)
resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    if n==1 and m==1:
        ans=1
    
    elif m==1:
        ans=n-2
    elif n==1:
        ans=m-2
    else:
        ans=(n-2)*(m-2)
    print(ans)
resolve()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    if n==1 and m==1:
        ans=1
    elif m==1:
        ans=max(0,n-2)
    elif n==1:
        ans=max(0,m-2)
    else:
        ans=(n-2)*(m-2)
    print(ans)
resolve()

Solution (Python):
N,M=map(int,input().split())

if N==1 and M==1:
    result=1

elif N==1:
    result=M-2

elif M==1:
    result=N-2

else:
    result=(M-2)*(N-2)

print(result)

Solution (Python):
n, m = map(int, input().split())
if n < 2 and m < 2:
    ans = 1
elif n < 2:
    ans = m - 2
elif m < 2:
    ans = n - 2
else:
    ans = n * m - (2 * n + 2 * m - 4)
print(ans)

Solution (Python):
n, m = map(int, input().split())
if n == m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n, m) - 2)
else:
    print((n - 2) * (m - 2))

Solution (Python):
N,M = map(int,input().split())

n = min(N,M)
m = max(N,M)

if n*m == 1:
  print(1)
  exit()
if n == 1:
  print(m-2)
  exit()
print((n-2)*(m-2))

Solution (Python):
N,M = map(int,input().split())

n = min(N,M)
m = max(N,M)

if n == 1 and m == 1:
  print(1)
  exit()
if n == 1:
  print(m-2)
  exit()
print((n-2)*(m-2))

Solution (Python):
N, M = map(int, input().split())

if (N==1) & (M > 1):
    ans = M - 2
elif (M==1) & (N > 1):
    ans = N - 2
elif (N==1) & (M==1):
    ans = 1
else:
    ans = ((N - 2) * (M - 2))

print(ans)

Solution (Python):
N, M = list(map(int, input().split()))
result = 0
if N == 1 and M == 1:
    result = 1
elif N == 1:
    result = M - 2
elif M == 1:
    result = N - 2
else:
    result = (N - 2) * (M - 2)
print(result)

Solution (Python):
n,m=map(int,input().split())
if n == 1 and m == 1:
  print(1)
elif n <= 2 and m <= 2:
  print(0)
elif n == 1:
  print(m-2)
elif m == 1:
  print(n-2)
else:
  print((n-2)*(m-2))

Solution (Python):
n,m = map(int,input().split())
if min(n,m) == 1 and max(n,m) >= 3:
    print(max(n,m)-2)
elif min(n,m) == 1 and max(n,m) == 2:
    print(0)
elif min(n,m) == 2:
    print(0)
else:
    print((n-2)*(m-2))

Solution (Python):
n, m = map(int, input().split())
if n == 1 or m == 1:
    print(1 if n * m == 1 else max(n, m) - 2)
else:
    print((n - 2) * (m - 2))

Solution (Python):
n, m = map(int, input().split())
if n == 1 or m == 1:
    print(max(n, m) - 2 if n * m > 1 else 1)
else:
    print((n - 2) * (m - 2))

Solution (Python):
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N, M) - 2)
else:
    print((N - 2) * (M - 2))

Solution (Python):
n, m = map(int, input().split())
if n*m==1:
    print(1)
elif n==1:
    print(m-2)
elif m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

Solution (Python):
N,M = map(int,input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N,M)-2)
else:
    print((N-2)*(M-2))

Solution (Python):
N,M = map(int,input().split())

if N == 1 and M == 1:
    print(1)
    exit()
elif N == 1:
    print(M-2)
    exit()
elif M == 1:
    print(N-2)
    exit()

print((N-2)*(M-2))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, m = map(int, readline().split())
if n == 1 or m == 1:
    if n == 1 and m == 1:
        print(1)
    else:
        print(n * m - 2)
else:
    print(n * m - (n + m - 2) * 2)

Solution (Python):
n, m = map(int, input().split())
 
if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
elif n == 2 or m == 2:
    print(0)
else:
    print((n-2) * (m-2))

Solution (Python):


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


def main() -> None:
    """Entry point
    """
    
    """
    各カードが奇数回または偶数回裏返されるかを考える。
    """
    result = 0
    if N == 1:
        if M == 1:
            result = 1
        else:
            result = M - 2
    else:
        result = (N - 2) * (M - 2)

    
    print(result)


if __name__ == "__main__":
    main()

Solution (Python):


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


N, M = min(N, M), max(N, M)
result = 0
if N == 1:
    if M == 1:
        result = 1
    else:
        result = M - 2
else:
    result = (N - 2) * (M - 2)


print(result)

Solution (Python):
n, m = map(int, input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m-2)
elif m == 1:
    print(n-2)
elif n == 2 or m == 2:
    print(0)
else:
    print((n-2) * (m-2))

Solution (Python):
n,m = map(int,input().split())

if n==1 or m==1:
    ans = max(max(n,m)-2,1)
else:
    ans = (n-2)*(m-2)
print(ans)

Solution (Python):
n,m = map(int,input().split())

if n==1 or m==1:
    ans = max(max(n,m)-2,1)
else:
    ans = (n-2)*(m-2)
print(ans)
'''
input_map = [[1 for i in range(m)]for j in range(n)]

def checker(input_map,x,y):
    if 0<=x<=m-1 and 0<=y<=n-1:
        input_map[y][x]*=-1
    return input_map

check_li = [[0,0],[0,1],[1,0],[1,1],[-1,0],[0,-1],[-1,-1],[-1,1],[1,-1]]
for i in range(n):
    for j in range(m):
        for c in check_li:
            input_map = checker(input_map,j+c[0],i+c[1])

ans=0
for i in range(n):
    for j in range(m):
        if input_map[i][j]==-1:
            ans+=1
print(ans)
'''

Solution (Python):
n,m=map(int,input().split())
print(abs(m-2)*abs(n-2))

Solution (Python):
n,m=map(int,input().split())
if n==2 or m==2:
    print(0)
elif n==m==1:
    print(1)
elif n==1 or m==1:
    print(max(n,m)-2)
else:
    print((n-2)*(m-2))

Solution (Python):
h,w = map(int,input().split(" "))
if h == 1 and w == 1:
    print(1)
elif h == 1:
    print(w - 2)
elif w == 1:
    print(h - 2)
else:
    print((h - 2) * (w - 2))

Solution (Python):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(n*m-2)
else:
    print((m-2)*(n-2))

Solution (Python):
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy





sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))




def main():
    n, m = ns()

    if n > 2 and m > 2:
        ans = (n - 2) * (m - 2)
    elif n == 2 or m == 2:
        ans = 0
    elif n == 1 or m == 1:
        if n == 1 and m == 1:
            ans = 1
        else:
            ans = max(n - 2, m - 2)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import os

def file_input():
    f = open('ARC091/input.txt', 'r')
    sys.stdin = f

def main():
    
    
    N,M=map(int, input().split())

    if N==1 and M==1:
        print(1)
    elif N==1 or M==1:
        print(N*M-2)
    else:
        print(N*M-4-(N+M-4)*2)

if __name__ == '__main__':
    main()

Solution (Python):
n, m = sorted(map(int, input().split()))
print(1 if n==m==1 else m-2 if n==1 else (n-2)*(m-2))

Solution (Python):
N, M = map(int, input().split())

if N >= 3 and M >= 3:
    print((N-2)*(M-2))
elif N == 2 or M == 2:
    print(0)
else:
    print(max(N - 2, M - 2, 1))

Solution (Python):
n,m=map(int,input().split())
n,m=min(n,m),max(n,m)
if n==1:
    if m==1:
        print(1)
    else:
        print(max(0,m-2))
        exit()
else:
    print(max(0,(n-2)*(m-2)))

Solution (Python):
N, M = map(int, input().split())


if min(N, M) == 1:
    if max(N, M) > 1:
        print(max(N, M) - 2)
    else:
        print(1)
else:
    print(N * M - 4 - (N - 2) * 2 - (M - 2) * 2)

Solution (Python):
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,m=mis()
    ans=n*m
    cnt=0
    if n>1:
        ans-=2*m
        cnt+=1
    if m>1:
        ans-=2*n
        cnt+=1
    if cnt==2: ans+=4
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def resolve():
    '''
    code here
    '''

    N, M = [int(item) for item in input().split()]
    res_dict = {0:0, 1:0, 2:0, 3:0, 5:0, 8:0}

    if N > M:
        N, M = M, N
    
    if N == 1:
        if M >= 2:
            res_dict[1] = 2
            res_dict[2] = M -2
        else:
            res_dict[0] = 1
    else:
        res_dict[3] = 4
        res_dict[5] = 2* (N - 2 + M - 2)
        res_dict[8] = M*N - (2*(N+M) -4)
    
    
    cnt = 0
    for i, v in res_dict.items():
        if i % 2 == 0:
            cnt += v

    print(cnt)            


if __name__ == "__main__":
    resolve()

Solution (Python):
n, m = map(int, input().split())
if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m - 2)
elif m == 1:
    print(n - 2)
else:
    print((n - 2) * (m - 2))

Solution (Python):
n, m = map(int, input().split())
if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(m - 2)
elif m == 1:
    print(n - 2)
else:
    print((n - 2) * (m - 2))

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()

if n == 1 or m == 1:
    if n*m == 1:
        print(1)
    else:
        print(n*m-2)
else:
    print((n-2)*(m-2))

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7



def main():
    N, M = map(int, input().split())
    if N == 1 and M == 1:
        print(1)
    elif (N == 1 and M >= 2):
        print(M - 2)
    elif (N >= 2 and M == 1):
        print(N - 2)
    else:
        print((N - 2) * (M - 2))


if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
if N==1 and M==1:
    print(1)
elif (N==1 and M>=2):
    print(M-2)
elif  (N>=2 and M==1):
    print(N-2)
else:
    print((N-2)*(M-2))

Solution (Python):
N, M = map(int,input().split())

total = N * M

sumi = 4
if N >= 2 and M >= 2:
    hen = (N-2) * 2 + (M-2) * 2
    ans = total - sumi - hen
elif N == 1 and M > 1:
    hen = M-2
    ans = hen
elif N > 1 and M == 1:
    hen = N - 2
    ans = hen
else:
    ans = 1


print(ans)

Solution (Python):
N,M=map(int,input().split())

if min(N,M)>1:
    print(M*N-2*(M+N-2))
elif N==1 and M==1:
    print(1)
else:
    print(max(M,N)-2)

Solution (Python):
N, M = map(int, input().split())
if(N == 1 and M == 1):
    print(1)
elif(N == 1):
    if(M == 2):
        print(0)
    else:
        print(1 * M-2)
elif(M == 1):
    if(N == 2):
        print(0)
    else:
        print(1 * N-2)
else:
    print((N - 2) * (M - 2))

Solution (Python):
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


N, M = map(int, input().split())
if N == 1 and M == 1:
    print(1)
    exit(0)

elif N == 1:
    N, M = M, N
if M == 1:
    print(N - 2)
    exit(0)

corner = 4
edge = (N - 2) * 2 + (M - 2) * 2

print(N * M - corner - edge)

Solution (Python):
n,m = map(int,input().split())
ans=0
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(n*m-2)
else:
    print(n*m-2*(n+m)+4)

Solution (Python):
def main():
    N, M = map(int, input().split())

    if N == 1 or M == 1:
        if N == 1 and M == 1:
            print(1)
            return
        print(N*M-2)
        return

    if N == 2 or M == 2:
        print(0)
        return

    print((N-2)*(M-2))

if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    n, m = map(int, input().split())

    ans = abs(0*4 + 0*(n-2)*2 + 0*(m-2)*2 + 1*(n-2)*(m-2))

    return ans

print(solve())

Solution (Python):
N,M = map(int, input().split())
if N==M==1:
    print(1)
elif N == 1 or M == 1:
    print(max(N,M)-2)
else:
    print((N-2) * (M-2))

Solution (Python):

import sys


def solve(N: int, M: int):
    if N > 2 and M > 2:
        print((N-2) * (M-2))
        return
    if N == 1 and M == 1:
        print(1)
        return
    if N == 1 and M >= 2:
        print(M-2)
        return
    if N >= 2 and M == 1:
        print(N-2)
        return
    print(0)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    solve(N, M)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, M = map(int, input().split())

    if N > M:
        N, M = M, N

    if (N, M) == (1, 1):
        print(1)
        return

    if N == 1:
        print(M - 2)
        return

    print((N - 2) * (M - 2))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N, M = map(int, input().split())

    def judge(r, c):
        if r >= N or c >= M:
            return 0

        if ~memo[r][c]:
            return 0

        ux = (r == 0)  
        bx = (r == N - 1)  
        lx = (c == 0)  
        rx = (c == M - 1)  

        ret = 9  
        ret -= (ux + bx + lx + rx) * 3 - (ux & lx) - (ux & rx) - (bx & lx) - (bx & rx)
        return ret & 1  

    memo = [[-1] * 2 for _ in range(2)]
    

    for r in range(2):
        for c in range(2):
            memo[r][c] = judge(r=r, c=c)

    ans = memo[0][0] + memo[1][0] * (N - 2) + memo[0][1] * (M - 2) + memo[1][1] * (N - 2) * (M - 2)

    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split())
ans = n * m

if n > 1 or m > 1:
    if n >= 2 and m >= 2:
        ans -= 4
    else:
        ans -= 2

if n > 1:
    ans -= max((m - 2) * 2, 0)

if m > 1:
    ans -= max((n - 2) * 2, 0)

print(ans)

Solution (Python):
n, m = map(int, input().split())

if n > 1 and m > 1:
    print((n-2)*(m-2))
elif max(n,m) > 2:
    print(max(n,m)-2)
elif max(n,m) == 2:
    print(0)
else:
    print(1)

Solution (Python):
n, m = map(int, input().split())

if n == 1 and m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max((n - 2), (m - 2)))
else:
    print((n - 2) * (m - 2))

Solution (Python):
N,M=map(int, input().split())
ans=0
if min(N,M)==1:
    if max(N,M)==1:
        print(1)
        exit()
    print(max(0,max(N,M)-2))
    exit()
ans=(N-2)*(M-2)
print(ans)

Solution (Python):
def solve():
    N,M = map(int,input().split())
    if N == 1 or M == 1:
        if N==2 or M ==2:
            print(0)
        else:
            print(max(1, max(N,M)-2))
    else:
        print(N*M - (N+M+M+N-4))



if __name__ == '__main__':
    solve()

Solution (Python):
n,m=map(int,input().split())
c=n*m
if c==1:
    print(1)
elif n==1 or m==1:
    print(c-2)
else:
    print(c-n*2-(m-2)*2)

Solution (Python):
n,m = map(int, input().split())
if n==m==1: print(1)
elif n == 1 or m == 1: print(max(n,m)-2)
else: print((n-2) * (m-2))

Solution (Python):
n,k=map(int, input().split())
print(abs((n-2)*(k-2)))

Solution (Python):

N,M = map(int,input().split())
if(min(N,M)==1):
    if(max(N,M)==1):
        print(1)
    else:
        print(max(N,M)-2)
elif(min(N,M)==2):
    print(0)
else:
    print(N*M - (N*2+M*2 - 4))

Solution (Python):
def myAnswer(N:int,M:int) -> int:
   if(N == 1 and M == 1): return 1
   if(min(N,M) == 1): return max(N,M) - 2
   if(min(N,M) == 2): return 0
   return N*M - (max(N,M) * 2 + (min(N,M) - 2) * 2)

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   print(myAnswer(N,M))
if __name__ == '__main__':
   main()

Solution (Python):
N,M = map(int,input().split())
if N==1 and M==1:
    ans = 1
elif N==1 or M==1:
    ans = max(N-2,M-2)
elif N==2 or M==2:
    ans = 0
else:
    ans = N*M-2*(N+M-2)
print(ans)

Solution (Python):
n,m = map(int, input().split())
if n == m== 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n,m)-2)
else:
    print((n-2)*(m-2))

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N,M=map(int,readline().split())
    if N==1 and M==1:
        print(1)
    elif N==1 or M==1:
        print(max(N,M)-2)
    else:
        print((N-2)*(M-2))
if __name__=="__main__":
    main()

Solution (Python):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1:
    print(m-2)
elif m==1:
    print(n-2)
else:
    print(n*m-(2*n+2*m-4))

Solution (Python):
n, m = map(int,input().split())

if n * m == 1:
    print(1)
    exit()

if n > 1 and m > 1:
    temp = 2 * (n + m) - 4
    ans = n * m - temp
    print(ans)
else:
    print(n * m - 2)

Solution (Python):
N, M = map(int, input().split())

def solve(N,M):
    if N==1 and M==1:
        return 1
    if N==1:
        return M-2
    if M==1:
        return N-2
    ans = (N-2)*(M-2)
    return ans
print(solve(N,M))

Solution (Python):
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
if N > M: N, M = M, N
if N == 1 and (M == 1): print(1)
elif N == 2: print(0)
elif N == 1 and (M == 2): print(0)
elif N == 1: print(max(0, M - 2))
else: print(max(0, (N - 2) * (M - 2)))

Solution (Python):
def main():
    n, m = map(int, input().split())
    
    
    
    if n > m:
        n, m = m, n
    
    if n == 1 and m == 1:
        print(1)
    elif n == 1:
        print(m - 2)
    else:
        print((n - 2) * (m - 2))



if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
if n==1 and m==1:
  print(1)
elif n==1 and m!=1:
  print(m-2)
elif m==1 and n!=1: 
  print(n-2)
elif n==2:
  print(0)
elif n>3:
  print((m-2)*(n-2))

Solution (Python):

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
answer = abs((N-2) * (M-2))
print(answer)

Solution (Python):
def main():
    N, M = (int(i) for i in input().split())
    ans = 0
    if N == 1 and M == 1:
        ans = 1
    elif N == 1:
        ans = M-2
    elif M == 1:
        ans = N-2
    else:
        h = N-2
        w = M-2
        ans = h*w
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  










N, M = read_ints()
N, M = (N, M) if N < M else (M, N)

if N == 1 and M == 1:
    print(1)
    exit()
if N == 1:
    print(M - 2)
    exit()
print((N - 2) * (M - 2))

Solution (Python):
n,m=map(int,input().split())
if n==1 and m==1:
  print(1)
elif n==1 and m!=1:
  print(m-2)
elif m==1 and n!=1: 
  print(n-2)
elif n==2:
  print(0)
elif n>3:
  print((m-2)*(n-2))

Solution (Python):
N, M = map(int, input().split())

res = 0

if N*M==1:
    res = 1
elif N==1:
    res = (M-2)
elif M==1:
    res = (N-2)
else:
    res = (N-2)*(M-2)
print(res)

Solution (Python):
N,M=map(int,input().split())
if N==1:
  if M==1:
    print(1)
  else:
    print(M-2)
elif M==1:
  print(N-2)
else:
  print(N*M-2*max(0,N-1)-2*max(0,M-1))

Solution (Python):
N, M = map(int, input().split())

if N == M == 1:
    print (1)
elif N == 1 or M == 1:
    print (N * M - 2)
else:
    print ((N -2) * (M - 2))

Solution (Python):
N,M = map(int,input().split())
if N == 1 and M == 1:
  print(1)
elif N == 1 or M == 1:
  print(N*M-2)
elif 2 <= N*M <= 6:
  print(0)
else:
  print((N-2)*(M-2))

Solution (Python):


n, m = map(int, input().split())

peremeter = 0
if n == 1 and m == 1:
    pass 
elif n == 1 or m == 1:
    peremeter += 2
else:
    peremeter += (n - 1) * 2
    peremeter += (m - 1) * 2
ans = n * m - peremeter
print(ans)

Solution (Python):
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]

N, M = ri_()
if N == 1 and M == 1:
    print(1)
elif N == 1:
    print(M - 2)
elif M == 1:
    print(N - 2)
else:
    print((N - 2) * (M - 2))

Solution (Python):
n, m = (map(int, input().split()))
print(abs((n-2) * (m-2)))

Solution (Python):
N, M = map(int, input().split())
if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max(N, M) - 2)
else:
    print((N - 2) * (M - 2))