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



Sample input:
2 2


Sample output:
0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

def 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)
    elif N>=2 and M>=2:
        print((N-2)*(M-2))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

# N <= M となるようにする
if N > M:
  tmp = N
  N = M
  M = tmp
  
if N == 1 and M == 1:
  print(1)
elif N == 1 and M >= 2:
  print(M-2)
elif N >= 2 and M >= 2:
  print((N-2) * (M-2))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
sq = list(map(int, input().split()))
sq.sort()

if sq[0] == 1 and sq[1] == 1:
    print(1)
elif sq[0] == 1:
    print(sq[1] - 2)
elif sq[0] == 2:
    print(0)
else:
    print((sq[0] - 2) * (sq[1] - 2))

Submission status: Accepted

Solution code:
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)
elif n == 2 or m == 2:
  print(0)
else:
  print((n-2) * (m-2))

Submission status: Accepted

Solution code:
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 m==1 and n>=2:
  print(n-2)
else:
  print(1)

Submission status: Accepted

Solution code:
H, W = map(int, input().split()); H -= 2; W -= 2
print(abs(H * W))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def f(x):
    if x == 1:
        return 1
    else:
        return x - 2

ans = f(n) * f(m)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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((M-2)*(N-2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n > m:
  n, m = m, n
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))

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:



import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

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

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc090/tasks/arc091_a
# C - Flip,Flip, and Flip......

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

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

print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M = II()

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    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))
        
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
(rows, cols) = (int(tok) for tok in input().split())
res = 1

if rows > 1 and cols > 1:
  res = (rows - 2) * (cols - 2)
elif rows > 1 or cols > 1:
  res = max(rows, cols) - 2

print(res)

Submission status: Accepted

Solution code:
import sys
from statistics import *
from collections import *
from operator import itemgetter
stdin = sys.stdin

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

n, m = na()
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
    if m==1:
        print(1)
    else:
        print(m-2)
elif m==1:
    print(n-2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = 0

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

print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_N, _M = [int(_) for _ in input().split()]


def calc(N, M):
    ans = 0

    def hashicco(n, m):
        tmp = 1
        if n > 1:
            tmp += 1
        if m > 1:
            tmp += 1
            if n > 1:
                tmp += 1
        res = tmp % 2
        if n > 1:
            res *= 2
        if n > 1:
            res *= 2
        return res

    # ans += hashicco(N, M)

    v = 0
    if M > 2 and N == 1:
        v += M - 2
    h = 0
    if N > 2 and M == 1:
        h += N - 2

    return hashicco(N,M)+v+h


res = calc(_N, _M)

if _N >= 3 and _M >= 3:
    res += (_N - 2) * (_M - 2)
print(res)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int,input().split())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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(M - 2)
elif N != 1 and M == 1:
    print(N - 2)
else:
    print(1)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    if N >=2 and M >=2:
        return (N-2)*(M-2)
    elif [N, M] == [1, 1]:
        return 1
    elif N == 1:
        return M-2
    elif M == 1:
        return N-2

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
if (n == 1) and (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))

Submission status: Accepted

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

if n == 1 or m == 1:
    if n == 1 and m == 1:
        print(1)
        exit(0)
    else:
        mx = max([n, m])
        print(mx - 2)
        exit(0)
val = (n - 2) * (m-2)
print(val)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)
else:
  print(1)

Submission status: Accepted

Solution code:
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*m-2*(n-1)-2*(m-1))

Submission status: Accepted

Solution code:
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
print(abs(N-2)*abs(M-2))

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
cnt = 0
# corner
if N == M == 1:
    cnt += 1
if N == 1 and M >= 3:
    cnt += M-2
if N >= 3 and M == 1:
    cnt += N-2
if N >= 3 and M>= 3:
    cnt +=(N-2)*(M-2)
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
if n == 2 or m == 2:
  print('0')
else:
  print(abs(n-2)*abs(m-2))

Submission status: Accepted

Solution code:
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(max(N,M)-2)
else:
    print(0)

Submission status: Accepted

Solution code:
h,q=map(int,input().split())

if h==2 or q==2:print(0)
elif h==1 or q==1:
    if h!=1:print((h-2)*1)
    elif q!=1:print((q-2)*1)
    else:print(1)
else:
    print((h-2)*(q-2))

Submission status: Accepted

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

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

main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# 周囲に偶数個のマスがあるものが裏返る
# 角と辺のマスを除けば良い
print(abs(N * M - (2 * N + 2 * M - 4)))

Submission status: Accepted

Solution code:


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

n,m = list(sorted(getints()))

if n == 1:
    if m != 1:
        res = m - 2
    else:
        res = 1
elif n == 2:
    res = 0
else:
    res = n * m - 2 * n - 2 * m + 4

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
if a >= 2 and b >= 2:
  print((a-2) * (b-2))
elif a == 1 and b == 1:
  print(1)
elif a == 1:
  print(b-2)
elif b == 1:
  print(a-2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if n > m:
    c = m
    m = n
    n = c
if n==1:
    print(abs(m-2))
elif n==2:
    print(0)
else:
    print(n*m - 2*(n+m) + 4)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split());o=n-2;p=m-2;print((m<2)*o+(n<2)*p+3*(m<2>n)+o*p*(m>2<n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
if a == 1 and b == 1 :
    ans = 1
elif a == 1:
    ans = b-2
elif b == 1:
    ans = a-2
else:
    ans = (a-2) * (b-2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    s = SR(3)
    for i in range(3):
        print(s[i][i], end="")
    print()
    return

#B
def B():
    a, b = LI()
    ans = 0
    for i in range(a, b + 1):
        x = str(i)
        for k in range(len(x)//2):
            if x[k] != x[-k - 1]:
                break
        else:
            ans += 1
    print(ans)
    return

#C
def C():
    n, m = LI()
    if n == m == 1:
        print(1)
        return
    if n == 1 or m == 1:
        print(max(n - 2, m - 2))
        return
    if n == 2 or m == 2:
        print(0)
        return
    print(n * m - n * 2 - (m - 2) * 2)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()

Submission status: Accepted

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

if N>=2 and M>=2:
  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)

Submission status: Accepted

Solution code:
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-(N*2+(M-2)*2))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().rstrip().split(' '))

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

Submission status: Accepted

Solution code:
# 0:表 1:裏
# 1の数を計算する
# ある行に操作が奇数回適用されると 1(M=1) or 0(1..1)0(M>=2)
## 1の個数num_of_one=1 or M-2
# ある行に操作が偶数回適用されると 0..0
## 1の個数は0
# 各行のパターンは (奇数パターン)(N=1) or
# (偶数パターン)(奇数パターン..奇数パターン)(偶数パターン)(N>=2)
# 1の個数の合計(答え)は num_of_one (N=1) or num_of_one*(N-2)

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    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 and M == 2:
        print(0)
        sys.exit()
    
    if N == 2 or M == 2:
        print(0)
        sys.exit()
        
    total = N*M
    total = total - (2*N)
    total = total - (2*M)
    total += 4
    
    print(total)
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
print(abs(h-2)*abs(w-2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC90 C

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

Submission status: Accepted

Solution code:
def solve(N, M):
    if N == 1 and M == 1:
        return 1

    if N == 1 or M == 1:
        return max(N, M) - 2

    return (N - 2) * (M - 2)


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

Submission status: Accepted

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

Submission status: Accepted

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

if n>m:
	w=n
	n=m
	m=w

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 and M >= 2:
    print((N - 2) * (M - 2))
    sys.exit()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
if n==1 and 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))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC090C - Flip, Flip, and Flip...... (ARC091C)
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    print(abs((n - 2) * (m - 2)))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC090C - Flip, Flip, and Flip...... (ARC091C)
def main():
    n, m = sorted(list(map(int, input().rstrip().split())))
    if (n, m) == (1, 1):  # special case
        print(1)
    elif n == 1:
        print(m - 2)
    elif n == 2:
        print(0)
    else:
        print((n - 2) * (m - 2))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 自分を含む次数

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

def F(N,M):
  if N > M:
    N,M = M,N
  # N is smaller
  if N == 1:
    if M == 1:
      return 1
    else:
      # 両端だけ生き残る
      return M-2
  # 以下N,M >= 2
  # 中央の全て
  return (N-2)*(M-2)

answer = F(N,M)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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