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):
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext

def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

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

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

if __name__ == '__main__':
    main()

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


if N == 1 and M == 1:
    ans = 1
elif N <= 2 and M <= 2:
    ans = 0
elif N == 1 or M == 1:
    ans = max(N, M) - 2
else:
    ans = N * M - (2 * N + 2 * M - 4)

print(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 = (M-2) * (N-2)
print(ans)

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

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

Solution (Python):
a,b=map(int, input().split())

if a == 1 and b == 1:
    print(1)
if a == 1 and b != 1:
    print(b-2)
if a != 1 and b == 1:
    print(a-2)
if a != 1 and b != 1:
    print(a*b-2*(a+b)+4)

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())
print(abs((n-2)*(m-2)))

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

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

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m=sorted(nm())

if n==1 and m==1:
  print(1)
elif n==1:
  print(m-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<m:
  n,m=m,n
if m==1:
  print(abs(n-2))
elif m==2:
  print(0)
else:
  print((m-2)*(n-2))

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

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

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

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

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

    

        


if __name__ == "__main__":
    main()

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

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

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

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

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

print(ans)

Solution (Python):
N,M=map(int,input().split())
N,M=sorted([N,M])
if N==1:
  if M>=3:print(M-2)
  else:print(2-M)
elif N==2:print(0)
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,0))
else:
    print(max((N*M)-N*2-M*2+4,0))

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):
n,m = map(int, raw_input().split())
def f(a,b): 
	if a == 1 and b == 1:
		return 1
	if a == 1 or b == 1:
		return max(0, max(a,b) - 2)
	return max(0,a - 2) * max(0, b - 2) 
print f(n,m)

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

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

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

if n*m == 1:
    print(1)
elif m*n == 4:
    print(0)
else:
    print(abs((n-2)*(m-2)))

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

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

Solution (Python):
N,M = (int(X) for X in input().split())
if N==1 or M==1:
    if N==M:
        print(1)
    else:
        print(max(N,M)-2)
else:
    Four = 4
    Six  = 2*(N+M-4)
    Nine = N*M-(Four+Six)
    print(Nine)

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

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

Solution (Python):
a,b = map(int, open(0).read().split())

if a==1 and b==1:
    print(1)
elif 1 in [a,b]:
    x = a*b
    print(x-2)
else:
    print((a-2)*(b-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-2,M-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())
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:
    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<=2 and m<=2:
    if n==m==1:
        print(1)
    else:
        print(0)
elif n==1 or m==1:
    print(max(n,m)-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==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):
N,M=map(int,input().split())
 
if N==1:
  if M==1:
    print(1)
  else:
    print(M-2)
elif N==2:
  print(0)
else:
  if M==1:
    print(N-2)
  elif M==2:
    print(0)
  else:
    print((N-2)*(M-2))

Solution (Python):
import sys, os, math, bisect, itertools, collections, heapq, queue

from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()

    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))


if __name__ == '__main__':
    main()

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

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


def main():
    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 = (m - 2) * (n - 2)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
H,W=list(map(int,input().split()))
H=H-2
W=W-2

if H < 0:
    H=1
if W < 0:
    W=1

ans=H*W
print(ans)

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

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

num_ac = H*W
if H>=2 and W>=2:
    num_hd = 2*W+2*(H-2)
elif (H == 1 and W>= 2) or ( H>=2 and W==1):
    num_hd = 2

else:
    num_hd = 0

print(num_ac-num_hd)

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

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

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

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

if (N>1) and (M>1):
    ans = (N-2) * (M-2)
elif (N==1) and (M==1):
    ans = 1
else:
    ans = N + M - 3
print(ans)

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

if (N>1) and (M>1):
  ans = (N-2) * (M-2)
elif (N==1) and (M==1):
  ans = 1
else:
  ans = N + M - 3
print(ans)

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

Solution (Python):
N, M = list(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 > 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))

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-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):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    p=max(n,m)
    print(p-2)
else:
    print((n-2)*(m-2))

Solution (Python):
a,b = map(int, input().split())

if a ==1:
    if b == 1:
        print(1)
        exit()
    else:
        print(b-2)
        exit()

elif a==2:
    print(0)
    exit()

else:
    if b ==1:
        print(a-2)
        exit()
    elif b==2:
        print(0)
        exit()
    else:
        print((a-2)*(b-2))
        exit()

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((m-2)*(n-2))

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

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

Solution (Python):
def main():
    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*m - (2*n + 2*m - 4)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, M = in_nn()
    if N == 1 and M == 1:
        ans = 1
    elif N == 1 and M > 1:
        ans = M - 2
    elif N > 1 and M == 1:
        ans = N - 2
    else:
        ans = (N - 2) * (M - 2)
    print(ans)


if __name__ == '__main__':
    main()

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*m - (2*n+2*m-4))

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

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

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((m-2)*(n-2))

Solution (Python):
N, M = [int(x) for x in input().split()]
print(abs((N - 2) * (M - 2)))

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

if N==1 and M==1: print(1);exit()
if N==1 and M==2: print(0);exit()
if N==2 and M==1: print(0);exit()
if N==1: print(M-2);exit()
if M==1:print(N-2);exit()
if N==2 or M==2:print(0);exit()
else: print((N-2)*(M-2))

Solution (Python):
n, m = map(int, input().split())
if n == 1 and m == 1:
  print(1)
  exit()
if n == 1 or m == 1:
  print(max(n, 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 >= 2:
    print(M - 2)
elif N >= 2 and M == 1:
    print(N - 2)
else:
    print((M-2) * (N-2))

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

Solution (Python):
import sys

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def main():
    N, M = mi()
    if N == 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-2)*(m-2))

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

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

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

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

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

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

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n, m = MI()
    if n == 2 or m == 2:
        print(0)
        sys.exit()
    h = max(n-2, 1)
    w = max(m-2, 1)
    print(h*w)

if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
if n*m==1:print(1)
elif n==1:print(max(m-2,0))
elif m==1:print(max(n-2,0))
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)
elif n == 2:
    print(0)
else:
    print((n-2)*(m-2))

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

if n>=3 and m>=3:
    ans=n*m-(2*n+2*m-4)
elif n==2 or m==2:
    ans=0
elif n==1 and m==1:
    ans=1
else:
    ans=n*m-2

print(ans)

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

import itertools
print(abs(m*n - ((n-1)*2 + (m-1)*2)))

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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):

import sys

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

N, M = lr()
if N > M:
    N, M = M, N
if N == 1:
    if M == 1:
        answer = 1
    else:
        answer = M - 2
else:
    answer = (N-2) * (M-2)

print(answer)

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

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

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

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, M = map(int, input().split())
if N>M:
    N, M = M, N

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

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()
else:
    print((n-2)*(m-2))

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

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

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((n-2) * (m-2))

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, m) - 2
else:
    ans = (n - 2)*(m - 2)

print(ans)

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

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

print(ans)

Solution (Python):
def main():
    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 * m - (n + m - 2) * 2)
        
if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
if n==2 or m==2:
  print(0)
elif 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())

ans = 0
if N==1:
  if M==1:
    ans=1
  else:
  	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())
print((N-2 if N >= 2 else 1) * (M-2 if M >= 2 else 1))

Solution (Python):
N, M = map(int, input().split())
if N <= 2 or M <= 2:
    if N == 1 and M ==1:
        ans = 1
    elif N == 1 or M == 1:
        ans = max(N-2, M-2)
    else:
        ans = 0
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 and m!=1:
    print(m-2)
elif n!=1 and m==1:
    print(n-2)
else:
    print((n-2)*(m-2))

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    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):
n, m = [int(x) for x in input().split()]
if n == 1 and m == 1:
    ans = 1
elif n == 1 or m == 1:
    ans = max(n, m) - 2
else:
    ans = n * m - 2 * n - 2 * m + 4
print(ans)

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)
elif N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(N*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 * M - 2 * (N + 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)
else:
    print(abs((N-2)*(M-2)))

Solution (Python):
N,M=map(int,input().split())
if N==1:
  N+=2
if M==1:
  M+=2
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 and m == 2) or (n == 2 and m == 2) or (n == 2 and m == 3):
  print(0)
elif (n == 1):
  print(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)
elif n == 2 or m == 2:
  print(0)
else:
  print(n*m -(n+m-2)*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)
elif n == 2 or m == 2:
  print(0)
else:
  print(n*m -(n+m-2)*2)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N, M = MAP()
if N*M == 1:
	print(1)
elif N == 1 or M == 1:
	print(max(N, M)-2)
	exit()
else:
	C = (N+M-2)*2
	print(N*M-C)

Solution (Python):
def solve(n, m):

    return (n-2 if n-2 >= 0 else 1) * (m-2 if m-2 >= 0 else 1)

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print(solve(n, m))

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

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)
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>=2 and m>=2:
    print((n-2)*(m-2))

elif 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)

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

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

n = (n + 2) if n == 1 else n
m = (m + 2) if m == 1 else m

print((n - 2) * (m - 2))

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

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

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

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

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

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

if n == m == 1:
    ans = 1
    
elif min(n,m) == 1 and max(n,m) == 2:
    ans = 0
    
elif min(n,m) == 1 and max(n,m) > 2:
    ans = max(n,m) - 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)
else:
    print(abs((N-2)*(M-2)))

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

Solution (Python):
n,m = map(int,input().split())
 
if (n == 2 and m != 1) or (m == 2 and n != 1):
  print(0)
elif 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*m-(n+m-2)*2)

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

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    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))



if __name__ == "__main__":
    main()

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

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import fractions
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N, M = getNM()
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 resolve():
	n, m = map(int, input().split())
	print(abs(n-2) * abs(m-2))
resolve()

Solution (Python):
def main():
    N, M = list(map(int, input().split(' ')))
    N, M = min([N, M]), max([N, M])
    if N == 1:
        if M == 1:
            print(1)
        elif M == 2:
            print(0)
        else:
            print(M - 2)
    elif N == 2:
        print(0)
    else:
        print((N - 2) * (M - 2))


if __name__ == '__main__':
    main()