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())
n,m=min(n,m),max(n,m)
if n==1 and m==1:
  print(1)
elif n==1:
  print(m-2)
else:
  print(n*m-2*m-2*n+4)

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

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

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

print(ans)

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

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

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

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

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

solve()

Solution (Python):
N,M = [int(x) for x in input().split()]
if(N==2 or M==2):
  print(0)
elif(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 or M == 1:
        if N*M == 1:
                print(1)
        elif N*M == 2:
                print(0)
        else:
                print(N*M-2)
else:
        if N == 2 or M == 2:
                print(0)
        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((M-2)*(N-2))

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

if N == 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:
    tmp = N
    N=M
    M=tmp
if N >= 2:
    print(N*M-2*N-2*M+4)
elif M == 1:
    print(1)
else:
    print(N*M-2)

Solution (Python):


import sys
from collections import deque

INF = float('inf')
MOD = 10 ** 9 + 7
dy, dx = (0, -1, 0, 1), (1, 0, -1, 0)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


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

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

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

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

Solution (Python):
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter

def j(q):
    if q==1: print("YES")
    else:print("NO")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)



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








a.sort()
if max(a) == 1:
    print(1)
elif min(a)==1:
    if max(a)==2:
        print(0)
    else: print(a[1]-2)
elif min(a)==2:
    print(0)
else:
    print((a[0]-2)*(a[1]-2))

Solution (Python):
import sys
from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().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-N*2)
elif M == 1:
    print(N-M*2)
else:
    print(N*M-2*M-2*(N-2))

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

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

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

Solution (Python):
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n, m = MI()

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

Solution (Python):
a = sorted(list(map(int,input().split())))
n = a[0]
m = a[1]
ans = 0
if n == m == 1:
        ans = 1
elif n == 1:
        ans = 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 - 2 ) * ( m - 2 )

print(ans)

Solution (Python):
N,M=map(int,input().split(' '))
print(abs(N-2)*abs(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 N > 1 and 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)):
  ans = (N-2)*(M-2)
elif((N == 1)and(M == 1)):
  ans = 1
elif(N == 1):
  ans = M-2
elif(M == 1):
  ans = N-2
print(ans)

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

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

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

Solution (Python):
N, M = map(int, raw_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 - 1 + M - 1) * 2

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

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

Solution (Python):
N, M = map(int, input().split(' '))
if N != 1 and M != 1:
    ans = N*M - (2*N + 2*M - 4)
else:
    if N == 1 and M == 1:
        ans = 1
    else:
        ans = N*M - 2

print(ans)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
N, M = inpl()
if M < N:
    N, M = M, N
if N == 1:
    if M == 1:
        print(1)
    else:
        print(M-2)
elif N == 2:
    print(0)
else:
    print((N-2)*(M-2))

Solution (Python):
n, m = list(map(int, input().split()))
n, m = max(n, m), min(n, m)
if n == 1 and m == 1:
    print(1)
else:
    a = min(2, n)
    b = max(0, n-2)
    c = min(2, m)
    d = max(0, m-2)
    if m == 1:
        print(b)
    else:
        print(b*d)

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

Solution (Python):
N,M = map(int,input().split())
 
if N == 2 or M == 2:
    print(0)
    exit()

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

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

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

Solution (Python):
N, M = [int(x) for x in input().split()]

if N == 1 and M == 1:
    print(1)
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 = list(map(int, input().split()))

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

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

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

print(ans)

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

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

Solution (Python):
l = list(map(int, input().split()))
l.sort()


N, M = l

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

Solution (Python):
def solve(n, m):
    if n == 1 and m == 1:
        return 1
    if n == 1:
        return m - 2
    if m == 1:
        return n - 2
    return (n - 2) * (m - 2)

if __name__ == "__main__":
    n, m = map(int, input().split())
    print(solve(n, m))

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

Solution (Python):

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

Solution (Python):
N,M = (int(i) for i in 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):
import sys
N,M=map(int,input().split())
if N==1 and M==1:
    print(1)
    sys.exit()
if N==1:
    print(M-2)
    sys.exit()
if M==1:
    print(N-2)
    sys.exit()
if N==2 or M==2:
    print(0)
    sys.exit()
print((M-2)*(N-2))

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

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

if b[0] == 1 and b[1] == 1:
	print(1)
elif b[0] == 1:
	print(b[1]-2)
elif b[1] == 1:
	print(b[0] -2)

else:
	print(b[0]*b[1] - 2*(b[0] + b[1] - 2))

Solution (Python):
n,m=input().split()
n,m=int(n),int(m)
if 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)
else:
    print(n*m-2*n-2*m+4)

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

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 M*N == 1:
  print(1)
elif min(N, M) == 1:
  print(max(N, M)-2)
else:
  print((N-2)*(M-2))

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

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

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

Solution (Python):
if __name__ == "__main__":
    N, M = map(int, input().split())
    if (N > M):
        N, M = M, N
    if (N == 1):
        print(max(1, M - 2))
        exit(0)
    result = (N - 2) * (M - 2)
    print(result)

Solution (Python):

from collections import deque
lines = input().split(' ')
m = int(lines[0])
n = int(lines[1])

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

Solution (Python):
H, W = map(int, raw_input().split())

if H > W:
    H, W = W, H

if H == 1 and W == 1:
    print 1
elif H == 1:
    print W - 2
else:
    print (H - 2) * (W - 2)

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

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

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(n+m-3)
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 M > N:
    tmp = M
    M = N
    N = tmp

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

Solution (Python):
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft


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

n, m = LI()
result = {
    (1, 1): 1,
    (1, 2): 0, (2, 1): 0,
    (2, 2): 0
}

if (n, m) in result.keys():
    print(result[(n, m)])
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:
    ans = 1
elif n == 1:
    ans = m - 2
elif m == 1:
    ans = n - 2
else:
    ans = (n - 2) * (m - 2)
print(ans)

Solution (Python):
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

(N, M) = reads()

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

print(ans)

Solution (Python):
def calc_flips(n,m):
    flips = {}
    if n==1 and m==1:
        flips[1]=1
    elif n==1 or m==1:
        flips[2]=2
        b = n if n>m else m
        flips[3]=b-2
    elif n==2 and m==2:
        flips[4]=4
    elif n==2 or m==2:
        flips[4]=4
        b = n if n>m else m
        flips[6]=(b-2)*2
    else:
        flips[4]=4
        flips[6]=((n-2)*2)+((m-2)*2)
        flips[9]=(n-2)*(m-2)
    return flips

def calc_backs(flips):
    num_backs = 0
    for k,v in flips.items():
        if k % 2 == 1:
            num_backs += v
    return num_backs

n,m = map(int, input().split())
flips = calc_flips(n,m)
num_backs = calc_backs(flips)
print(num_backs)

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

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

if m==1:
	ans += (n-2)
if n==1:
	ans += (m-2)
	
if n*m==3:
	print('2')
elif n*m==2:
	print('0')
elif n*m==1:
	print('1')
else:
	print(ans)

Solution (Python):
def solve(N, M):
    if N * M == 1:
        return 1
    elif min(N, M) == 1:
        return max(N, M) - 2
    else:
        return (N-2) * (M-2)

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

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

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

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

Solution (Python):
def calc(N, M):
    if N == 1 and M == 1:
        return 1
    if N == 1:
        return M - 2
    if M == 1:
        return N - 2
    
    return (N - 2) * (M - 2)

N, M = [int(_) for _ in input().split()]

print(calc(N, M))

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


def a(nm):
    if nm == 1:
        return 1
    else:
        return nm - 2


print(a(n) * a(m))

Solution (Python):
Tmp = []
Tmp = input().rstrip().split(' ')

N = int(Tmp[0])
M = int(Tmp[1])

Ans = 0

if (N==1) and (M==1):
    Ans = 1
elif (N==2) or (M==2):
    Ans = 0
elif (N==1):
    Ans= M - 2
elif (M==1):
    Ans= N - 2
else:
    Ans = (N - 2)*(M - 2)
    

print(Ans)

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

Solution (Python):
n,m = list(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((m-2)*(n-2))

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

s=min(N,M)
l=max(N,M)

ans=None

if s==1:
    if l>=2: ans=l-2
    else: ans=1

elif s==2: ans=0
else:
    ans=(s-2)*(l-2)

print(ans)

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

Solution (Python):
n, m = raw_input().split(' ');
n = int(n);
m = int(m);
if ((n == 1) & (m == 1)):
    print 1;
elif (n == 1):
    print m - 2;
elif (m == 1):
    print n - 2;
else :
    print n * m - 2 * (n - 1) - 2 * (m - 1);

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

Solution (Python):
def solve():
    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

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


if __name__ == "__main__":
    solve()

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

if N == 1:
    N = 3


if M == 1:
    M = 3

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

Solution (Python):
import sys
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [long(input_raw[0]), long(input_raw[1])]
    if N == 1 and M == 1:
        print 1
    elif N == 1:
        print M - 2
    elif M == 1:
        print N - 2
    else:
        print N * M - ((((M - 1) + (N - 1)) * 2))


if __name__ == '__main__':
    main()

Solution (Python):
num = map(int,raw_input().split())
n = num[0]
m = num[1]

if 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())
if N == M and N == 1:
    print(1)
elif min(N,M) == 1:
    print(max(N,M)-2)
elif min(N,M) == 2:
    print(0)
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==2 or M ==2:
    print (0)
elif N==1 and M ==1:
    print (1)
elif N+M < 3:
    print (0)
else:
    print (N+M-3)

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

if (HW[0] == 1 and HW[1] == 1):
	count = 1
elif (HW[0] == 1 or HW[1] == 1):
	count = HW[0] * HW[1] - 2
else:
	count = (HW[0] - 2) * (HW[1] - 2)

print(count)

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

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

Solution (Python):

import numpy


def main():
    n, m = map(int, input().split())
    if n < m:
        n, m = m, n

    if m == 1 and n == 1:
        return 1

    if m == 1:
        return n - 2

    return (n - 2) * (m - 2)


if __name__ == '__main__':
    print(main())

Solution (Python):
import sys
N, M = [int(x) for x in input().split()]

if M * N == 1:
    print(1)
    sys.exit()

if N == 1:
    print(M - 2)
    sys.exit()

if M == 1:
    print(N - 2)
    sys.exit()
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 == 2 or M == 2:
    print(0)
elif N == 1:
    print(M-2)
elif M == 1:
    print(N-2)
else:
    print((N-2) * (M-2))

Solution (Python):


x,y=[int(i) for i in input().split()]

if x==1:
    if y == 1:
        print(1)
    else:
        print(y-2)
elif y==1:
    print(x-2)
else:
    print((x-2)*(y-2))

Solution (Python):
l = input().split(" ")
W = int(l[0])
H = int(l[1])
if W == 1 and H == 1:
  print(1)
elif W == 1 or H == 1:
  print(W * H - 2)
else:
  print(W * H - 2 * (W + H - 2))

Solution (Python):
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
a=1
if n>2:
 a*=n-2
if m>2:
 a*=m-2
if n==2 or m==2:
  a=0
print(a)

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

ans =0
n1 =0
m1 = 0

if N == 1:
    n1 = 1
else:
    n1 = N -2

if M == 1:
    m1 = 1
else:
    m1 = M -2

ans = n1*m1


print(ans)

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

Solution (Python):
n, m = map(int, input().split())
def a(nm):
    if nm == 1:
        return 1
    else:
        return nm - 2
n2, m2 = a(n), a(m)
print(n2*m2)

Solution (Python):
x, y = map(int, raw_input().split())
if x == 1:
    if y == 1:
        print 1
    else:
        print y-2
elif y == 1:
    print x-2
else:
    print x*y-2*x-2*(y-2)

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

Solution (Python):

def solve():
    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

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

solve()

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

Solution (Python):

def calc0(N, M):
    cell = [[0 for i in range(M)] for j in range(N)]
    for i in range(M):
        for j in range(N):
            for y in range(-1, 2):
                for x in range(-1, 2):
                    xx = i + x
                    yy = j + y
                    if 0 <= xx < M and 0 <= yy < N:
                        cell[yy][xx] ^= 1
    r = 0
    for i in range(M):
        for j in range(N):
            if cell[j][i]:
                r += 1
    return r
    
def calc(N, M):
    if N == 1 and M == 1:
        return 1
    if N >= 2 and M >= 2:
        return (N - 2) * (M - 2)
    if N == 1:
        return M - 2
    return N - 2

N, M = [int(_) for _ in input().split()]

print(calc(N, M))

Solution (Python):
n,m = [int(i) for i in input().split()]
if n==1 and m==1:
  print(1)
elif n==1 or m==1 and n*m>=2:
  print(n*m-2)
else:
  print( n * m - n * 2 - m * 2 +4 )

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):

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

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string

H, W = map(int, input().split())
if H > W:
    H, W = W, H
ans = None
if H == 1:
    if W == 1:
        ans = 1
    else:
        ans = W - 2
elif H == 2:
    ans = 0
else:
    ans = (H - 2) * (W - 2)
print(ans)

Solution (Python):
import sys
import random

def rd():
        return sys.stdin.readline().rstrip()

def rdi():
        return [ int(x) for x in rd().split() ]

N, M = rdi()

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 = 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, raw_input().split())

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

Solution (Python):
def solve(n, m):
    if n == 2 or m == 2:
        return 0
    if min(n, m) == 1:
        if max(n, m) == 1:
            return 1
        else:
            return n * m - 2
    return n * m - 2 * (n + m) + 4


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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    if n == 1 and m == 1:
        return 1

    if n == 1:
        return m - 2
    if m == 1:
        return n - 2

    return (n-2) * (m-2)


print(main())